commit ffe03048da71bdfd2d1d83182b65bbed8295809d
parent 66babbe78ca2d9c28cf6b94a23c7f05628d31d10
Author: Jacob R. Edwards <n/a>
Date: Sat, 21 May 2022 19:55:37 -0500
Fix polling bug
Both read and write ability was polled when only one or the other
should have been. This caused poll to return without delay, then
get called again and again when a client was idle.
Diffstat:
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/aps/aps.c b/aps/aps.c
@@ -46,10 +46,8 @@ aps_open(char *path, char **player)
if (aps == NULL)
return NULL;
- for (i = 0; i < LEN(aps->pfds); ++i) {
+ for (i = 0; i < LEN(aps->pfds); ++i)
aps->pfds[i].fd = -1;
- aps->pfds[i].events = POLLIN | POLLOUT;
- }
aps->player = pnew(player);
if (aps->player == NULL) {
@@ -149,7 +147,7 @@ aps_handle(struct aps *aps, int fd)
if (aps_command(aps, fd))
return 1;
} else if (aps->pfds[fd].revents & POLLOUT) {
- if (aps->clients[fd].resp->lock && respond(aps, fd))
+ if (respond(aps, fd))
return 1;
} else {
bug("impossible poll event");
diff --git a/aps/response.c b/aps/response.c
@@ -93,6 +93,7 @@ respfinish(struct aps *aps, int fd, char *error)
}
aps->clients[fd].resp->lock = 1;
+ aps->pfds[fd].events = POLLOUT;
return 0;
}
@@ -118,6 +119,7 @@ respond(struct aps *aps, int fd)
resp->buf->len = 0;
resp->sent = 0;
resp->lock = 0;
+ aps->pfds[fd].events = POLLIN;
}
return 0;
}