diff options
author | June McEnroe <june@causal.agency> | 2019-10-25 02:27:05 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-10-25 02:27:05 -0400 |
commit | 3f243081d85ca02188ccdd61ae3476ed9df933e1 (patch) | |
tree | e3adbde6da2c302255ee31d9db1f4fbe5ae45a37 /bounce.c | |
parent | Implement ringDiff and ringRead (diff) | |
download | pounce-3f243081d85ca02188ccdd61ae3476ed9df933e1.tar.gz pounce-3f243081d85ca02188ccdd61ae3476ed9df933e1.zip |
Implement client reading from ring buffer
It's still messy but it works!!
Diffstat (limited to '')
-rw-r--r-- | bounce.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/bounce.c b/bounce.c index 6de5e5d..c771bbe 100644 --- a/bounce.c +++ b/bounce.c @@ -140,17 +140,30 @@ int main(int argc, char *argv[]) { struct tls *tls; int fd = listenAccept(&tls, event.fds[i].fd); eventAdd(fd, clientAlloc(tls)); - } else if (!event.clients[i]) { + continue; + } + if (!event.clients[i]) { serverRecv(); + continue; + } + short revents = event.fds[i].revents; + struct Client *client = event.clients[i]; + if (revents & POLLIN) clientRecv(client); + if (revents & POLLOUT) clientRead(client); + if (clientError(client) || revents & (POLLHUP | POLLERR)) { + clientFree(client); + close(event.fds[i].fd); + eventRemove(i); + break; + } + } + + for (size_t i = 0; i < event.len; ++i) { + if (!event.clients[i]) continue; + if (clientDiff(event.clients[i])) { + event.fds[i].events |= POLLOUT; } else { - struct Client *client = event.clients[i]; - if (event.fds[i].revents & POLLIN) clientRecv(client); - if (event.fds[i].revents & ~POLLIN || clientError(client)) { - clientFree(client); - close(event.fds[i].fd); - eventRemove(i); - break; - } + event.fds[i].events &= ~POLLOUT; } } } |