mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-06 13:37:34 +08:00
Fix socket leak when there are too many open fds
CL: Mongoose Web Server: Fix socket leak when there are too many open file descriptors Fixes https://github.com/cesanta/mongoose/issues/870 PUBLISHED_FROM=c802b6834a54eca37821d46efde192c527e0a6b7
This commit is contained in:
parent
5d5badfcee
commit
255da78bed
14
mongoose.c
14
mongoose.c
@ -3914,10 +3914,16 @@ time_t mg_socket_if_poll(struct mg_iface *iface, int timeout_ms) {
|
|||||||
/* A hack to make sure all our file descriptos fit into FD_SETSIZE. */
|
/* A hack to make sure all our file descriptos fit into FD_SETSIZE. */
|
||||||
if (nc->sock >= (sock_t) FD_SETSIZE && try_dup) {
|
if (nc->sock >= (sock_t) FD_SETSIZE && try_dup) {
|
||||||
int new_sock = dup(nc->sock);
|
int new_sock = dup(nc->sock);
|
||||||
if (new_sock >= 0 && new_sock < (sock_t) FD_SETSIZE) {
|
if (new_sock >= 0) {
|
||||||
closesocket(nc->sock);
|
if (new_sock < (sock_t) FD_SETSIZE) {
|
||||||
DBG(("new sock %d -> %d", nc->sock, new_sock));
|
closesocket(nc->sock);
|
||||||
nc->sock = new_sock;
|
DBG(("new sock %d -> %d", nc->sock, new_sock));
|
||||||
|
nc->sock = new_sock;
|
||||||
|
} else {
|
||||||
|
closesocket(new_sock);
|
||||||
|
DBG(("new sock is still larger than FD_SETSIZE, disregard"));
|
||||||
|
try_dup = 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try_dup = 0;
|
try_dup = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user