mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-10 06:23:01 +03:00
poll: Started to add a poll based event loop.
This commit is contained in:
@@ -117,6 +117,7 @@ typedef struct ssh_key_struct* ssh_key;
|
||||
typedef struct ssh_scp_struct* ssh_scp;
|
||||
typedef struct ssh_session_struct* ssh_session;
|
||||
typedef struct ssh_string_struct* ssh_string;
|
||||
typedef struct ssh_event_struct* ssh_event;
|
||||
|
||||
/* Socket type */
|
||||
#ifdef _WIN32
|
||||
@@ -474,6 +475,8 @@ LIBSSH_API void ssh_string_free_char(char *s);
|
||||
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);
|
||||
|
||||
#ifndef LIBSSH_LEGACY_0_4
|
||||
#include "libssh/legacy.h"
|
||||
#endif
|
||||
|
49
src/poll.c
49
src/poll.c
@@ -34,6 +34,11 @@
|
||||
#include "libssh/poll.h"
|
||||
#include "libssh/socket.h"
|
||||
#include "libssh/session.h"
|
||||
#ifdef WITH_SERVER
|
||||
#include "libssh/server.h"
|
||||
#include "libssh/misc.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef SSH_POLL_CTX_CHUNK
|
||||
#define SSH_POLL_CTX_CHUNK 5
|
||||
@@ -678,6 +683,50 @@ ssh_poll_ctx ssh_poll_get_default_ctx(ssh_session session){
|
||||
return session->default_poll_ctx;
|
||||
}
|
||||
|
||||
/* public event API */
|
||||
|
||||
struct ssh_event_struct {
|
||||
ssh_poll_ctx ctx;
|
||||
#ifdef WITH_SERVER
|
||||
struct ssh_list *sessions;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Create a new event context. It could be associated with many
|
||||
* ssh_session objects and socket fd which are going to be polled at the
|
||||
* same time as the event context. You would need a single event context
|
||||
* per thread.
|
||||
*
|
||||
* @return The ssh_event object on success, NULL on failure.
|
||||
*/
|
||||
ssh_event ssh_event_new(void) {
|
||||
ssh_event event;
|
||||
|
||||
event = malloc(sizeof(struct ssh_event_struct));
|
||||
if (event == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ZERO_STRUCTP(event);
|
||||
|
||||
event->ctx = ssh_poll_ctx_new(2);
|
||||
if(event->ctx == NULL) {
|
||||
free(event);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef WITH_SERVER
|
||||
event->sessions = ssh_list_new();
|
||||
if(event->sessions == NULL) {
|
||||
ssh_poll_ctx_free(event->ctx);
|
||||
free(event);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
/* vim: set ts=4 sw=4 et cindent: */
|
||||
|
Reference in New Issue
Block a user