session: Introduce SSH_TIMEOUT_DEFAULT
The default timeout of 30seconds is very nice when connecting to a new SSH session, however it completely breaks the synchronous blocking API. Use SSH_TIMEOUT_DEFAULT when in blocking mode so channel reads&write are blocking as expected Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
родитель
6bc64c368d
Коммит
66b37c856c
@ -69,8 +69,13 @@ enum ssh_pending_call_e {
|
|||||||
#define SSH_SESSION_FLAG_AUTHENTICATED 2
|
#define SSH_SESSION_FLAG_AUTHENTICATED 2
|
||||||
|
|
||||||
/* codes to use with ssh_handle_packets*() */
|
/* codes to use with ssh_handle_packets*() */
|
||||||
|
/* Infinite timeout */
|
||||||
#define SSH_TIMEOUT_INFINITE -1
|
#define SSH_TIMEOUT_INFINITE -1
|
||||||
|
/* Use the timeout defined by user if any. Mostly used with new connections */
|
||||||
#define SSH_TIMEOUT_USER -2
|
#define SSH_TIMEOUT_USER -2
|
||||||
|
/* Use the default timeout, depending on ssh_is_blocking() */
|
||||||
|
#define SSH_TIMEOUT_DEFAULT -3
|
||||||
|
/* Don't block at all */
|
||||||
#define SSH_TIMEOUT_NONBLOCKING 0
|
#define SSH_TIMEOUT_NONBLOCKING 0
|
||||||
|
|
||||||
/* members that are common to ssh_session and ssh_bind */
|
/* members that are common to ssh_session and ssh_bind */
|
||||||
|
@ -1222,7 +1222,7 @@ static int ssh_waitsession_unblocked(void *s){
|
|||||||
* SSH_AGAIN Timeout elapsed (or in nonblocking mode)
|
* SSH_AGAIN Timeout elapsed (or in nonblocking mode)
|
||||||
*/
|
*/
|
||||||
int ssh_channel_flush(ssh_channel channel){
|
int ssh_channel_flush(ssh_channel channel){
|
||||||
return ssh_blocking_flush(channel->session, SSH_TIMEOUT_USER);
|
return ssh_blocking_flush(channel->session, SSH_TIMEOUT_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
int channel_write_common(ssh_channel channel, const void *data,
|
int channel_write_common(ssh_channel channel, const void *data,
|
||||||
@ -1282,7 +1282,7 @@ int channel_write_common(ssh_channel channel, const void *data,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (ssh_waitsession_unblocked(session) == 0){
|
if (ssh_waitsession_unblocked(session) == 0){
|
||||||
rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_USER,
|
rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_DEFAULT,
|
||||||
ssh_waitsession_unblocked, session);
|
ssh_waitsession_unblocked, session);
|
||||||
if (rc == SSH_ERROR || !ssh_waitsession_unblocked(session))
|
if (rc == SSH_ERROR || !ssh_waitsession_unblocked(session))
|
||||||
goto out;
|
goto out;
|
||||||
@ -1298,7 +1298,7 @@ int channel_write_common(ssh_channel channel, const void *data,
|
|||||||
/* nothing can be written */
|
/* nothing can be written */
|
||||||
ssh_log(session, SSH_LOG_PROTOCOL,
|
ssh_log(session, SSH_LOG_PROTOCOL,
|
||||||
"Wait for a growing window message...");
|
"Wait for a growing window message...");
|
||||||
rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_USER,
|
rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_DEFAULT,
|
||||||
ssh_channel_waitwindow_termination,channel);
|
ssh_channel_waitwindow_termination,channel);
|
||||||
if (rc == SSH_ERROR || !ssh_channel_waitwindow_termination(channel))
|
if (rc == SSH_ERROR || !ssh_channel_waitwindow_termination(channel))
|
||||||
goto out;
|
goto out;
|
||||||
@ -2681,13 +2681,13 @@ int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_std
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* block reading until all bytes are read
|
/* block reading until at least one byte has been read
|
||||||
* and ignore the trivial case count=0
|
* and ignore the trivial case count=0
|
||||||
*/
|
*/
|
||||||
ctx.channel = channel;
|
ctx.channel = channel;
|
||||||
ctx.buffer = stdbuf;
|
ctx.buffer = stdbuf;
|
||||||
ctx.count = count;
|
ctx.count = 1;
|
||||||
rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_USER,
|
rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_DEFAULT,
|
||||||
ssh_channel_read_termination, &ctx);
|
ssh_channel_read_termination, &ctx);
|
||||||
if (rc == SSH_ERROR){
|
if (rc == SSH_ERROR){
|
||||||
leave_function();
|
leave_function();
|
||||||
|
@ -512,6 +512,7 @@ int ssh_handle_packets(ssh_session session, int timeout) {
|
|||||||
* (-1) means an infinite timeout.
|
* (-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 immediately.
|
||||||
|
* SSH_TIMEOUT_DEFAULT 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
|
||||||
@ -530,6 +531,11 @@ int ssh_handle_packets_termination(ssh_session session, int timeout,
|
|||||||
session->opts.timeout_usec);
|
session->opts.timeout_usec);
|
||||||
else
|
else
|
||||||
timeout = SSH_TIMEOUT_NONBLOCKING;
|
timeout = SSH_TIMEOUT_NONBLOCKING;
|
||||||
|
} else if (timeout == SSH_TIMEOUT_DEFAULT){
|
||||||
|
if(ssh_is_blocking(session))
|
||||||
|
timeout = SSH_TIMEOUT_INFINITE;
|
||||||
|
else
|
||||||
|
timeout = SSH_TIMEOUT_NONBLOCKING;
|
||||||
}
|
}
|
||||||
ssh_timestamp_init(&ts);
|
ssh_timestamp_init(&ts);
|
||||||
tm = timeout;
|
tm = timeout;
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user