aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormilo <milo@r0ot.me>2011-02-20 14:06:57 +0100
committermilo <milo@r0ot.me>2011-02-20 14:37:43 +0100
commitddb1c1838f35818db92809d92c999a1352be5521 (patch)
tree5b9fb36013c5fda82b526aa8c06949655fa168b3 /src
parente40261c22ce8630558fdadf2932f472793528a1b (diff)
downloadlibssh-ddb1c1838f35818db92809d92c999a1352be5521.tar.gz
libssh-ddb1c1838f35818db92809d92c999a1352be5521.tar.xz
libssh-ddb1c1838f35818db92809d92c999a1352be5521.zip
poll: Added a function to poll the events.
Diffstat (limited to 'src')
-rw-r--r--src/poll.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/poll.c b/src/poll.c
index bfb54e6..79dbb49 100644
--- a/src/poll.c
+++ b/src/poll.c
@@ -836,6 +836,44 @@ int ssh_event_add_session(ssh_event event, ssh_session session) {
}
/**
+ * @brief Poll all the sockets and sessions associated through an event object.
+ * If any of the events are set after the poll, the
+ * call back functions of the sessions or sockets will be called.
+ * This function should be called once within the programs main loop.
+ *
+ * @param event The ssh_event object to poll.
+ * @param timeout An upper limit on the time for which the poll will
+ * block, in milliseconds. Specifying a negative value
+ * means an infinite timeout. This parameter is passed to
+ * the poll() function.
+ * @returns SSH_OK No error.
+ * SSH_ERROR Error happened during the poll.
+ */
+int ssh_event_dopoll(ssh_event event, int timeout) {
+ int rc;
+#ifdef WITH_SERVER
+ ssh_session session;
+ struct ssh_iterator *iterator;
+#endif
+
+ if(event == NULL || event->ctx == NULL) {
+ return SSH_ERROR;
+ }
+ rc = ssh_poll_ctx_dopoll(event->ctx, timeout);
+#ifdef WITH_SERVER
+ if(rc == SSH_OK) {
+ iterator = ssh_list_get_iterator(event->sessions);
+ while(iterator != NULL) {
+ session = (ssh_session)iterator->data;
+ ssh_execute_message_callbacks(session);
+ iterator = iterator->next;
+ }
+ }
+#endif
+ return rc;
+}
+
+/**
* @brief Remove a socket fd from an event context.
*
* @param event The ssh_event object.