14 [[nodiscard]]
bool valid()
const {
return value.length > 0; }
94 bool connect(
const std::string_view host,
const std::string_view port);
107 bool listen(std::string_view port,
int backlog);
114 bool listen_unix(std::string_view path,
int backlog);
126 bool bind(std::string_view port);
137 [[nodiscard]] std::optional<Socket>
accept();
146 ssize_t
read(
void *buf,
size_t bytes,
int flags);
153 bool readline(
char **buffer,
size_t *len);
161 ssize_t
write(
const void *buf,
size_t bytes,
int flags);
168 ssize_t
read_all(
void *buf,
size_t bytes);
175 ssize_t
write_all(
const void *buf,
size_t bytes);
182 ssize_t
sendto(
const void *buf,
size_t bytes);
189 ssize_t
recvfrom(
void *buf,
size_t bytes);
194 [[nodiscard]]
bool valid()
const;
196 [[nodiscard]]
bool is_open()
const;
bool listen_unix(std::string_view path, int backlog)
Start listening on a UNIX-domain socket path.
ssize_t write_all(const void *buf, size_t bytes)
Write exactly the requested number of bytes.
ssize_t write(const void *buf, size_t bytes, int flags)
Write bytes to the socket.
void close()
Close the socket if it is open.
bool valid() const
Return true when the socket handle is valid.
bool is_open() const
Return true when the socket is open.
bool bind_unix(std::string_view path)
Bind a UNIX-domain socket to a local path.
bool readline(char **buffer, size_t *len)
Read a line of text from the socket.
SocketType socket_type() const
Return the socket family and transport type.
~Socket() noexcept
Destroy the socket wrapper and close the socket if needed.
ssize_t sendto(const void *buf, size_t bytes)
Send a datagram using the configured socket type.
Socket() noexcept
Construct an invalid socket wrapper.
bool bind(std::string_view port)
Bind an Internet socket to a local port.
bool listen(std::string_view port, int backlog)
Start listening on an Internet port.
std::optional< Socket > accept()
Accept an incoming connection.
bool setblocking(bool block)
Toggle blocking mode.
ssize_t read_all(void *buf, size_t bytes)
Read exactly the requested number of bytes.
ssize_t read(void *buf, size_t bytes, int flags)
Read bytes from the socket.
mx_socket_fd sockfd() const
Return the underlying socket handle.
Socket & operator=(const Socket &s)=delete
Socket(const Socket &s)=delete
bool connect_unix(const std::string_view path)
Connect to a UNIX-domain endpoint.
bool connect(const std::string_view host, const std::string_view port)
Connect to a remote Internet endpoint.
ssize_t recvfrom(void *buf, size_t bytes)
Receive a datagram using the configured socket type.
SocketType
Socket family and transport type.
@ TYPE_INVALID
No socket type selected.
@ TYPE_UNIX_DGRAM
UNIX-domain datagram socket.
@ TYPE_INET_DGRAM
IPv4 datagram socket.
@ TYPE_INET6_DGRAM
IPv6 datagram socket.
@ TYPE_UNIX
UNIX-domain stream socket.
@ TYPE_INET6
IPv6 stream socket.
@ TYPE_INET
IPv4 stream socket.
Cross-platform socket state used by the C API.
MXNetworkInit()
Initialize the socket backend for the current process.
MXNetworkInit(const MXNetworkInit &)=delete
MXNetworkInit & operator=(const MXNetworkInit &)=delete
~MXNetworkInit()
Shut down the socket backend.
bool operator==(const SocketAddress &other) const