diff --git a/source/eventcore/drivers/posix/sockets.d b/source/eventcore/drivers/posix/sockets.d index 1dc381f..12247a4 100644 --- a/source/eventcore/drivers/posix/sockets.d +++ b/source/eventcore/drivers/posix/sockets.d @@ -217,7 +217,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets invalidateSocket(); return; } - if (listen(sockfd, 128) != 0) { + if (listen(sockfd, getBacklogSize()) != 0) { invalidateSocket(); return; } @@ -955,3 +955,21 @@ private int getSocketError() version (Windows) return WSAGetLastError(); 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; +}