forked from aniani/gmnisrv
Only handle one client per poll iteration
This is a bit of a hack but it avoids some problems with invalid reads when a client gets disconnected
This commit is contained in:
parent
1f229ba123
commit
7fed84898b
12
src/server.c
12
src/server.c
@ -322,8 +322,8 @@ client_writable(struct gmnisrv_server *server, struct gmnisrv_client *client)
|
|||||||
break;
|
break;
|
||||||
case RESPOND_BODY:
|
case RESPOND_BODY:
|
||||||
if (client->bufix >= client->bufln) {
|
if (client->bufix >= client->bufln) {
|
||||||
n = fread(client->buf, 1,
|
n = fread(client->buf, 1, sizeof(client->buf),
|
||||||
sizeof(client->buf), client->body);
|
client->body);
|
||||||
if (n == -1) {
|
if (n == -1) {
|
||||||
client_error(&client->addr,
|
client_error(&client->addr,
|
||||||
"Error reading response body: %s",
|
"Error reading response body: %s",
|
||||||
@ -443,13 +443,9 @@ server_run(struct gmnisrv_server *server)
|
|||||||
for (size_t i = 0; i < server->nclients; ++i) {
|
for (size_t i = 0; i < server->nclients; ++i) {
|
||||||
if ((server->fds[server->nlisten + i].revents & (POLLHUP | POLLERR))) {
|
if ((server->fds[server->nlisten + i].revents & (POLLHUP | POLLERR))) {
|
||||||
disconnect_client(server, &server->clients[i]);
|
disconnect_client(server, &server->clients[i]);
|
||||||
--i;
|
} else if ((server->fds[server->nlisten + i].revents & POLLIN)) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ((server->fds[server->nlisten + i].revents & POLLIN)) {
|
|
||||||
client_readable(server, &server->clients[i]);
|
client_readable(server, &server->clients[i]);
|
||||||
}
|
} else if ((server->fds[server->nlisten + i].revents & POLLOUT)) {
|
||||||
if ((server->fds[server->nlisten + i].revents & POLLOUT)) {
|
|
||||||
client_writable(server, &server->clients[i]);
|
client_writable(server, &server->clients[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user