diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2011-01-10 17:39:47 +0100 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2011-01-10 17:39:47 +0100 |
commit | bcea8921ba279712efc79dc46bbe427bc70d8def (patch) | |
tree | f82cfa6c506b250d4da81d4638290a39b0133fbb | |
parent | 076dfb82942384d9839f779a986b95932a754c9e (diff) | |
download | libssh-bcea8921ba279712efc79dc46bbe427bc70d8def.tar.gz libssh-bcea8921ba279712efc79dc46bbe427bc70d8def.tar.xz libssh-bcea8921ba279712efc79dc46bbe427bc70d8def.zip |
Change blocking parameter to a flag
-rw-r--r-- | include/libssh/libssh.h | 1 | ||||
-rw-r--r-- | include/libssh/session.h | 8 | ||||
-rw-r--r-- | src/session.c | 16 |
3 files changed, 20 insertions, 5 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index 77af789..5a3505c 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -384,6 +384,7 @@ LIBSSH_API int ssh_get_random(void *where,int len,int strong); LIBSSH_API int ssh_get_version(ssh_session session); LIBSSH_API int ssh_get_status(ssh_session session); LIBSSH_API int ssh_init(void); +LIBSSH_API int ssh_is_blocking(ssh_session session); LIBSSH_API int ssh_is_server_known(ssh_session session); LIBSSH_API void ssh_log(ssh_session session, int prioriry, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); LIBSSH_API ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg); diff --git a/include/libssh/session.h b/include/libssh/session.h index a2cdfa0..406ba13 100644 --- a/include/libssh/session.h +++ b/include/libssh/session.h @@ -51,6 +51,10 @@ enum ssh_dh_state_e { DH_STATE_FINISHED }; + +/* libssh calls may block an undefined amount of time */ +#define SSH_SESSION_FLAG_BLOCKING 1 + struct ssh_session_struct { struct error_struct error; struct ssh_socket_struct *socket; @@ -72,8 +76,8 @@ struct ssh_session_struct { /* two previous are deprecated */ /* int auth_service_asked; */ -/* socket status */ - int blocking; /* functions should block */ + /* session flags (SSH_SESSION_FLAG_*) */ + int flags; ssh_string banner; /* that's the issue banner from the server */ diff --git a/src/session.c b/src/session.c index cb6382e..c862e71 100644 --- a/src/session.c +++ b/src/session.c @@ -85,7 +85,7 @@ ssh_session ssh_new(void) { session->alive = 0; session->auth_methods = 0; - session->blocking = 1; + ssh_set_blocking(session, 1); session->log_indent = 0; session->maxchannel = FIRST_CHANNEL; @@ -280,11 +280,21 @@ void ssh_silent_disconnect(ssh_session session) { * \bug nonblocking code is in development and won't work as expected */ void ssh_set_blocking(ssh_session session, int blocking) { - if (session == NULL) { + if (session == NULL) { return; } + session->flags &= ~SSH_SESSION_FLAG_BLOCKING; + session->flags |= blocking ? SSH_SESSION_FLAG_BLOCKING : 0; +} - session->blocking = blocking ? 1 : 0; +/** + * @brief Return the blocking mode of libssh + * @param[in] session The SSH session + * @returns 0 if the session is nonblocking, + * @returns 1 if the functions may block. + */ +int ssh_is_blocking(ssh_session session){ + return (session->flags&SSH_SESSION_FLAG_BLOCKING) ? 1 : 0; } /** |