39 bool bind(std::string_view address, uint16_t port);
54 std::optional<Socket>
accept(std::chrono::milliseconds timeout);
58 bool connect(std::string_view address, uint16_t port,
59 std::chrono::milliseconds timeout = {});
64 std::chrono::milliseconds timeout = {});
75 int send(
const uint8_t* data,
size_t length);
76 int send(std::string_view data);
79 int send_to(
const uint8_t* data,
size_t length,
80 std::string_view address, uint16_t port);
83 int receive(uint8_t* buffer,
size_t buffer_size);
95 std::string& from_address, uint16_t& from_port);
122 std::uintptr_t fd_ =
~std::uintptr_t{0};
127 std::string bound_local_path_;
128 std::uint64_t bound_local_device_ = 0;
129 std::uint64_t bound_local_inode_ = 0;
134 std::atomic<bool> shutdown_requested_{
false};
135 std::atomic<std::int64_t> read_timeout_ms_{0};
138 bool connect_address(
const void* address, std::size_t address_size,
139 std::chrono::milliseconds timeout);
bool bind(std::string_view address, uint16_t port)
Bind to a local address and port.
bool connect(std::string_view address, uint16_t port, std::chrono::milliseconds timeout={})
Connect to a remote address (TCP).
Socket & operator=(const Socket &)=delete
Socket(const Socket &)=delete
Socket & operator=(Socket &&other) noexcept
int receive(uint8_t *buffer, size_t buffer_size)
Receive data. Returns bytes received, or -1 on error. 0 = connection closed.
void shutdown()
Interrupt blocking stream operations without closing the socket handle.
int send_to(const uint8_t *data, size_t length, std::string_view address, uint16_t port)
Send UDP datagram to specific address.
bool create(SocketType type)
Create a socket.
int send(std::string_view data)
bool duplicate_local_handle(std::intptr_t handle)
Duplicate an already-connected OS-local stream handle and own the duplicate.
void close()
Close the socket.
bool bind_local(std::string_view path)
Bind an OS-local stream endpoint.
std::optional< Socket > accept()
Accept an incoming TCP or OS-local connection, blocking until one is available.
int send(const uint8_t *data, size_t length)
Send data. Returns bytes sent, or -1 on error.
bool listen(int backlog=5)
Listen for incoming TCP or OS-local stream connections.
bool connect_local(std::string_view path, std::chrono::milliseconds timeout={})
Connect to an OS-local stream endpoint with the same bounded-connect semantics as TCP.
int receive_from(uint8_t *buffer, size_t buffer_size, std::string &from_address, uint16_t &from_port)
Receive UDP datagram. Returns bytes received and source address.
std::optional< LocalPeerCredentials > local_peer_credentials() const
Kernel-observed credentials for the connected OS-local peer.
bool is_open() const
Whether the socket is open.
std::optional< Socket > accept(std::chrono::milliseconds timeout)
Wait up to timeout for and accept an incoming connection.
bool set_write_timeout(std::chrono::milliseconds timeout)
Bound blocking send operations.
std::string local_address() const
Bound local IPv4 address in dotted form, or empty when unavailable/unbound.
uint16_t local_port() const
Bound local port, or 0 when unavailable/unbound.
Socket(Socket &&other) noexcept
bool set_read_timeout(std::chrono::milliseconds timeout)
Bound blocking receive operations.
Definition generated_event_source.hpp:33
@ other
Definition udev_monitor.hpp:26
SocketType
Definition socket.hpp:16
@ Local
Definition socket.hpp:16
@ TCP
Definition socket.hpp:16
@ UDP
Definition socket.hpp:16
Credentials reported by the kernel for the process on the other end of an OS-local stream.
Definition socket.hpp:20
std::uint64_t group_id
Definition socket.hpp:22
std::uint64_t process_generation_id
Kernel process-generation discriminator when the platform exposes one.
Definition socket.hpp:27
std::int64_t process_id
Definition socket.hpp:23
std::uint64_t user_id
Definition socket.hpp:21