aboutsummaryrefslogtreecommitdiff
path: root/src/poll.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-11-21 09:45:41 +0100
committerAndreas Schneider <asn@cryptomilk.org>2019-01-09 15:42:33 +0100
commit0e7a962417cb7fe944a6b1d96107e97c323bfff4 (patch)
treee8825c048f824158e26c43b7b823e740c29a9d74 /src/poll.c
parent531b80a60bcb89c0ea09e85e36e240755407febf (diff)
downloadlibssh-0e7a962417cb7fe944a6b1d96107e97c323bfff4.tar.gz
libssh-0e7a962417cb7fe944a6b1d96107e97c323bfff4.tar.xz
libssh-0e7a962417cb7fe944a6b1d96107e97c323bfff4.zip
poll: Reformat ssh_poll_ctx_dopoll()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/poll.c')
-rw-r--r--src/poll.c105
1 files changed, 55 insertions, 50 deletions
diff --git a/src/poll.c b/src/poll.c
index 0ee8db20..8c4446d0 100644
--- a/src/poll.c
+++ b/src/poll.c
@@ -591,59 +591,64 @@ void ssh_poll_ctx_remove(ssh_poll_ctx ctx, ssh_poll_handle p) {
* SSH_AGAIN Timeout occured
*/
-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;
- struct ssh_timestamp ts;
-
- if (!ctx->polls_used)
- return SSH_ERROR;
-
- ssh_timestamp_init(&ts);
- do {
- int tm = ssh_timeout_update(&ts, timeout);
- rc = ssh_poll(ctx->pollfds, ctx->polls_used, tm);
- } while (rc == -1 && errno == EINTR);
-
- if(rc < 0)
- return SSH_ERROR;
- if (rc == 0)
- return SSH_AGAIN;
- used = ctx->polls_used;
- for (i = 0; i < used && rc > 0; ) {
- if (!ctx->pollfds[i].revents || ctx->pollptrs[i]->lock) {
- i++;
- } else {
- int ret;
-
- 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;
- }
- /* the poll was removed, reload the used counter and start again */
- used = ctx->polls_used;
- i=0;
- } else {
- ctx->pollfds[i].revents = 0;
- ctx->pollfds[i].events = p->events;
- p->lock = 0;
- i++;
- }
+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;
+ struct ssh_timestamp ts;
- rc--;
+ if (ctx->polls_used == 0) {
+ return SSH_ERROR;
}
- }
- return rc;
+ ssh_timestamp_init(&ts);
+ do {
+ int tm = ssh_timeout_update(&ts, timeout);
+ rc = ssh_poll(ctx->pollfds, ctx->polls_used, tm);
+ } while (rc == -1 && errno == EINTR);
+
+ if (rc < 0) {
+ return SSH_ERROR;
+ }
+ if (rc == 0) {
+ return SSH_AGAIN;
+ }
+
+ used = ctx->polls_used;
+ for (i = 0; i < used && rc > 0; ) {
+ if (!ctx->pollfds[i].revents || ctx->pollptrs[i]->lock) {
+ i++;
+ } else {
+ int ret;
+
+ 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;
+ }
+ /* the poll was removed, reload the used counter and start again */
+ used = ctx->polls_used;
+ i = 0;
+ } else {
+ ctx->pollfds[i].revents = 0;
+ ctx->pollfds[i].events = p->events;
+ p->lock = 0;
+ i++;
+ }
+
+ rc--;
+ }
+ }
+
+ return rc;
}
/**