diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-04-21 17:24:18 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-04-21 17:24:18 +0000 |
commit | 227b2e0226445d0c4f39572f51f55451f9fa90f3 (patch) | |
tree | 2c1fb15b829e3fc1e21ec29c1c5e9f28c7d02dbc /src/or | |
parent | 671b990f5168771051b251162698354ebbf39a6c (diff) | |
download | tor-227b2e0226445d0c4f39572f51f55451f9fa90f3.tar.gz tor-227b2e0226445d0c4f39572f51f55451f9fa90f3.zip |
r12759@Kushana: nickm | 2007-04-20 08:47:20 -0400
Track the number of connection_t separately from the number of open sockets. It is already possible to have connections that do not count: resolving conns, for one. Once we move from socketpairs to linked conns, and once we do dns proxying, there will be lots of such connections.
svn:r9994
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/connection.c | 22 | ||||
-rw-r--r-- | src/or/main.c | 12 |
2 files changed, 25 insertions, 9 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index 2163c82349..165d1290bf 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -613,7 +613,16 @@ connection_create_listener(const char *listenaddress, uint16_t listenport, log_notice(LD_NET, "Opening %s on %s:%d", conn_type_to_string(type), address, usePort); - s = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); + if (get_n_open_sockets() >= get_options()->_ConnLimit-1) { + int n_conns = get_n_open_sockets(); + log_warn(LD_NET,"Failing because we have %d connections already. Please " + "raise your ulimit -n.", n_conns); + control_event_general_status(LOG_WARN, "TOO_MANY_CONNECTIONS CURRENT=%d", + n_conns); + return NULL; + } + + s = tor_open_socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); if (s < 0) { log_warn(LD_NET,"Socket creation failed."); goto err; @@ -853,7 +862,16 @@ connection_connect(connection_t *conn, const char *address, struct sockaddr_in dest_addr; or_options_t *options = get_options(); - s = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); + if (get_n_open_sockets() >= get_options()->_ConnLimit-1) { + int n_conns = get_n_open_sockets(); + log_warn(LD_NET,"Failing because we have %d connections already. Please " + "raise your ulimit -n.", n_conns); + control_event_general_status(LOG_WARN, "TOO_MANY_CONNECTIONS CURRENT=%d", + n_conns); + return -1; + } + + s = tor_open_socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); if (s < 0) { log_warn(LD_NET,"Error creating network socket: %s", tor_socket_strerror(tor_socket_errno(-1))); diff --git a/src/or/main.c b/src/or/main.c index 1249bafc74..f15b18243b 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -68,6 +68,7 @@ static time_t time_of_last_signewnym = 0; static int signewnym_is_pending = 0; /** Array of all open connections. The first n_conns elements are valid. */ +/*XXXX020 Should we just use a smartlist here? */ static connection_t *connection_array[MAXCONNECTIONS+1] = { NULL }; /** List of connections that have been marked for close and need to be freed @@ -156,15 +157,12 @@ connection_add(connection_t *conn) tor_assert(conn); tor_assert(conn->s >= 0); - if (n_conns >= get_options()->_ConnLimit-1) { - log_warn(LD_NET,"Failing because we have %d connections already. Please " - "raise your ulimit -n.", n_conns); - control_event_general_status(LOG_WARN, "TOO_MANY_CONNECTIONS CURRENT=%d", - n_conns); + tor_assert(conn->conn_array_index == -1); /* can only connection_add once */ + if (n_conns == MAXCONNECTIONS) { + log_warn(LD_BUG, "Unable to add a connection; MAXCONNECTIONS is set too " + "low. This is a bug; tell the developers."); return -1; } - - tor_assert(conn->conn_array_index == -1); /* can only connection_add once */ conn->conn_array_index = n_conns; connection_array[n_conns] = conn; |