aboutsummaryrefslogtreecommitdiff
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:31:35 +0100
commit297e8d9c1bbcbed27f11673aa38a17862ecaeadb (patch)
treed01be2b9367dddd397a303f323532bcdd7570c02
parent531b80a60bcb89c0ea09e85e36e240755407febf (diff)
downloadlibssh-297e8d9c1bbcbed27f11673aa38a17862ecaeadb.tar.gz
libssh-297e8d9c1bbcbed27f11673aa38a17862ecaeadb.tar.xz
libssh-297e8d9c1bbcbed27f11673aa38a17862ecaeadb.zip
poll: Reformat ssh_poll_ctx_dopoll()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-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..6b516930 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;
}
/**