diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-09-19 10:50:34 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-09-19 10:50:34 -0400 |
commit | 67bb1a44bd2af54d2475404b187c5475db7ea76d (patch) | |
tree | 046a447ed946c452a24bcf5989681bf766f6d9c6 | |
parent | 2f2fa7683d768ce165e9fc5b6f22d2fdcd79d9ca (diff) | |
parent | a2754d418dffb6188717d5e84d9bea59a2c9853b (diff) | |
download | tor-67bb1a44bd2af54d2475404b187c5475db7ea76d.tar tor-67bb1a44bd2af54d2475404b187c5475db7ea76d.tar.gz |
Merge remote-tracking branch 'public/bug9716_024'
-rw-r--r-- | changes/bug9716 | 4 | ||||
-rw-r--r-- | src/or/connection.c | 23 |
2 files changed, 26 insertions, 1 deletions
diff --git a/changes/bug9716 b/changes/bug9716 new file mode 100644 index 000000000..5e3907717 --- /dev/null +++ b/changes/bug9716 @@ -0,0 +1,4 @@ + o Bugfixes (performance): + - Set the listen() backlog limit to the largest actually supported + on the system, not to the value in a header file. Fixes bug 9716; + bugfix on every released Tor. diff --git a/src/or/connection.c b/src/or/connection.c index 8c66a170e..8cf23ab0e 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -963,6 +963,27 @@ make_socket_reuseable(tor_socket_t sock) #endif } +/** Max backlog to pass to listen. We start at */ +static int listen_limit = INT_MAX; + +/* Listen on <b>fd</b> with appropriate backlog. Return as for listen. */ +static int +tor_listen(tor_socket_t fd) +{ + int r; + + if ((r = listen(fd, listen_limit)) < 0) { + if (listen_limit == SOMAXCONN) + return r; + if ((r = listen(fd, SOMAXCONN)) == 0) { + listen_limit = SOMAXCONN; + log_warn(LD_NET, "Setting listen backlog to INT_MAX connections " + "didn't work, but SOMAXCONN did. Lowering backlog limit."); + } + } + return r; +} + /** Bind a new non-blocking socket listening to the socket described * by <b>listensockaddr</b>. * @@ -1045,7 +1066,7 @@ connection_listener_new(const struct sockaddr *listensockaddr, } if (is_tcp) { - if (listen(s,SOMAXCONN) < 0) { + if (tor_listen(s) < 0) { log_warn(LD_NET, "Could not listen on %s:%u: %s", address, usePort, tor_socket_strerror(tor_socket_errno(s))); goto err; |