mirror of
https://git.sr.ht/~sircmpwn/gmnisrv
synced 2025-01-03 14:57:39 -05:00
Close some files when too many are open
This commit is contained in:
parent
132f2ececc
commit
95138564ac
11
src/server.c
11
src/server.c
@ -115,8 +115,19 @@ accept_client(struct gmnisrv_server *server, int fd)
|
||||
int sockfd = accept(fd, &addr, &addrlen);
|
||||
if (sockfd == -1) {
|
||||
server_error("accept error: %s", strerror(errno));
|
||||
if (errno == EMFILE) {
|
||||
for (int i = 1; i < 4; i++) {
|
||||
struct gmnisrv_client *client = &server->clients[server->nclients-i];
|
||||
disconnect_client(server, client);
|
||||
}
|
||||
sockfd = accept(fd, &addr, &addrlen);
|
||||
if (sockfd != -1) {
|
||||
goto accepted;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
accepted:;
|
||||
|
||||
int flags = fcntl(fd, F_GETFL);
|
||||
int r = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||
|
Loading…
Reference in New Issue
Block a user