summaryrefslogtreecommitdiffstats
path: root/libssh/poll.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2009-12-11 21:11:23 +0100
committerAris Adamantiadis <aris@0xbadc0de.be>2009-12-11 21:11:23 +0100
commit80b6cf77b03a6a29f76bdb4768b2b2c6d7d37495 (patch)
tree418c1cea022addfb08152887f7c3f47ec0798d58 /libssh/poll.c
parent79b4bf4ac2811d868c7c27830fd5538e21cb33a8 (diff)
downloadlibssh-80b6cf77b03a6a29f76bdb4768b2b2c6d7d37495.tar.gz
libssh-80b6cf77b03a6a29f76bdb4768b2b2c6d7d37495.tar.xz
libssh-80b6cf77b03a6a29f76bdb4768b2b2c6d7d37495.zip
Added a global poll context
Diffstat (limited to 'libssh/poll.c')
-rw-r--r--libssh/poll.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libssh/poll.c b/libssh/poll.c
index 42da4aa..ac86750 100644
--- a/libssh/poll.c
+++ b/libssh/poll.c
@@ -39,6 +39,9 @@
#define SSH_POLL_CTX_CHUNK 5
#endif
+/** global poll context used for blocking operations */
+static ssh_poll_ctx global_poll_ctx;
+
struct ssh_poll_handle_struct {
ssh_poll_ctx ctx;
union {
@@ -580,3 +583,31 @@ int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout) {
return rc;
}
+
+/** @internal
+ * @brief returns a pointer to the global poll context.
+ * Allocates it if it does not exist.
+ * @param session an optional session handler, used to store the error
+ * message if needed.
+ * @returns pointer to the global poll context.
+ */
+ssh_poll_ctx ssh_get_global_poll_ctx(ssh_session session){
+ if(global_poll_ctx != NULL)
+ return global_poll_ctx;
+ global_poll_ctx=ssh_poll_ctx_new(5);
+ if(global_poll_ctx == NULL && session != NULL){
+ ssh_set_error_oom(session);
+ return NULL;
+ }
+ return global_poll_ctx;
+}
+
+/** @internal
+ * @brief Deallocate the global poll context
+ */
+void ssh_free_global_poll_ctx(){
+ if(global_poll_ctx != NULL){
+ ssh_poll_ctx_free(global_poll_ctx);
+ global_poll_ctx=NULL;
+ }
+}