aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2013-05-20 17:32:18 +0200
committerAndreas Schneider <asn@cryptomilk.org>2013-07-13 14:58:47 +0200
commit560b5087714e793ccb8a2776e2ec1fdbd8b8ee3f (patch)
tree0aeb88dd92e4a34962109910fb2aee29885bfd1f
parentf528f71920b6b7e8ccb9441d47b27c096a7989d3 (diff)
downloadlibssh-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>
-rw-r--r--src/poll.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/poll.c b/src/poll.c
index 932c4918..85ee655d 100644
--- a/src/poll.c
+++ b/src/poll.c
@@ -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++;
}