Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::runtime::Socket Class Reference

#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

Constructor & Destructor Documentation

◆ Socket() [1/3]

pulp::runtime::Socket::Socket ( )
default

◆ ~Socket()

pulp::runtime::Socket::~Socket ( )

◆ Socket() [2/3]

pulp::runtime::Socket::Socket ( const Socket & )
delete

◆ Socket() [3/3]

pulp::runtime::Socket::Socket ( Socket && other)
noexcept

Member Function Documentation

◆ accept() [1/2]

std::optional< Socket > pulp::runtime::Socket::accept ( )

Accept an incoming TCP or OS-local connection, blocking until one is available.

◆ accept() [2/2]

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().

◆ bind()

bool pulp::runtime::Socket::bind ( std::string_view address,
uint16_t port )

Bind to a local address and port.

◆ bind_local()

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.

◆ close()

void pulp::runtime::Socket::close ( )

Close the socket.

◆ connect()

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.

◆ connect_local()

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.

◆ create()

bool pulp::runtime::Socket::create ( SocketType type)

Create a socket.

◆ duplicate_local_handle()

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.

◆ is_open()

bool pulp::runtime::Socket::is_open ( ) const

Whether the socket is open.

◆ listen()

bool pulp::runtime::Socket::listen ( int backlog = 5)

Listen for incoming TCP or OS-local stream connections.

◆ local_address()

std::string pulp::runtime::Socket::local_address ( ) const

Bound local IPv4 address in dotted form, or empty when unavailable/unbound.

◆ local_peer_credentials()

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.

◆ local_port()

uint16_t pulp::runtime::Socket::local_port ( ) const

Bound local port, or 0 when unavailable/unbound.

◆ operator=() [1/2]

Socket & pulp::runtime::Socket::operator= ( const Socket & )
delete

◆ operator=() [2/2]

Socket & pulp::runtime::Socket::operator= ( Socket && other)
noexcept

◆ receive()

int pulp::runtime::Socket::receive ( uint8_t * buffer,
size_t buffer_size )

Receive data. Returns bytes received, or -1 on error. 0 = connection closed.

◆ receive_from()

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.

◆ send() [1/2]

int pulp::runtime::Socket::send ( const uint8_t * data,
size_t length )

Send data. Returns bytes sent, or -1 on error.

◆ send() [2/2]

int pulp::runtime::Socket::send ( std::string_view data)

◆ send_to()

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.

◆ set_read_timeout()

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.

◆ set_write_timeout()

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.

◆ shutdown()

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.


The documentation for this class was generated from the following file:
  • /home/runner/work/pulp/pulp/core/runtime/include/pulp/runtime/socket.hpp