aboutsummaryrefslogtreecommitdiff
path: root/src/or/connection.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-12-01 03:15:59 +0000
committerNick Mathewson <nickm@torproject.org>2004-12-01 03:15:59 +0000
commit6e88abf418684ccaf4a1d7146b0129857a3864fe (patch)
tree40fe96c95f262f00fdf714759553f42eb45429eb /src/or/connection.c
parentbde1d5bfb2a6c1c39d51ff807e2d13ce6e8a30ce (diff)
downloadtor-6e88abf418684ccaf4a1d7146b0129857a3864fe.tar
tor-6e88abf418684ccaf4a1d7146b0129857a3864fe.tar.gz
If we are using select, make sure we stay within FD_SETSIZE.
svn:r3051
Diffstat (limited to 'src/or/connection.c')
-rw-r--r--src/or/connection.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index ab5197cf2..fb7efdc24 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -363,6 +363,10 @@ static int connection_create_listener(const char *bindaddress, uint16_t bindport
if (s < 0) {
log_fn(LOG_WARN,"Socket creation failed.");
return -1;
+ } else if (!SOCKET_IS_POLLABLE(s)) {
+ log_fn(LOG_WARN,"Too many connections; can't create pollable listener.");
+ tor_close_socket(s);
+ return -1;
}
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*) &one, sizeof(one));
@@ -410,8 +414,16 @@ static int connection_handle_listener_read(connection_t *conn, int new_type) {
int remotelen = sizeof(struct sockaddr_in);
news = accept(conn->s,(struct sockaddr *)&remote,&remotelen);
- if (news == -1) { /* accept() error */
- int e = tor_socket_errno(conn->s);
+ if (!SOCKET_IS_POLLABLE(news)) {
+ /* accept() error, or two many conns to poll */
+ int e;
+ if (news>=0) {
+ /* Too many conns to poll. */
+ log_fn(LOG_WARN,"Too many connections; couldn't accept connection.");
+ tor_close_socket(news);
+ return 0;
+ }
+ e = tor_socket_errno(conn->s);
if (ERRNO_IS_ACCEPT_EAGAIN(e)) {
return 0; /* he hung up before we could accept(). that's fine. */
} else if (ERRNO_IS_ACCEPT_RESOURCE_LIMIT(e)) {
@@ -505,11 +517,16 @@ int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_
struct sockaddr_in dest_addr;
or_options_t *options = get_options();
- s=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
+ s = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
if (s < 0) {
log_fn(LOG_WARN,"Error creating network socket: %s",
tor_socket_strerror(tor_socket_errno(-1)));
return -1;
+ } else if (!SOCKET_IS_POLLABLE(s)) {
+ log_fn(LOG_WARN,
+ "Too many connections; can't create pollable connection to %s", address);
+ tor_close_socket(s);
+ return -1;
}
if (options->OutboundBindAddress) {