Get the listen backlog size from net.core.somaxconn on linux

This commit is contained in:
Hiroki Noda 2018-03-22 05:12:37 +09:00
parent 51527e77f8
commit 041d55e584

View file

@ -217,7 +217,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
invalidateSocket(); invalidateSocket();
return; return;
} }
if (listen(sockfd, 128) != 0) { if (listen(sockfd, getBacklogSize()) != 0) {
invalidateSocket(); invalidateSocket();
return; return;
} }
@ -955,3 +955,19 @@ private int getSocketError()
version (Windows) return WSAGetLastError(); version (Windows) return WSAGetLastError();
else return errno; else return errno;
} }
private int getBacklogSize()
@trusted @nogc nothrow {
int backlog = 128;
version(linux)
{
import core.stdc.stdio : fopen, fscanf;
auto somaxconn = fopen("/proc/sys/net/core/somaxconn", "re");
if(somaxconn)
{
int tmp;
if (fscanf(somaxconn, "%d", &tmp) == 1)
backlog = tmp;
}
}
return backlog;
}