mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +01:00
simplify code now that libevent considers all sockets pollable.
what we really mean now is ">= 0", which is clearer to test for. svn:r6543
This commit is contained in:
parent
4e773352c2
commit
45065f1466
@ -415,17 +415,8 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
|
||||
}
|
||||
|
||||
listener = socket(AF_INET, type, 0);
|
||||
if (listener == -1)
|
||||
if (listener < 0)
|
||||
return -tor_socket_errno(-1);
|
||||
if (!SOCKET_IS_POLLABLE(listener)) {
|
||||
log_warn(LD_NET, "Too many connections; can't open socketpair");
|
||||
tor_close_socket(listener);
|
||||
#ifdef MS_WINDOWS
|
||||
return -ENFILE;
|
||||
#else
|
||||
return -ENCONN;
|
||||
#endif
|
||||
}
|
||||
memset(&listen_addr, 0, sizeof(listen_addr));
|
||||
listen_addr.sin_family = AF_INET;
|
||||
listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
@ -437,12 +428,8 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
|
||||
goto tidy_up_and_fail;
|
||||
|
||||
connector = socket(AF_INET, type, 0);
|
||||
if (connector == -1)
|
||||
if (connector < 0)
|
||||
goto tidy_up_and_fail;
|
||||
if (!SOCKET_IS_POLLABLE(connector)) {
|
||||
log_warn(LD_NET, "Too many connections; can't open socketpair");
|
||||
goto tidy_up_and_fail;
|
||||
}
|
||||
/* We want to find out the port number to connect to. */
|
||||
size = sizeof(connect_addr);
|
||||
if (getsockname(listener, (struct sockaddr *) &connect_addr, &size) == -1)
|
||||
@ -455,12 +442,8 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
|
||||
|
||||
size = sizeof(listen_addr);
|
||||
acceptor = accept(listener, (struct sockaddr *) &listen_addr, &size);
|
||||
if (acceptor == -1)
|
||||
if (acceptor < 0)
|
||||
goto tidy_up_and_fail;
|
||||
if (!SOCKET_IS_POLLABLE(acceptor)) {
|
||||
log_warn(LD_NET, "Too many connections; can't open socketpair");
|
||||
goto tidy_up_and_fail;
|
||||
}
|
||||
if (size != sizeof(listen_addr))
|
||||
goto abort_tidy_up_and_fail;
|
||||
tor_close_socket(listener);
|
||||
|
@ -175,10 +175,6 @@ int touch_file(const char *fname);
|
||||
typedef int socklen_t;
|
||||
#endif
|
||||
|
||||
/* Now that we use libevent, all real sockets are safe for polling ... or
|
||||
* if they aren't, libevent will help us. */
|
||||
#define SOCKET_IS_POLLABLE(fd) ((fd)>=0)
|
||||
|
||||
struct in_addr;
|
||||
int tor_inet_aton(const char *cp, struct in_addr *addr);
|
||||
int tor_lookup_hostname(const char *name, uint32_t *addr);
|
||||
|
@ -532,10 +532,6 @@ connection_create_listener(const char *listenaddress, uint16_t listenport,
|
||||
if (s < 0) {
|
||||
log_warn(LD_NET,"Socket creation failed.");
|
||||
goto err;
|
||||
} else if (!SOCKET_IS_POLLABLE(s)) {
|
||||
log_warn(LD_NET,"Too many connections; can't create pollable listener.");
|
||||
tor_close_socket(s);
|
||||
goto err;
|
||||
}
|
||||
|
||||
#ifndef MS_WINDOWS
|
||||
@ -635,16 +631,9 @@ connection_handle_listener_read(connection_t *conn, int new_type)
|
||||
memset(addrbuf, 0, sizeof(addrbuf));
|
||||
|
||||
news = accept(conn->s,(struct sockaddr *)&addrbuf,&remotelen);
|
||||
if (!SOCKET_IS_POLLABLE(news)) {
|
||||
/* accept() error, or too many conns to poll */
|
||||
int e;
|
||||
if (news>=0) {
|
||||
/* Too many conns to poll. */
|
||||
log_warn(LD_NET,"Too many connections; couldn't accept connection.");
|
||||
tor_close_socket(news);
|
||||
return 0;
|
||||
}
|
||||
e = tor_socket_errno(conn->s);
|
||||
if (news < 0) {
|
||||
/* accept() error */
|
||||
int 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)) {
|
||||
@ -771,12 +760,6 @@ connection_connect(connection_t *conn, char *address,
|
||||
log_warn(LD_NET,"Error creating network socket: %s",
|
||||
tor_socket_strerror(tor_socket_errno(-1)));
|
||||
return -1;
|
||||
} else if (!SOCKET_IS_POLLABLE(s)) {
|
||||
log_warn(LD_NET,
|
||||
"Too many connections; can't create pollable connection to %s",
|
||||
escaped_safe_str(address));
|
||||
tor_close_socket(s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (options->OutboundBindAddress) {
|
||||
|
Loading…
Reference in New Issue
Block a user