28 int domain,
int type,
int protocol,
29 int cloexec,
int nonblock);
35 struct sockaddr *addr,
38 struct sockaddr *addr,
40 int cloexec,
int nonblock);
42 const struct sockaddr *address,
43 socklen_t address_len));
47 socklen_t *address_len));
51 #define tor_socket_send(s, buf, len, flags) send(s, buf, len, flags)
52 #define tor_socket_recv(s, buf, len, flags) recv(s, buf, len, flags)
73 #define SOCK_ERRNO(e) WSA##e
75 #define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN || (e) == WSAEWOULDBLOCK)
77 #define ERRNO_IS_EINPROGRESS(e) ((e) == WSAEINPROGRESS)
80 #define ERRNO_IS_CONN_EINPROGRESS(e) \
81 ((e) == WSAEINPROGRESS || (e)== WSAEINVAL || (e) == WSAEWOULDBLOCK)
84 #define ERRNO_IS_ACCEPT_EAGAIN(e) ERRNO_IS_EAGAIN(e)
87 #define ERRNO_IS_RESOURCE_LIMIT(e) \
88 ((e) == WSAEMFILE || (e) == WSAENOBUFS)
90 #define ERRNO_IS_EADDRINUSE(e) ((e) == WSAEADDRINUSE)
92 #define ERRNO_IS_EINTR(e) ((e) == WSAEINTR || 0)
94 const char *tor_socket_strerror(
int e);
96 #define SOCK_ERRNO(e) e
97 #if EAGAIN == EWOULDBLOCK
99 #define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN || 0)
101 #define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN || (e) == EWOULDBLOCK)
103 #define ERRNO_IS_EINTR(e) ((e) == EINTR || 0)
104 #define ERRNO_IS_EINPROGRESS(e) ((e) == EINPROGRESS || 0)
105 #define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == EINPROGRESS || 0)
106 #define ERRNO_IS_ACCEPT_EAGAIN(e) \
107 (ERRNO_IS_EAGAIN(e) || (e) == ECONNABORTED)
108 #define ERRNO_IS_RESOURCE_LIMIT(e) \
109 ((e) == EMFILE || (e) == ENFILE || (e) == ENOBUFS || (e) == ENOMEM)
110 #define ERRNO_IS_EADDRINUSE(e) (((e) == EADDRINUSE) || 0)
111 #define tor_socket_errno(sock) (errno)
112 #define tor_socket_strerror(e) strerror(e)
115 #if defined(_WIN32) && !defined(SIO_IDEAL_SEND_BACKLOG_QUERY)
116 #define SIO_IDEAL_SEND_BACKLOG_QUERY 0x4004747b
Declarations for types used throughout the Tor networking system.
int server_mode(const or_options_t *options)
tor_socket_t tor_accept_socket(tor_socket_t sockfd, struct sockaddr *addr, socklen_t *len)
int tor_close_socket_simple(tor_socket_t s)
tor_socket_t tor_accept_socket_nonblocking(tor_socket_t sockfd, struct sockaddr *addr, socklen_t *len)
int get_max_sockets(void)
int tor_close_socket(tor_socket_t s)
int set_socket_nonblocking(tor_socket_t socket)
int tor_getsockname(tor_socket_t socket, struct sockaddr *address, socklen_t *address_len)
tor_socket_t tor_accept_socket_with_extensions(tor_socket_t sockfd, struct sockaddr *addr, socklen_t *len, int cloexec, int nonblock)
ssize_t write_all_to_socket(tor_socket_t fd, const char *buf, size_t count)
void check_network_configuration(bool server_mode)
tor_socket_t tor_open_socket_with_extensions(int domain, int type, int protocol, int cloexec, int nonblock)
int get_n_open_sockets(void)
int tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2])
ssize_t read_all_from_socket(tor_socket_t fd, char *buf, size_t count)
void tor_release_socket_ownership(tor_socket_t s)
int tor_addr_from_getsockname(struct tor_addr_t *addr_out, tor_socket_t sock)
void tor_take_socket_ownership(tor_socket_t s)
tor_socket_t tor_connect_socket(tor_socket_t socket, const struct sockaddr *address, socklen_t address_len)
tor_socket_t tor_open_socket(int domain, int type, int protocol)
void set_max_sockets(int)
tor_socket_t tor_open_socket_nonblocking(int domain, int type, int protocol)
Macros to implement mocking and selective exposure for the test code.
#define MOCK_DECL(rv, funcname, arglist)
Integer definitions used throughout Tor.