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.
This commit is contained in:
Nick Mathewson
2018-08-01 09:40:02 -04:00
parent 9b24609af0
commit fc0dc5aa9e
4 changed files with 47 additions and 25 deletions
+17 -7
View File
@@ -5540,10 +5540,13 @@ test_util_socketpair(void *arg)
tt_assert(SOCKET_OK(fds[0]));
tt_assert(SOCKET_OK(fds[1]));
tt_int_op(get_n_open_sockets(), OP_EQ, n + 2);
if (ersatz)
tt_int_op(get_n_open_sockets(), OP_EQ, n);
else
tt_int_op(get_n_open_sockets(), OP_EQ, n + 2);
#ifdef CAN_CHECK_CLOEXEC
tt_int_op(fd_is_cloexec(fds[0]), OP_EQ, 1);
tt_int_op(fd_is_cloexec(fds[1]), OP_EQ, 1);
tt_int_op(fd_is_cloexec(fds[0]), OP_EQ, !ersatz);
tt_int_op(fd_is_cloexec(fds[1]), OP_EQ, !ersatz);
#endif
#ifdef CAN_CHECK_NONBLOCK
tt_int_op(fd_is_nonblocking(fds[0]), OP_EQ, 0);
@@ -5551,10 +5554,17 @@ test_util_socketpair(void *arg)
#endif
done:
if (SOCKET_OK(fds[0]))
tor_close_socket(fds[0]);
if (SOCKET_OK(fds[1]))
tor_close_socket(fds[1]);
if (ersatz) {
if (SOCKET_OK(fds[0]))
tor_close_socket_simple(fds[0]);
if (SOCKET_OK(fds[1]))
tor_close_socket_simple(fds[1]);
} else {
if (SOCKET_OK(fds[0]))
tor_close_socket(fds[0]);
if (SOCKET_OK(fds[1]))
tor_close_socket(fds[1]);
}
}
#undef SOCKET_EPROTO