aboutsummaryrefslogtreecommitdiff
path: root/src/session.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2011-01-12 23:04:43 +0100
committerAris Adamantiadis <aris@0xbadc0de.be>2011-01-12 23:04:43 +0100
commit5b6f048197a56d0b45ad642431f2b5ee718c53e9 (patch)
tree877882858e7d6301dc7e660eef9e2dbbdddc8bed /src/session.c
parenta17472ff2b723059841d194c19ad65b0d76b7860 (diff)
downloadlibssh-5b6f048197a56d0b45ad642431f2b5ee718c53e9.tar.gz
libssh-5b6f048197a56d0b45ad642431f2b5ee718c53e9.tar.xz
libssh-5b6f048197a56d0b45ad642431f2b5ee718c53e9.zip
Use termination functions for event polling
Diffstat (limited to 'src/session.c')
-rw-r--r--src/session.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/session.c b/src/session.c
index c862e714..83436dc2 100644
--- a/src/session.c
+++ b/src/session.c
@@ -396,6 +396,43 @@ int ssh_handle_packets(ssh_session session, int timeout) {
}
/**
+ * @internal
+ *
+ * @brief Poll the current session for an event and call the appropriate
+ * callbacks.
+ *
+ * This will block until termination fuction returns true, or timeout expired.
+ *
+ * @param[in] session The session handle to use.
+ *
+ * @param[in] timeout Set an upper limit on the time for which this function
+ * will block, in milliseconds. Specifying a negative value
+ * means an infinite timeout. This parameter is passed to
+ * the poll() function.
+ * @param[in] fct Termination function to be used to determine if it is
+ * possible to stop polling.
+ * @param[in] user User parameter to be passed to fct termination function.
+ * @return SSH_OK on success, SSH_ERROR otherwise.
+ */
+int ssh_handle_packets_termination(ssh_session session, int timeout,
+ ssh_termination_function fct, void *user){
+ int ret;
+ while(!fct(user)){
+ ret = ssh_handle_packets(session, timeout);
+ if(ret == SSH_ERROR)
+ return SSH_ERROR;
+ if(timeout == 0){
+ if(fct(user))
+ return SSH_OK;
+ else
+ return SSH_AGAIN;
+ }
+ /* TODO: verify that total timeout has not expired and then return SSH_AGAIN */
+ }
+ return ret;
+}
+
+/**
* @brief Get session status
*
* @param session The ssh session to use.