diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-04-14 14:50:11 +0000 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-04-14 14:50:11 +0000 |
commit | 8e34f0cf0cd5dba21fc19125dced3fd541f835b3 (patch) | |
tree | 5aa56d9ddf4184f6700cee484e91ff4af2c762d8 /libssh/session.c | |
parent | 16084e548ed60ff474887a762c0cd146bfd64fd0 (diff) | |
download | libssh-8e34f0cf0cd5dba21fc19125dced3fd541f835b3.tar.gz libssh-8e34f0cf0cd5dba21fc19125dced3fd541f835b3.tar.xz libssh-8e34f0cf0cd5dba21fc19125dced3fd541f835b3.zip |
Improve ssh_get_status().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@475 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/session.c')
-rw-r--r-- | libssh/session.c | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/libssh/session.c b/libssh/session.c index 60e47681..05a08eee 100644 --- a/libssh/session.c +++ b/libssh/session.c @@ -261,21 +261,36 @@ int ssh_handle_packets(SSH_SESSION *session) { return rc; } -/** \brief get session status - * \param session ssh session - * \returns a bitmask including SSH_CLOSED, SSH_READ_PENDING or SSH_CLOSED_ERROR - * which respectively means the session is closed, has data to read on the connection socket and session was closed due to an error +/** + * @brief Get session status + * + * @param session The ssh session to use. + * + * @returns A bitmask including SSH_CLOSED, SSH_READ_PENDING or SSH_CLOSED_ERROR + * which respectively means the session is closed, has data to read on + * the connection socket and session was closed due to an error. */ -int ssh_get_status(SSH_SESSION *session){ - int ret=0; - int socketstate=ssh_socket_get_status(session->socket); - if(session->closed) - ret |= SSH_CLOSED; - if(socketstate & SSH_READ_PENDING) - ret |= SSH_READ_PENDING; - if(session->closed && socketstate & SSH_CLOSED_ERROR) - ret |= SSH_CLOSED_ERROR; - return ret; +int ssh_get_status(SSH_SESSION *session) { + int socketstate; + int r = 0; + + if (session == NULL) { + return 0; + } + + socketstate = ssh_socket_get_status(session->socket); + + if (session->closed) { + r |= SSH_CLOSED; + } + if (socketstate & SSH_READ_PENDING) { + r |= SSH_READ_PENDING; + } + if (session->closed && (socketstate & SSH_CLOSED_ERROR)) { + r |= SSH_CLOSED_ERROR; + } + + return r; } /** \brief get the disconnect message from the server |