diff options
author | Linus Nordberg <linus@nordberg.se> | 2019-04-24 16:11:39 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2019-04-24 16:11:39 +0200 |
commit | ae16838248abb5406a8f48207082bc249e85ac37 (patch) | |
tree | 4c2ff4f8e3b64970b0d358c26ccf1d849d5c794f | |
parent | Do advance buffer after (second) short write (diff) | |
download | wg-dynamic-ae16838248abb5406a8f48207082bc249e85ac37.tar.xz wg-dynamic-ae16838248abb5406a8f48207082bc249e85ac37.zip |
Don't declare variables mid block
Also, do name variables slightly better.
-rw-r--r-- | wg-dynamic-client.c | 6 | ||||
-rw-r--r-- | wg-dynamic-server.c | 8 |
2 files changed, 8 insertions, 6 deletions
diff --git a/wg-dynamic-client.c b/wg-dynamic-client.c index 8a1fecb..5bcd3b4 100644 --- a/wg-dynamic-client.c +++ b/wg-dynamic-client.c @@ -490,6 +490,7 @@ int main(int argc __attribute__((unused)), char *argv[] __attribute__((unused))) pollfds[0] = (struct pollfd){.fd = -1, .events = POLLIN }; while (1) { + size_t off; int nevents = poll(pollfds, 1, LEASE_CHECK_INTERVAL); if (nevents == -1) @@ -507,10 +508,9 @@ int main(int argc __attribute__((unused)), char *argv[] __attribute__((unused))) pollfds[0].revents &= ~POLLOUT; debug("sending, trying again with %lu bytes\n", req.buflen); - size_t w = send_message(pollfds[0].fd, req.buf, - &req.buflen); + off = send_message(pollfds[0].fd, req.buf, &req.buflen); if (req.buflen) - memmove(req.buf, req.buf + w, req.buflen); + memmove(req.buf, req.buf + off, req.buflen); else close_connection(&pollfds[0].fd, &req); } diff --git a/wg-dynamic-server.c b/wg-dynamic-server.c index 295a127..19b8b83 100644 --- a/wg-dynamic-server.c +++ b/wg-dynamic-server.c @@ -555,15 +555,17 @@ int main(int argc, char *argv[]) } for (int i = 1; i < MAX_CONNECTIONS + 1; ++i) { + size_t off; + if (!(pollfds[i].revents & POLLOUT)) continue; pollfds[i].revents &= ~POLLOUT; - size_t w = send_message(pollfds[i].fd, reqs[i - 1].buf, - &reqs[i - 1].buflen); + off = send_message(pollfds[i].fd, reqs[i - 1].buf, + &reqs[i - 1].buflen); if (reqs[i - 1].buflen) - memmove(reqs[i - 1].buf, reqs[i - 1].buf + w, + memmove(reqs[i - 1].buf, reqs[i - 1].buf + off, reqs[i - 1].buflen); else close_connection(&pollfds[i].fd, &reqs[i - 1]); |