If listen() is called with a backlog argument value that is less than 0, the function behaves as if it had been called with a backlog argument value of 0.
A backlog argument of 0 may allow the socket to accept connections, in which case the length of the listen queue may be set to an implementation-defined minimum value.
I wonder whether Linux chooses an "implementation-defined minimum value" or behaves differently here. An alternative seems to be to simply always set this to 4096 (or some larger value) and let it be limited to the OS limit, regardless of the platform.
(Windows also has SOMAXCONN_HINT(n) => -n, which can be used to ignore the SOMAXCONN limit)
I found this in the OpenGroup documentation:
I wonder whether Linux chooses an "implementation-defined minimum value" or behaves differently here. An alternative seems to be to simply always set this to 4096 (or some larger value) and let it be limited to the OS limit, regardless of the platform.
(Windows also has
SOMAXCONN_HINT(n) => -n
, which can be used to ignore theSOMAXCONN
limit)