diff options
author | Russ Allbery <rra@stanford.edu> | 2012-02-19 10:40:22 -0800 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2012-02-19 10:40:22 -0800 |
commit | b071bad600dd9ff4043864f2d83cadcaa048c441 (patch) | |
tree | 14b87f1bbdd2a737ebf8226d709d10a2f6d07e4c /client | |
parent | db95a8aa1c4dc9fde2dca643aff5017903dbe07c (diff) |
Add remctl_set_timeout to the client library
Add new remctl_set_timeout function to the remctl library API. Call
this function after remctl_new and before remctl_open to set a network
timeout in seconds. The client must then receive a reply from the
server in no more than that number of seconds or will abort whatever
action is in progress with a timeout error.
Change-Id: Ica8276460cc551d7fc07d2f6bfcc605d694780da
Diffstat (limited to 'client')
-rw-r--r-- | client/api.c | 20 | ||||
-rw-r--r-- | client/libremctl.map | 1 | ||||
-rw-r--r-- | client/libremctl.sym | 1 | ||||
-rw-r--r-- | client/remctl.h | 12 |
4 files changed, 32 insertions, 2 deletions
diff --git a/client/api.c b/client/api.c index ba5cb13..5cec897 100644 --- a/client/api.c +++ b/client/api.c @@ -11,7 +11,7 @@ * * Written by Russ Allbery <rra@stanford.edu> * Based on work by Anton Ushakov - * Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011 + * Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 * The Board of Trustees of the Leland Stanford Junior University * * See LICENSE for licensing terms. @@ -24,6 +24,7 @@ #include <portable/uio.h> #include <errno.h> +#include <time.h> #include <client/internal.h> #include <client/remctl.h> @@ -288,6 +289,23 @@ remctl_set_source_ip(struct remctl *r, const char *source) /* + * Set the network timeout in seconds, which may be 0 to not use any timeout + * (the default). Returns true on success, false on an invalid timeout, such + * as a negative value. + */ +int +remctl_set_timeout(struct remctl *r, time_t timeout) +{ + if (timeout < 0) { + internal_set_error(r, "invalid timeout %ld", (long) timeout); + return 0; + } + r->timeout = timeout; + return 1; +} + + +/* * Open a new persistant remctl connection to a server, given the host, port, * and principal. Returns true on success and false on failure. */ diff --git a/client/libremctl.map b/client/libremctl.map index 287de0f..8cfa11c 100644 --- a/client/libremctl.map +++ b/client/libremctl.map @@ -12,6 +12,7 @@ REMCTL_1.0 { remctl_result_free; remctl_set_ccache; remctl_set_source_ip; + remctl_set_timeout; local: *; diff --git a/client/libremctl.sym b/client/libremctl.sym index 091e39c..d49dbae 100644 --- a/client/libremctl.sym +++ b/client/libremctl.sym @@ -10,3 +10,4 @@ remctl_output remctl_result_free remctl_set_ccache remctl_set_source_ip +remctl_set_timeout diff --git a/client/remctl.h b/client/remctl.h index 56f4ec5..12e9d28 100644 --- a/client/remctl.h +++ b/client/remctl.h @@ -3,7 +3,7 @@ * * Written by Russ Allbery <rra@stanford.edu> * Based on prior work by Anton Ushakov - * Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2011 + * Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 * The Board of Trustees of the Leland Stanford Junior University * * Permission to use, copy, modify, and distribute this software and its @@ -145,6 +145,16 @@ int remctl_set_ccache(struct remctl *, const char *); int remctl_set_source_ip(struct remctl *, const char *); /* + * Set the network timeout, which may be 0 to not use any timeout (the + * default). If remctl_set_timeout is called before remctl_open, that timeout + * (in seconds) will be used for each network action, both connect and packet + * reads and writes. Returns true on success, false on failure (only possible + * with an invalid timeout, such as a negative value). On failure, use + * remctl_error to get the error. + */ +int remctl_set_timeout(struct remctl *, time_t); + +/* * Send a complete remote command. Returns true on success, false on failure. * On failure, use remctl_error to get the error. There are two forms of this * function; remctl_command takes a NULL-terminated array of nul-terminated |