mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-02 01:17:52 +03:00
session: Check the session timeout and use it if set
This checks if a timeout has been set using ssh_options_set(). If it has been set it will use that parametr by default for blocking sessions. This is at least what users are expecting. Fixes T33 Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
@@ -2751,7 +2751,7 @@ int ssh_channel_read_timeout(ssh_channel channel,
|
|||||||
ctx.buffer = stdbuf;
|
ctx.buffer = stdbuf;
|
||||||
ctx.count = 1;
|
ctx.count = 1;
|
||||||
|
|
||||||
if (timeout_ms < 0) {
|
if (timeout_ms < SSH_TIMEOUT_DEFAULT) {
|
||||||
timeout_ms = SSH_TIMEOUT_INFINITE;
|
timeout_ms = SSH_TIMEOUT_INFINITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -645,11 +645,13 @@ int ssh_handle_packets(ssh_session session, int timeout) {
|
|||||||
* @param[in] session The session handle to use.
|
* @param[in] session The session handle to use.
|
||||||
*
|
*
|
||||||
* @param[in] timeout Set an upper limit on the time for which this function
|
* @param[in] timeout Set an upper limit on the time for which this function
|
||||||
* will block, in milliseconds. Specifying SSH_TIMEOUT_INFINITE
|
* will block, in milliseconds. Specifying
|
||||||
* (-1) means an infinite timeout.
|
* SSH_TIMEOUT_INFINITE (-1) means an infinite timeout.
|
||||||
* Specifying SSH_TIMEOUT_USER means to use the timeout
|
* Specifying SSH_TIMEOUT_USER means to use the timeout
|
||||||
* specified in options. 0 means poll will return immediately.
|
* specified in options. 0 means poll will return
|
||||||
* SSH_TIMEOUT_DEFAULT uses blocking parameters of the session.
|
* immediately.
|
||||||
|
* SSH_TIMEOUT_DEFAULT uses the session timeout if set or
|
||||||
|
* uses blocking parameters of the session.
|
||||||
* This parameter is passed to the poll() function.
|
* This parameter is passed to the poll() function.
|
||||||
*
|
*
|
||||||
* @param[in] fct Termination function to be used to determine if it is
|
* @param[in] fct Termination function to be used to determine if it is
|
||||||
@@ -663,41 +665,45 @@ int ssh_handle_packets_termination(ssh_session session,
|
|||||||
void *user)
|
void *user)
|
||||||
{
|
{
|
||||||
struct ssh_timestamp ts;
|
struct ssh_timestamp ts;
|
||||||
|
long timeout_ms = SSH_TIMEOUT_INFINITE;
|
||||||
|
long tm;
|
||||||
int ret = SSH_OK;
|
int ret = SSH_OK;
|
||||||
int tm;
|
|
||||||
|
|
||||||
if (timeout == SSH_TIMEOUT_USER) {
|
/* If a timeout has been provided, use it */
|
||||||
|
if (timeout > 0) {
|
||||||
|
timeout_ms = timeout;
|
||||||
|
} else {
|
||||||
if (ssh_is_blocking(session)) {
|
if (ssh_is_blocking(session)) {
|
||||||
timeout = ssh_make_milliseconds(session->opts.timeout,
|
if (timeout == SSH_TIMEOUT_USER || timeout == SSH_TIMEOUT_DEFAULT) {
|
||||||
|
if (session->opts.timeout > 0 ||
|
||||||
|
session->opts.timeout_usec > 0) {
|
||||||
|
timeout_ms =
|
||||||
|
ssh_make_milliseconds(session->opts.timeout,
|
||||||
session->opts.timeout_usec);
|
session->opts.timeout_usec);
|
||||||
} else {
|
|
||||||
timeout = SSH_TIMEOUT_NONBLOCKING;
|
|
||||||
}
|
}
|
||||||
} else if (timeout == SSH_TIMEOUT_DEFAULT) {
|
}
|
||||||
if (ssh_is_blocking(session)) {
|
|
||||||
timeout = SSH_TIMEOUT_INFINITE;
|
|
||||||
} else {
|
} else {
|
||||||
timeout = SSH_TIMEOUT_NONBLOCKING;
|
timeout_ms = SSH_TIMEOUT_NONBLOCKING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* avoid unnecessary syscall for the SSH_TIMEOUT_NONBLOCKING case */
|
/* avoid unnecessary syscall for the SSH_TIMEOUT_NONBLOCKING case */
|
||||||
if (timeout != SSH_TIMEOUT_NONBLOCKING) {
|
if (timeout_ms != SSH_TIMEOUT_NONBLOCKING) {
|
||||||
ssh_timestamp_init(&ts);
|
ssh_timestamp_init(&ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
tm = timeout;
|
tm = timeout_ms;
|
||||||
while(!fct(user)) {
|
while(!fct(user)) {
|
||||||
ret = ssh_handle_packets(session, tm);
|
ret = ssh_handle_packets(session, tm);
|
||||||
if (ret == SSH_ERROR) {
|
if (ret == SSH_ERROR) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ssh_timeout_elapsed(&ts,timeout)) {
|
if (ssh_timeout_elapsed(&ts, timeout_ms)) {
|
||||||
ret = fct(user) ? SSH_OK : SSH_AGAIN;
|
ret = fct(user) ? SSH_OK : SSH_AGAIN;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
tm = ssh_timeout_update(&ts, timeout);
|
tm = ssh_timeout_update(&ts, timeout_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user