Skip to content
Permalink
Browse files

allow to modify socket backlog length and change unix backlog default…

… to 128 as in linux kernel defaults
  • Loading branch information...
pavel.mash
pavel.mash committed Oct 7, 2019
1 parent 7249138 commit d94c4454c9957819e29ffbf8ad362451acb72bee
Showing with 12 additions and 2 deletions.
  1. +10 −1 SynCrtSock.pas
  2. +2 −1 SynFPCSock.pas
@@ -3227,6 +3227,15 @@ TPollAsynchSockets = class
function WinHTTP_WebSocketEnabled: boolean;
{$endif}

var
/// Queue length for completely established sockets waiting to be accepted,
// a backlog parameter for listen() function. If queue overflows client
// got ECONNREFUSED error for connect() call
// - for windows default is taken from SynWinSock ($7fffffff) and should
// not be modified. Actual limit is 200;
// - for Unix default is taken from SynFPCSock (128 as in linux cernel >2.2),
// but actual value is min(DefaultListenBacklog, /proc/sys/net/core/somaxconn)
DefaultListenBacklog: integer = SOMAXCONN;

implementation

@@ -4596,7 +4605,7 @@ function CallServer(const Server, Port: SockString; doBind: boolean;
SetInt32Option(result,SO_LINGER,5);
// bind and listen to this port
if (Bind(result,sin)<>0) or
((aLayer<>cslUDP) and (Listen(result,SOMAXCONN)<>0)) then begin
((aLayer<>cslUDP) and (Listen(result,DefaultListenBacklog)<>0)) then begin
CloseSocket(result);
result := -1;
end;
@@ -194,7 +194,8 @@ procedure DestroySocketInterface;
{$IFDEF BSD}
SO_NOSIGPIPE = $1022;
{$ENDIF}
SOMAXCONN = 1024;
// we use Linux default here
SOMAXCONN = 128;

IPV6_UNICAST_HOPS = sockets.IPV6_UNICAST_HOPS;
IPV6_MULTICAST_IF = sockets.IPV6_MULTICAST_IF;

0 comments on commit d94c445

Please sign in to comment.
You can’t perform that action at this time.