1
1

Fix style in ssh_poll_ctx_dopoll

Also do a rescan of polled events when a poll object has been deleted.
Этот коммит содержится в:
Aris Adamantiadis 2010-05-10 23:19:39 +02:00
родитель 5713481838
Коммит 26d04ff037

Просмотреть файл

@ -516,37 +516,44 @@ void ssh_poll_ctx_remove(ssh_poll_ctx ctx, ssh_poll_handle p) {
* block, in milliseconds. Specifying a negative value * block, in milliseconds. Specifying a negative value
* means an infinite timeout. This parameter is passed to * means an infinite timeout. This parameter is passed to
* the poll() function. * 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 ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout) {
int rc; int rc;
int i, used;
ssh_poll_handle p;
socket_t fd;
int revents;
if (!ctx->polls_used) if (!ctx->polls_used)
return 0; return 0;
rc = ssh_poll(ctx->pollfds, ctx->polls_used, timeout); rc = ssh_poll(ctx->pollfds, ctx->polls_used, timeout);
if (rc > 0) { if(rc < 0)
register size_t i, used; 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; if (p->cb(p, fd, revents, p->cb_data) < 0) {
for (i = 0; i < used && rc > 0; ) { /* the poll was removed, reload the used counter and start again */
if (!ctx->pollfds[i].revents) { used = ctx->polls_used;
i++; i=0;
} else { } else {
ssh_poll_handle p = ctx->pollptrs[i]; ctx->pollfds[i].revents = 0;
int fd = ctx->pollfds[i].fd; i++;
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--;
} }
rc--;
} }
} }