aboutsummaryrefslogtreecommitdiff
path: root/libssh/poll.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2010-05-10 23:19:39 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2010-05-10 23:19:39 +0200
commit26d04ff0373a749bc66b6bf2c10a4a2b5c35fd75 (patch)
tree0429129790807a0d36989a115a55d28140040fbf /libssh/poll.c
parent57134818385d89db542f466ea98dbf25f0396700 (diff)
downloadlibssh-26d04ff0373a749bc66b6bf2c10a4a2b5c35fd75.tar.gz
libssh-26d04ff0373a749bc66b6bf2c10a4a2b5c35fd75.tar.xz
libssh-26d04ff0373a749bc66b6bf2c10a4a2b5c35fd75.zip
Fix style in ssh_poll_ctx_dopoll
Also do a rescan of polled events when a poll object has been deleted.
Diffstat (limited to 'libssh/poll.c')
-rw-r--r--libssh/poll.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/libssh/poll.c b/libssh/poll.c
index 56f940a..327c9b2 100644
--- a/libssh/poll.c
+++ b/libssh/poll.c
@@ -516,37 +516,44 @@ void ssh_poll_ctx_remove(ssh_poll_ctx ctx, ssh_poll_handle p) {
* block, in milliseconds. Specifying a negative value
* means an infinite timeout. This parameter is passed to
* the poll() function.
+ * @returns SSH_OK No error.
+ * SSH_ERROR Error happened during the poll.
*/
int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout) {
int rc;
+ int i, used;
+ ssh_poll_handle p;
+ socket_t fd;
+ int revents;
if (!ctx->polls_used)
return 0;
rc = ssh_poll(ctx->pollfds, ctx->polls_used, timeout);
- if (rc > 0) {
- register size_t i, used;
+ if(rc < 0)
+ rc=SSH_ERROR;
+ if(rc <= 0)
+ return rc;
+ used = ctx->polls_used;
+ for (i = 0; i < used && rc > 0; ) {
+ if (!ctx->pollfds[i].revents) {
+ i++;
+ } else {
+ p = ctx->pollptrs[i];
+ fd = ctx->pollfds[i].fd;
+ revents = ctx->pollfds[i].revents;
- used = ctx->polls_used;
- for (i = 0; i < used && rc > 0; ) {
- if (!ctx->pollfds[i].revents) {
- i++;
+ if (p->cb(p, fd, revents, p->cb_data) < 0) {
+ /* the poll was removed, reload the used counter and start again */
+ used = ctx->polls_used;
+ i=0;
} else {
- ssh_poll_handle p = ctx->pollptrs[i];
- int fd = ctx->pollfds[i].fd;
- int revents = ctx->pollfds[i].revents;
-
- if (p->cb(p, fd, revents, p->cb_data) < 0) {
- /* the poll was removed, reload the used counter and stall the loop */
- used = ctx->polls_used;
- } else {
- ctx->pollfds[i].revents = 0;
- i++;
- }
-
- rc--;
+ ctx->pollfds[i].revents = 0;
+ i++;
}
+
+ rc--;
}
}