Merge pull request #71 from kubo39/somaxconn

Get the listen backlog size from net.core.somaxconn on Linux
merged-on-behalf-of: Sönke Ludwig <s-ludwig@users.noreply.github.com>
This commit is contained in:
The Dlang Bot 2018-05-13 09:44:42 +02:00 committed by GitHub
commit ca56b31566
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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,21 @@ 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 : fclose, fopen, fscanf;
auto somaxconn = fopen("/proc/sys/net/core/somaxconn", "re");
if (somaxconn)
{
int tmp;
if (fscanf(somaxconn, "%d", &tmp) == 1)
backlog = tmp;
fclose(somaxconn);
}
}
return backlog;
}