11#if __has_include(<afunix.h>)
15#define UNIX_PATH_MAX 108
18 ADDRESS_FAMILY sun_family;
19 char sun_path[UNIX_PATH_MAX];
24typedef ptrdiff_t ssize_t;
25#define mx_close_socket(s) closesocket(s)
26#define mx_set_err(e) WSASetLastError(WSA##e)
27#define SOCK_ERRNO WSAGetLastError()
28#define SOCK_EINTR WSAEINTR
29#define SOCK_EAGAIN WSAEWOULDBLOCK
30#define SOCK_EWOULDBLOCK WSAEWOULDBLOCK
31#define SOCK_ECONNABORTED WSAECONNABORTED
32#define SOCK_EINVAL WSAEINVAL
33#define SOCK_EBADF WSAEBADF
34#define SOCK_ENOTSOCK WSAENOTSOCK
35#define SOCK_ESHUTDOWN WSAESHUTDOWN
36#define SOCK_ECONNRESET WSAECONNRESET
37#define NULL_SOCKET INVALID_SOCKET
38#define MX_LEN(x) (int)(x)
44#include <netinet/in.h>
45#include <sys/socket.h>
49#define mx_close_socket(s) close(s)
50#define mx_set_err(e) (errno = (e))
51#define SOCK_ERRNO errno
52#define SOCK_EINTR EINTR
53#define SOCK_EAGAIN EAGAIN
54#define SOCK_EWOULDBLOCK EWOULDBLOCK
55#define SOCK_ECONNABORTED ECONNABORTED
56#define SOCK_EINVAL EINVAL
57#define SOCK_EBADF EBADF
58#define SOCK_ENOTSOCK ENOTSOCK
59#define SOCK_ESHUTDOWN ESHUTDOWN
60#define SOCK_ECONNRESET ECONNRESET
61#define MX_LEN(x) (size_t)(x)
72 struct sockaddr_un
sun;
ssize_t mx_socket_read(MXSocket *s, void *data, size_t len, int flags)
Read data from a socket.
bool mx_socket_ipv6_connect(MXSocket *s, const char *host, const char *port, int type)
Connect an IPv6 Internet socket to a remote host.
ssize_t mx_socket_recvfrom_address(MXSocket *sock, void *buf, size_t bytes, MXSocketAddress *address)
bool mx_socket_unix_bind(MXSocket *s, const char *path)
Bind a UNIX-domain socket to a local path.
ssize_t mx_socket_read_all(MXSocket *sock, void *buf, size_t bytes)
Read the requested number of bytes from a socket.
void mx_socket_close(MXSocket *s)
Close a socket if it is open.
ssize_t mx_socket_recvfrom(MXSocket *sock, void *buf, size_t bytes)
Receive a datagram using an Internet socket.
bool mx_socket_is_open(const MXSocket *s)
Check whether the socket is open.
bool mx_socket_set_blocking(MXSocket *s, bool state)
Toggle blocking mode for a socket.
void mx_socket_ignore_pipe_signal()
Ignore SIGPIPE on platforms that require it.
ssize_t mx_socket_sendto_address(MXSocket *sock, const void *buf, size_t bytes, const MXSocketAddress *address)
ssize_t mx_socket_write_all(MXSocket *sock, const void *buf, size_t bytes)
Write the requested number of bytes to a socket.
bool mx_socket_unix_connect(MXSocket *s, const char *path, int type)
Connect a UNIX-domain socket to a local path.
bool mx_socket_valid(const MXSocket *s)
Check whether the socket handle is valid.
bool mx_socket_unix_listen(MXSocket *s, const char *path, int backlog, int type)
Create and bind a UNIX-domain socket for listening.
ssize_t mx_socket_unix_sendto(MXSocket *sock, const void *buf, size_t bytes)
Send a datagram using a UNIX-domain socket.
bool mx_socket_listen(MXSocket *s, const char *port, int backlog, int type)
Create and bind an Internet socket for listening.
bool mx_socket_accept(const MXSocket *input, MXSocket *output)
Accept an incoming connection.
ssize_t mx_socket_send(MXSocket *s, const void *data, size_t len, int flags)
Write data to a socket.
bool mx_socket_connect(MXSocket *s, const char *host, const char *port, int type)
Connect an Internet socket to a remote host.
ssize_t mx_socket_ipv6_recvfrom(MXSocket *sock, void *buf, size_t bytes)
Receive a datagram using an IPv6 Internet socket.
bool mx_socket_ipv6_bind(MXSocket *s, const char *port)
Bind an IPv6 Internet socket to a local port.
bool mx_socket_readline(MXSocket *s, char **buffer, size_t *len)
Read a line of text from a socket.
bool mx_socket_ipv6_listen(MXSocket *s, const char *port, int backlog, int type)
Create and bind an IPv6 Internet socket for listening.
bool mx_socket_bind(MXSocket *s, const char *port)
Bind an Internet socket to a local port.
ssize_t mx_socket_sendto(MXSocket *sock, const void *buf, size_t bytes)
Send a datagram using an Internet socket.
bool mx_socket_init(MXSocket *s)
Initialize a socket structure with default values.
ssize_t mx_socket_ipv6_sendto(MXSocket *sock, const void *buf, size_t bytes)
Send a datagram using an IPv6 Internet socket.
ssize_t mx_socket_unix_recvfrom(MXSocket *sock, void *buf, size_t bytes)
Receive a datagram using a UNIX-domain socket.
struct sockaddr_storage storage
Cross-platform socket state used by the C API.
struct sockaddr_in6 inet6
IPv6 address storage.
bool blocking
True when the socket is in blocking mode.
struct sockaddr_in inet
IPv4 address storage.
struct sockaddr_un sun
UNIX-domain address storage.
mx_socket_fd sockfd
Underlying socket handle.
socklen_t addrlen
Length of the active address structure.