aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilo <milo@r0ot.me>2011-02-20 13:56:40 +0100
committermilo <milo@r0ot.me>2011-02-20 14:36:44 +0100
commit4b72953c7eea7da69f7a7f7d2f48f4ef5d0cf433 (patch)
treeb69895e460f44ce2e58911d39dec8031b17cdc8a
parent4ee4450a6b37a099a067f6e1e9a61f566cce9247 (diff)
downloadlibssh-4b72953c7eea7da69f7a7f7d2f48f4ef5d0cf433.tar.gz
libssh-4b72953c7eea7da69f7a7f7d2f48f4ef5d0cf433.tar.xz
libssh-4b72953c7eea7da69f7a7f7d2f48f4ef5d0cf433.zip
poll: Added function to add session to an event.
-rw-r--r--include/libssh/libssh.h1
-rw-r--r--src/poll.c44
2 files changed, 45 insertions, 0 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index 3fc7b6c6..0cb96006 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -476,6 +476,7 @@ LIBSSH_API int ssh_getpass(const char *prompt, char *buf, size_t len, int echo,
int verify);
LIBSSH_API ssh_event ssh_event_new(void);
+LIBSSH_API int ssh_event_add_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 00ce4043..c265c9df 100644
--- a/src/poll.c
+++ b/src/poll.c
@@ -728,6 +728,50 @@ ssh_event ssh_event_new(void) {
}
/**
+ * @brief remove the poll handle from session and assign them to a event,
+ * when used in blocking mode.
+ *
+ * @param event The ssh_event object
+ * @param session The session to add to the event.
+ *
+ * @returns SSH_OK on success
+ * SSH_ERROR on failure
+ */
+int ssh_event_add_session(ssh_event event, ssh_session session) {
+ unsigned int i;
+ ssh_poll_handle p;
+#ifdef WITH_SERVER
+ struct ssh_iterator *iterator;
+#endif
+
+ if(event == NULL || event->ctx == NULL || session == NULL) {
+ return SSH_ERROR;
+ }
+ if(session->default_poll_ctx == NULL) {
+ return SSH_ERROR;
+ }
+ for(i = 0; i < session->default_poll_ctx->polls_used; i++) {
+ p = session->default_poll_ctx->pollptrs[i];
+ ssh_poll_ctx_remove(session->default_poll_ctx, p);
+ ssh_poll_ctx_add(event->ctx, p);
+ }
+#ifdef WITH_SERVER
+ iterator = ssh_list_get_iterator(event->sessions);
+ while(iterator != NULL) {
+ if((ssh_session)iterator->data == session) {
+ /* allow only one instance of this session */
+ return SSH_OK;
+ }
+ iterator = iterator->next;
+ }
+ if(ssh_list_append(event->sessions, session) == SSH_ERROR) {
+ return SSH_ERROR;
+ }
+#endif
+ return SSH_OK;
+}
+
+/**
* @brief Free an event context.
*
* @param event The ssh_event object to free.