aboutsummaryrefslogtreecommitdiff
path: root/src/common/compat.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-01-18 15:33:04 -0500
committerNick Mathewson <nickm@torproject.org>2012-01-18 15:33:04 -0500
commitd1b40cf2e7bb55d3c421e6eff476330e08ab4750 (patch)
tree557d4747579301e39f77e4889e84739793690ca3 /src/common/compat.c
parent1772782e425734967981b79be1122017ef606dd0 (diff)
parentdea0720dadea8f3915901833115726f4ba0d48f4 (diff)
downloadtor-d1b40cf2e7bb55d3c421e6eff476330e08ab4750.tar
tor-d1b40cf2e7bb55d3c421e6eff476330e08ab4750.tar.gz
Merge remote-tracking branch 'public/bug4533_part1'
Conflicts: src/common/compat.h
Diffstat (limited to 'src/common/compat.c')
-rw-r--r--src/common/compat.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index 3af43e80c..1f9066d20 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -1053,17 +1053,17 @@ tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2])
r = socketpair(family, type, protocol, fd);
if (r == 0) {
#if !defined(SOCK_CLOEXEC) && defined(FD_CLOEXEC)
- if (fd[0] >= 0)
+ if (SOCKET_OK(fd[0]))
fcntl(fd[0], F_SETFD, FD_CLOEXEC);
- if (fd[1] >= 0)
+ if (SOCKET_OK(fd[1]))
fcntl(fd[1], F_SETFD, FD_CLOEXEC);
#endif
socket_accounting_lock();
- if (fd[0] >= 0) {
+ if (SOCKET_OK(fd[0])) {
++n_sockets_open;
mark_socket_open(fd[0]);
}
- if (fd[1] >= 0) {
+ if (SOCKET_OK(fd[1])) {
++n_sockets_open;
mark_socket_open(fd[1]);
}
@@ -1100,7 +1100,7 @@ tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2])
}
listener = tor_open_socket(AF_INET, type, 0);
- if (listener < 0)
+ if (!SOCKET_OK(listener))
return -tor_socket_errno(-1);
memset(&listen_addr, 0, sizeof(listen_addr));
listen_addr.sin_family = AF_INET;
@@ -1113,7 +1113,7 @@ tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2])
goto tidy_up_and_fail;
connector = tor_open_socket(AF_INET, type, 0);
- if (connector < 0)
+ if (!SOCKET_OK(connector))
goto tidy_up_and_fail;
/* We want to find out the port number to connect to. */
size = sizeof(connect_addr);
@@ -1128,7 +1128,7 @@ tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2])
size = sizeof(listen_addr);
acceptor = tor_accept_socket(listener,
(struct sockaddr *) &listen_addr, &size);
- if (acceptor < 0)
+ if (!SOCKET_OK(acceptor))
goto tidy_up_and_fail;
if (size != sizeof(listen_addr))
goto abort_tidy_up_and_fail;
@@ -2889,6 +2889,11 @@ network_init(void)
log_warn(LD_NET,"Error initializing windows network layer: code was %d",r);
return -1;
}
+ if (sizeof(SOCKET) != sizeof(tor_socket_t)) {
+ log_warn(LD_BUG,"The tor_socket_t type does not match SOCKET in size; Tor "
+ "might not work. (Sizes are %d and %d respectively.)",
+ (int)sizeof(tor_socket_t), (int)sizeof(SOCKET));
+ }
/* WSAData.iMaxSockets might show the max sockets we're allowed to use.
* We might use it to complain if we're trying to be a server but have
* too few sockets available. */