diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2013-05-20 17:32:18 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2013-07-13 14:58:47 +0200 |
commit | 560b5087714e793ccb8a2776e2ec1fdbd8b8ee3f (patch) | |
tree | 0aeb88dd92e4a34962109910fb2aee29885bfd1f /src | |
parent | f528f71920b6b7e8ccb9441d47b27c096a7989d3 (diff) | |
download | libssh-560b5087714e793ccb8a2776e2ec1fdbd8b8ee3f.tar.gz libssh-560b5087714e793ccb8a2776e2ec1fdbd8b8ee3f.tar.xz libssh-560b5087714e793ccb8a2776e2ec1fdbd8b8ee3f.zip |
events: don't poll handles busy handling callbacks
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/poll.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -69,6 +69,7 @@ struct ssh_poll_handle_struct { size_t idx; } x; short events; + int lock; ssh_poll_callback cb; void *cb_data; }; @@ -336,7 +337,7 @@ short ssh_poll_get_events(ssh_poll_handle p) { */ void ssh_poll_set_events(ssh_poll_handle p, short events) { p->events = events; - if (p->ctx != NULL) { + if (p->ctx != NULL && !p->lock) { p->ctx->pollfds[p->x.idx].events = events; } } @@ -595,7 +596,7 @@ int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout) { return SSH_AGAIN; used = ctx->polls_used; for (i = 0; i < used && rc > 0; ) { - if (!ctx->pollfds[i].revents) { + if (!ctx->pollfds[i].revents || ctx->pollptrs[i]->lock) { i++; } else { int ret; @@ -603,7 +604,9 @@ int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout) { p = ctx->pollptrs[i]; fd = ctx->pollfds[i].fd; revents = ctx->pollfds[i].revents; - + /* avoid having any event caught during callback */ + ctx->pollfds[i].events = 0; + p->lock = 1; if (p->cb && (ret = p->cb(p, fd, revents, p->cb_data)) < 0) { if (ret == -2) { return -1; @@ -613,6 +616,8 @@ int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout) { i=0; } else { ctx->pollfds[i].revents = 0; + ctx->pollfds[i].events = p->events; + p->lock = 0; i++; } |