aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilo <milo@r0ot.me>2011-02-20 14:03:19 +0100
committermilo <milo@r0ot.me>2011-02-20 14:37:31 +0100
commit0c76156f5485d490953b2b8674aba77cc5f1b34e (patch)
tree965169b05a4d499a796eec02a17919319cf611b7
parent4b72953c7eea7da69f7a7f7d2f48f4ef5d0cf433 (diff)
downloadlibssh-0c76156f5485d490953b2b8674aba77cc5f1b34e.tar.gz
libssh-0c76156f5485d490953b2b8674aba77cc5f1b34e.tar.xz
libssh-0c76156f5485d490953b2b8674aba77cc5f1b34e.zip
poll: Added function to remove session from event loop.
-rw-r--r--include/libssh/libssh.h1
-rw-r--r--src/poll.c47
2 files changed, 48 insertions, 0 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index 0cb96006..2604b419 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -477,6 +477,7 @@ LIBSSH_API int ssh_getpass(const char *prompt, char *buf, size_t len, int echo,
LIBSSH_API ssh_event ssh_event_new(void);
LIBSSH_API int ssh_event_add_session(ssh_event event, ssh_session session);
+LIBSSH_API int ssh_event_remove_session(ssh_event event, ssh_session session);
LIBSSH_API void ssh_event_free(ssh_event event);
#ifndef LIBSSH_LEGACY_0_4
diff --git a/src/poll.c b/src/poll.c
index c265c9df..618ab01e 100644
--- a/src/poll.c
+++ b/src/poll.c
@@ -772,6 +772,53 @@ int ssh_event_add_session(ssh_event event, ssh_session session) {
}
/**
+ * @brief Remove a session object from an event context.
+ *
+ * @param event The ssh_event object.
+ * @param session The session to remove.
+ *
+ * @returns SSH_OK on success
+ * SSH_ERROR on failure
+ */
+int ssh_event_remove_session(ssh_event event, ssh_session session) {
+ ssh_poll_handle p;
+ register size_t i, used;
+ int rc = SSH_ERROR;
+ socket_t session_fd;
+#ifdef WITH_SERVER
+ struct ssh_iterator *iterator;
+#endif
+
+ if(event == NULL || event->ctx == NULL || session == NULL) {
+ return SSH_ERROR;
+ }
+
+ session_fd = ssh_get_fd(session);
+ used = event->ctx->polls_used;
+ for(i = 0; i < used; i++) {
+ if(session_fd == event->ctx->pollfds[i].fd) {
+ p = event->ctx->pollptrs[i];
+ ssh_poll_ctx_remove(event->ctx, p);
+ ssh_poll_ctx_add(session->default_poll_ctx, p);
+ rc = SSH_OK;
+ }
+ }
+#ifdef WITH_SERVER
+ iterator = ssh_list_get_iterator(event->sessions);
+ while(iterator != NULL) {
+ if((ssh_session)iterator->data == session) {
+ ssh_list_remove(event->sessions, iterator);
+ /* there should be only one instance of this session */
+ break;
+ }
+ iterator = iterator->next;
+ }
+#endif
+
+ return rc;
+}
+
+/**
* @brief Free an event context.
*
* @param event The ssh_event object to free.