aboutsummaryrefslogtreecommitdiff
path: root/src/lib/net/socket.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-08-01 09:40:02 -0400
committerNick Mathewson <nickm@torproject.org>2018-08-01 11:01:52 -0400
commitfc0dc5aa9ef526a8ed776fe4896fe4007173c638 (patch)
treebdc21beb7071ec3370700744ef3a16e823ba065c /src/lib/net/socket.c
parent9b24609af003cb79091e628c179cf617ff41aae7 (diff)
downloadtor-fc0dc5aa9ef526a8ed776fe4896fe4007173c638.tar.gz
tor-fc0dc5aa9ef526a8ed776fe4896fe4007173c638.zip
Refactor tor_ersatz_socketpair() not to need socket.
This change also makes tor_ersatz_socketpair() follow the same interface as socketpair() rather than tor_socketpair(), so it now needs to be wrapped in the same code as socketpair() does.
Diffstat (limited to 'src/lib/net/socket.c')
-rw-r--r--src/lib/net/socket.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lib/net/socket.c b/src/lib/net/socket.c
index 5487b8d9df..06421b080d 100644
--- a/src/lib/net/socket.c
+++ b/src/lib/net/socket.c
@@ -420,9 +420,9 @@ get_n_open_sockets(void)
int
tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2])
{
+ int r;
//don't use win32 socketpairs (they are always bad)
#if defined(HAVE_SOCKETPAIR) && !defined(_WIN32)
- int r;
#ifdef SOCK_CLOEXEC
r = socketpair(family, type|SOCK_CLOEXEC, protocol, fd);
@@ -438,6 +438,11 @@ tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2])
r = socketpair(family, type, protocol, fd);
if (r < 0)
return -errno;
+#else
+ r = tor_ersatz_socketpair(family, type, protocol, fd);
+ if (r < 0)
+ return -r;
+#endif
#if defined(FD_CLOEXEC)
if (SOCKET_OK(fd[0])) {
@@ -472,9 +477,6 @@ tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2])
socket_accounting_unlock();
return 0;
-#else /* !(defined(HAVE_SOCKETPAIR) && !defined(_WIN32)) */
- return tor_ersatz_socketpair(family, type, protocol, fd);
-#endif /* defined(HAVE_SOCKETPAIR) && !defined(_WIN32) */
}
/** Mockable wrapper for getsockname(). */