#include <socket.hpp>
Public Member Functions | |
| Socket ()=default | |
| ~Socket () | |
| bool | create (SocketType type) |
| Create a socket. | |
| bool | bind (std::string_view address, uint16_t port) |
| Bind to a local address and port. | |
| bool | bind_local (std::string_view path) |
| Bind an OS-local stream endpoint. | |
| bool | listen (int backlog=5) |
| Listen for incoming TCP or OS-local stream connections. | |
| std::optional< Socket > | accept () |
| Accept an incoming TCP or OS-local connection, blocking until one is available. | |
| std::optional< Socket > | accept (std::chrono::milliseconds timeout) |
| Wait up to timeout for and accept an incoming connection. | |
| bool | connect (std::string_view address, uint16_t port, std::chrono::milliseconds timeout={}) |
| Connect to a remote address (TCP). | |
| 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. | |
| std::optional< LocalPeerCredentials > | local_peer_credentials () const |
| Kernel-observed credentials for the connected OS-local peer. | |
| bool | duplicate_local_handle (std::intptr_t handle) |
| Duplicate an already-connected OS-local stream handle and own the duplicate. | |
| int | send (const uint8_t *data, size_t length) |
| Send data. Returns bytes sent, or -1 on error. | |
| int | send (std::string_view data) |
| int | send_to (const uint8_t *data, size_t length, std::string_view address, uint16_t port) |
| Send UDP datagram to specific address. | |
| int | receive (uint8_t *buffer, size_t buffer_size) |
| Receive data. Returns bytes received, or -1 on error. 0 = connection closed. | |
| bool | set_write_timeout (std::chrono::milliseconds timeout) |
| Bound blocking send operations. | |
| bool | set_read_timeout (std::chrono::milliseconds timeout) |
| Bound blocking receive operations. | |
| 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. | |
| void | close () |
| Close the socket. | |
| void | shutdown () |
| Interrupt blocking stream operations without closing the socket handle. | |
| bool | is_open () const |
| Whether the socket is open. | |
| uint16_t | local_port () const |
| Bound local port, or 0 when unavailable/unbound. | |
| std::string | local_address () const |
| Bound local IPv4 address in dotted form, or empty when unavailable/unbound. | |
| Socket (const Socket &)=delete | |
| Socket & | operator= (const Socket &)=delete |
| Socket (Socket &&other) noexcept | |
| Socket & | operator= (Socket &&other) noexcept |
|
default |
| pulp::runtime::Socket::~Socket | ( | ) |
|
delete |
|
noexcept |
| std::optional< Socket > pulp::runtime::Socket::accept | ( | ) |
Accept an incoming TCP or OS-local connection, blocking until one is available.
| std::optional< Socket > pulp::runtime::Socket::accept | ( | std::chrono::milliseconds | timeout | ) |
Wait up to timeout for and accept an incoming connection.
A non-positive timeout preserves the blocking behavior of accept().
| bool pulp::runtime::Socket::bind | ( | std::string_view | address, |
| uint16_t | port ) |
Bind to a local address and port.
| bool pulp::runtime::Socket::bind_local | ( | std::string_view | path | ) |
Bind an OS-local stream endpoint.
The path must not already exist and its parent directory must already be private to the owning user.
| void pulp::runtime::Socket::close | ( | ) |
Close the socket.
| bool pulp::runtime::Socket::connect | ( | std::string_view | address, |
| uint16_t | port, | ||
| std::chrono::milliseconds | timeout = {} ) |
Connect to a remote address (TCP).
A positive timeout bounds the nonblocking connect phase; non-positive preserves blocking behavior.
| bool pulp::runtime::Socket::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.
| bool pulp::runtime::Socket::create | ( | SocketType | type | ) |
Create a socket.
| bool pulp::runtime::Socket::duplicate_local_handle | ( | std::intptr_t | handle | ) |
Duplicate an already-connected OS-local stream handle and own the duplicate.
The supplied handle remains owned by its caller.
| bool pulp::runtime::Socket::is_open | ( | ) | const |
Whether the socket is open.
| bool pulp::runtime::Socket::listen | ( | int | backlog = 5 | ) |
Listen for incoming TCP or OS-local stream connections.
| std::string pulp::runtime::Socket::local_address | ( | ) | const |
Bound local IPv4 address in dotted form, or empty when unavailable/unbound.
| std::optional< LocalPeerCredentials > pulp::runtime::Socket::local_peer_credentials | ( | ) | const |
Kernel-observed credentials for the connected OS-local peer.
Unsupported transports and platforms return std::nullopt.
| uint16_t pulp::runtime::Socket::local_port | ( | ) | const |
Bound local port, or 0 when unavailable/unbound.
| int pulp::runtime::Socket::receive | ( | uint8_t * | buffer, |
| size_t | buffer_size ) |
Receive data. Returns bytes received, or -1 on error. 0 = connection closed.
| int pulp::runtime::Socket::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.
| int pulp::runtime::Socket::send | ( | const uint8_t * | data, |
| size_t | length ) |
Send data. Returns bytes sent, or -1 on error.
| int pulp::runtime::Socket::send | ( | std::string_view | data | ) |
| int pulp::runtime::Socket::send_to | ( | const uint8_t * | data, |
| size_t | length, | ||
| std::string_view | address, | ||
| uint16_t | port ) |
Send UDP datagram to specific address.
| bool pulp::runtime::Socket::set_read_timeout | ( | std::chrono::milliseconds | timeout | ) |
Bound blocking receive operations.
A non-positive duration clears the deadline. Applies to subsequently issued operations.
| bool pulp::runtime::Socket::set_write_timeout | ( | std::chrono::milliseconds | timeout | ) |
Bound blocking send operations.
A non-positive duration clears the deadline. Applies to subsequently issued operations.
| void pulp::runtime::Socket::shutdown | ( | ) |
Interrupt blocking stream operations without closing the socket handle.
A receive() blocked in another thread returns 0, as at end of stream.