diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-08-02 10:36:01 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-08-02 10:36:01 -0400 |
commit | d6adf055828283dda2ca9c0c77a80348778c45df (patch) | |
tree | d7e2e4e4459138b9ac61a645fe4462c105a06c6f /src/common/compat.c | |
parent | b8d9c8403718b2dca577947d2f5d9248ab87961e (diff) | |
download | tor-d6adf055828283dda2ca9c0c77a80348778c45df.tar.gz tor-d6adf055828283dda2ca9c0c77a80348778c45df.zip |
Split the socketpair replacement code into its own function for testing
Diffstat (limited to 'src/common/compat.c')
-rw-r--r-- | src/common/compat.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index 8aab12a30e..d69e3b0931 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -23,6 +23,7 @@ * we can also take out the configure check. */ #define _GNU_SOURCE +#define COMPAT_PRIVATE #include "compat.h" #ifdef _WIN32 @@ -1291,6 +1292,18 @@ tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2]) return 0; #else + return tor_ersatz_socketpair(family, type, protocol, fd); +#endif +} + +#ifdef NEED_ERSATZ_SOCKETPAIR +/** + * Helper used to implement socketpair on systems that lack it, by + * making a direct connection to localhost. + */ +STATIC int +tor_ersatz_socketpair(int family, int type, int protocol, tor_socket_t fd[2]) +{ /* This socketpair does not work when localhost is down. So * it's really not the same thing at all. But it's close enough * for now, and really, when localhost is down sometimes, we @@ -1301,7 +1314,7 @@ tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2]) tor_socket_t acceptor = -1; struct sockaddr_in listen_addr; struct sockaddr_in connect_addr; - int size; + socklen_t size; int saved_errno = -1; if (protocol @@ -1384,8 +1397,8 @@ tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2]) if (acceptor != -1) tor_close_socket(acceptor); return -saved_errno; -#endif } +#endif /** Number of extra file descriptors to keep in reserve beyond those that we * tell Tor it's allowed to use. */ |