aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2013-11-06 14:11:52 -0500
committerAndreas Schneider <asn@cryptomilk.org>2013-11-09 12:29:25 +0100
commit7372cd837ac97a3be853843f0eb08da073e7310d (patch)
tree65f4023b3110226ed513252961a89ec3759171ad /src
parent1ecf7003f6c7088c567e41029d31adac73dd7903 (diff)
downloadlibssh-7372cd837ac97a3be853843f0eb08da073e7310d.tar.gz
libssh-7372cd837ac97a3be853843f0eb08da073e7310d.tar.xz
libssh-7372cd837ac97a3be853843f0eb08da073e7310d.zip
Add ssh_get_poll_flags()
For integration with an external mainloop, we need to know how to replicate libssh's internal poll() calls. We originally through ssh_get_status() was that API, but it's not really - those flags only get updated from the *result* of a poll(), where what we really need is to know how libssh would *start* a poll(). Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r--src/session.c19
-rw-r--r--src/socket.c11
2 files changed, 30 insertions, 0 deletions
diff --git a/src/session.c b/src/session.c
index d4b3643f..06e7567f 100644
--- a/src/session.c
+++ b/src/session.c
@@ -608,6 +608,25 @@ int ssh_get_status(ssh_session session) {
}
/**
+ * @brief Get poll flags for an external mainloop
+ *
+ * @param session The ssh session to use.
+ *
+ * @returns A bitmask including SSH_READ_PENDING or SSH_WRITE_PENDING.
+ * For SSH_READ_PENDING, your invocation of poll() should include
+ * POLLIN. For SSH_WRITE_PENDING, your invocation of poll() should
+ * include POLLOUT.
+ */
+int ssh_get_poll_flags(ssh_session session)
+{
+ if (session == NULL) {
+ return 0;
+ }
+
+ return ssh_socket_get_poll_flags (session->socket);
+}
+
+/**
* @brief Get the disconnect message from the server.
*
* @param[in] session The ssh session to use.
diff --git a/src/socket.c b/src/socket.c
index c76ef5ae..d7cf5397 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -710,6 +710,17 @@ int ssh_socket_get_status(ssh_socket s) {
return r;
}
+int ssh_socket_get_poll_flags(ssh_socket s) {
+ int r = 0;
+ if (s->poll_in != NULL && (ssh_poll_get_events (s->poll_in) & POLLIN) > 0) {
+ r |= SSH_READ_PENDING;
+ }
+ if (s->poll_out != NULL && (ssh_poll_get_events (s->poll_out) & POLLOUT) > 0) {
+ r |= SSH_WRITE_PENDING;
+ }
+ return r;
+}
+
#ifdef _WIN32
int ssh_socket_set_nonblocking(socket_t fd) {
u_long nonblocking = 1;