Allow the operating system to set the size of the listen queue connection backlog. (#922)

* Allow the operating system to determine the size of the listen queue connection backlog.

* On Windows, set the listen queue backlog to SOMAXCONN, as advised in https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-listen.
This commit is contained in:
RobCrowston 2020-07-29 04:14:07 +01:00 committed by GitHub
parent 2da97b25fa
commit 6fee8724ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -21,6 +21,7 @@
*****************************************************************************/
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <sys/types.h>
@ -476,7 +477,12 @@ static tr_socket_t tr_netBindTCPImpl(tr_address const* addr, tr_port port, bool
#endif
if (listen(fd, 128) == -1)
#ifdef _WIN32
if (listen(fd, SOMAXCONN) == -1)
#else /* _WIN32 */
/* Listen queue backlog will be capped to the operating system's limit. */
if (listen(fd, INT_MAX) == -1)
#endif /* _WIN32 */
{
*errOut = sockerrno;
tr_netCloseSocket(fd);