From cfeafe5e77c9dd5587b1ec553eb1065f0bf841fd Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 23 May 2011 00:17:48 -0400 Subject: Use a 64-bit type to hold sockets on win64. On win64, sockets are of type UINT_PTR; on win32 they're u_int; elsewhere they're int. The correct windows way to check a socket for being set is to compare it with INVALID_SOCKET; elsewhere you see if it is negative. On Libevent 2, all callbacks take sockets as evutil_socket_t; we've been passing them int. This patch should fix compilation and correctness when built for 64-bit windows. Fixes bug 3270. --- src/common/compat.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/common/compat.h') diff --git a/src/common/compat.h b/src/common/compat.h index eff51ab30c..8f558e0ce5 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -390,9 +390,18 @@ int tor_fd_seekend(int fd); typedef int socklen_t; #endif -int tor_close_socket(int s); -int tor_open_socket(int domain, int type, int protocol); -int tor_accept_socket(int sockfd, struct sockaddr *addr, socklen_t *len); +#ifdef MS_WINDOWS +#define tor_socket_t intptr_t +#define SOCKET_OK(s) ((s) != INVALID_SOCKET) +#else +#define tor_socket_t int +#define SOCKET_OK(s) ((s) >= 0) +#endif + +int tor_close_socket(tor_socket_t s); +tor_socket_t tor_open_socket(int domain, int type, int protocol); +tor_socket_t tor_accept_socket(int sockfd, struct sockaddr *addr, + socklen_t *len); int get_n_open_sockets(void); #define tor_socket_send(s, buf, len, flags) send(s, buf, len, flags) @@ -464,8 +473,8 @@ int tor_inet_aton(const char *cp, struct in_addr *addr) ATTR_NONNULL((1,2)); const char *tor_inet_ntop(int af, const void *src, char *dst, size_t len); int tor_inet_pton(int af, const char *src, void *dst); int tor_lookup_hostname(const char *name, uint32_t *addr) ATTR_NONNULL((1,2)); -void set_socket_nonblocking(int socket); -int tor_socketpair(int family, int type, int protocol, int fd[2]); +void set_socket_nonblocking(tor_socket_t socket); +int tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2]); int network_init(void); /* For stupid historical reasons, windows sockets have an independent @@ -492,7 +501,7 @@ int network_init(void); ((e) == WSAEMFILE || (e) == WSAENOBUFS) /** Return true if e is EADDRINUSE or the local equivalent. */ #define ERRNO_IS_EADDRINUSE(e) ((e) == WSAEADDRINUSE) -int tor_socket_errno(int sock); +int tor_socket_errno(tor_socket_t sock); const char *tor_socket_strerror(int e); #else #define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN) -- cgit v1.2.3-54-g00ecf