diff options
author | rofl0r <retnyg@gmx.net> | 2011-12-31 02:15:16 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2012-01-02 12:39:43 +0100 |
commit | 4305da29a19446ccd2ab83c6b42cbd037fe377a3 (patch) | |
tree | 1d642f1930c42faeb89734234bf2c1e32b18e464 /src/misc.c | |
parent | 2f861a858be9f2fe1f55a0fbfc47d732e3b3b31b (diff) | |
download | libssh-4305da29a19446ccd2ab83c6b42cbd037fe377a3.tar.gz libssh-4305da29a19446ccd2ab83c6b42cbd037fe377a3.tar.xz libssh-4305da29a19446ccd2ab83c6b42cbd037fe377a3.zip |
session: Cleanup timeout functions.
It is possible that we get unrelated packets while waiting for
termination, thus waiting indefinitely. As a workaround we have to
check the user-supplied timeout.
Diffstat (limited to 'src/misc.c')
-rw-r--r-- | src/misc.c | 48 |
1 files changed, 38 insertions, 10 deletions
@@ -921,6 +921,24 @@ static int ssh_timestamp_difference(struct ssh_timestamp *old, /** * @internal + * @brief turn seconds and microseconds pair (as provided by user-set options) + * into millisecond value + * @param[in] sec number of seconds + * @param[in] usec number of microseconds + * @returns milliseconds, or 10000 if user supplied values are equal to zero + */ +int ssh_make_milliseconds(long sec, long usec) { + int res = usec ? (usec / 1000) : 0; + res += (sec * 1000); + if (res == 0) { + res = 10 * 1000; /* use a reasonable default value in case + * SSH_OPTIONS_TIMEOUT is not set in options. */ + } + return res; +} + +/** + * @internal * @brief Checks if a timeout is elapsed, in function of a previous * timestamp and an assigned timeout * @param[in] ts pointer to an existing timestamp @@ -930,17 +948,27 @@ static int ssh_timestamp_difference(struct ssh_timestamp *old, * 0 otherwise */ int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout) { - struct ssh_timestamp now; - if(timeout < 0) - return 0; // -1 means infinite timeout - if(timeout == SSH_TIMEOUT_NONBLOCKING) - return 1; // 0 means no timeout - ssh_timestamp_init(&now); + struct ssh_timestamp now; + + switch(timeout) { + case -2: /* + * -2 means user-defined timeout as available in + * session->timeout, session->timeout_usec. + */ + fprintf(stderr, "ssh_timeout_elapsed called with -2. this needs to " + "be fixed. please set a breakpoint on %s:%d and " + "fix the caller\n", __FILE__, __LINE__); + case -1: /* -1 means infinite timeout */ + return 0; + case 0: /* 0 means no timeout */ + return 1; + default: + break; + } - if(ssh_timestamp_difference(ts,&now) >= timeout) - return 1; - else - return 0; + ssh_timestamp_init(&now); + + return (ssh_timestamp_difference(ts,&now) >= timeout); } /** |