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

Interprocess connection — send and receive length-prefixed messages. More...

#include <interprocess_connection.hpp>

Public Member Functions

 InterprocessConnection ()
virtual ~InterprocessConnection ()
bool connect (std::string_view name, IpcTransport transport=IpcTransport::NamedPipe, std::chrono::milliseconds timeout={})
 Connect as client to a named pipe, TCP socket, or OS-local socket.
bool create_server (std::string_view name, IpcTransport transport=IpcTransport::NamedPipe, int timeout_ms=0)
 Create a server that listens for one client connection.
std::string server_bind_address () const
 Address the most recent socket create_server() bound its listener to (e.g.
bool attach_inherited_local_socket (std::intptr_t handle)
 Attach to a duplicate of an already-connected OS-local socket handle.
void disconnect ()
 Disconnect and clean up.
bool is_connected () const
 Whether currently connected.
IpcState state () const
 Current state.
std::optional< runtime::LocalPeerCredentials > local_peer_credentials () const
 Kernel-observed credentials for the process on the other end of a connected local socket.
bool send_message (const void *data, size_t size)
 Send a message (length-prefixed).
bool send_message (std::string_view message)
 Send a string message.
void set_max_message_bytes (std::size_t bytes)
 Override the framing ceiling before connecting or accepting work.
std::size_t max_message_bytes () const
void set_write_timeout (std::chrono::milliseconds timeout)
 Apply a blocking write deadline for socket transports.
void set_frame_read_timeout (std::chrono::milliseconds timeout)
 Bound a frame once its first byte arrives.
void set_secure_receive_buffer (bool enabled)
 Securely clear each received frame buffer after callbacks return.
virtual void connection_made ()
 Called when a connection is established.
virtual void connection_lost ()
 Called when the connection is lost.
virtual void message_received (const void *data, size_t size)
 Called when a message is received. Called on the background read thread.
virtual void message_received (std::string_view message)
 Convenience: called with string view for text messages.
void set_on_connected (std::function< void()> callback)
void set_on_disconnected (std::function< void()> callback)
void set_on_message (std::function< void(const void *, size_t)> callback)
void set_on_text_message (std::function< void(std::string_view)> callback)
 InterprocessConnection (const InterprocessConnection &)=delete
InterprocessConnection & operator= (const InterprocessConnection &)=delete

Public Attributes

std::function< void()> on_connected
 Lambda-based callbacks (alternative to overriding).
std::function< void()> on_disconnected
std::function< void(const void *, size_t)> on_message
std::function< void(std::string_view)> on_text_message

Friends

class InterprocessConnectionServer

Detailed Description

Interprocess connection — send and receive length-prefixed messages.

Messages are framed as: [4-byte little-endian length][payload bytes]

Constructor & Destructor Documentation

◆ InterprocessConnection() [1/2]

pulp::events::InterprocessConnection::InterprocessConnection ( )

◆ ~InterprocessConnection()

virtual pulp::events::InterprocessConnection::~InterprocessConnection ( )
virtual

◆ InterprocessConnection() [2/2]

pulp::events::InterprocessConnection::InterprocessConnection ( const InterprocessConnection & )
delete

Member Function Documentation

◆ attach_inherited_local_socket()

bool pulp::events::InterprocessConnection::attach_inherited_local_socket ( std::intptr_t handle)

Attach to a duplicate of an already-connected OS-local socket handle.

Callbacks must be installed first. Unsupported platforms fail closed.

◆ connect()

bool pulp::events::InterprocessConnection::connect ( std::string_view name,
IpcTransport transport = IpcTransport::NamedPipe,
std::chrono::milliseconds timeout = {} )

Connect as client to a named pipe, TCP socket, or OS-local socket.

For pipes: name is the pipe name (e.g., "pulp_scanner"). For sockets: name is "host:port" (e.g., "127.0.0.1:9100"). For local sockets: name is an absolute filesystem endpoint path. A positive timeout bounds the socket connect phase.

◆ connection_lost()

virtual void pulp::events::InterprocessConnection::connection_lost ( )
inlinevirtual

Called when the connection is lost.

◆ connection_made()

virtual void pulp::events::InterprocessConnection::connection_made ( )
inlinevirtual

Called when a connection is established.

◆ create_server()

bool pulp::events::InterprocessConnection::create_server ( std::string_view name,
IpcTransport transport = IpcTransport::NamedPipe,
int timeout_ms = 0 )

Create a server that listens for one client connection.

Blocks until a client connects (or timeout_ms expires, 0 = infinite). For sockets an omitted host ("9100") listens on 127.0.0.1 only; pass "0.0.0.0:9100" explicitly to accept connections from other hosts.

◆ disconnect()

void pulp::events::InterprocessConnection::disconnect ( )

Disconnect and clean up.

◆ is_connected()

bool pulp::events::InterprocessConnection::is_connected ( ) const
inline

Whether currently connected.

◆ local_peer_credentials()

std::optional< runtime::LocalPeerCredentials > pulp::events::InterprocessConnection::local_peer_credentials ( ) const

Kernel-observed credentials for the process on the other end of a connected local socket.

Request payloads cannot influence this result.

◆ max_message_bytes()

std::size_t pulp::events::InterprocessConnection::max_message_bytes ( ) const
inline

◆ message_received() [1/2]

virtual void pulp::events::InterprocessConnection::message_received ( const void * data,
size_t size )
inlinevirtual

Called when a message is received. Called on the background read thread.

◆ message_received() [2/2]

virtual void pulp::events::InterprocessConnection::message_received ( std::string_view message)
inlinevirtual

Convenience: called with string view for text messages.

◆ operator=()

InterprocessConnection & pulp::events::InterprocessConnection::operator= ( const InterprocessConnection & )
delete

◆ send_message() [1/2]

bool pulp::events::InterprocessConnection::send_message ( const void * data,
size_t size )

Send a message (length-prefixed).

Thread-safe. Returns true if the message was sent successfully.

◆ send_message() [2/2]

bool pulp::events::InterprocessConnection::send_message ( std::string_view message)

Send a string message.

◆ server_bind_address()

std::string pulp::events::InterprocessConnection::server_bind_address ( ) const

Address the most recent socket create_server() bound its listener to (e.g.

"127.0.0.1"), or empty when no socket listener was bound.

◆ set_frame_read_timeout()

void pulp::events::InterprocessConnection::set_frame_read_timeout ( std::chrono::milliseconds timeout)

Bound a frame once its first byte arrives.

Idle connections may wait indefinitely for the next frame, but a partial header or payload is disconnected when this cumulative deadline expires.

◆ set_max_message_bytes()

void pulp::events::InterprocessConnection::set_max_message_bytes ( std::size_t bytes)

Override the framing ceiling before connecting or accepting work.

Oversized outbound frames are rejected; oversized inbound frames close the connection before allocating their declared payload. Values above the socket API's INT_MAX transfer-count boundary are clamped.

◆ set_on_connected()

void pulp::events::InterprocessConnection::set_on_connected ( std::function< void()> callback)

◆ set_on_disconnected()

void pulp::events::InterprocessConnection::set_on_disconnected ( std::function< void()> callback)

◆ set_on_message()

void pulp::events::InterprocessConnection::set_on_message ( std::function< void(const void *, size_t)> callback)

◆ set_on_text_message()

void pulp::events::InterprocessConnection::set_on_text_message ( std::function< void(std::string_view)> callback)

◆ set_secure_receive_buffer()

void pulp::events::InterprocessConnection::set_secure_receive_buffer ( bool enabled)

Securely clear each received frame buffer after callbacks return.

Enable this before attaching transports that carry credential material.

◆ set_write_timeout()

void pulp::events::InterprocessConnection::set_write_timeout ( std::chrono::milliseconds timeout)

Apply a blocking write deadline for socket transports.

A timed-out frame poisons and closes the connection so no later frame can be appended to a truncated stream.

◆ state()

IpcState pulp::events::InterprocessConnection::state ( ) const
inline

Current state.

◆ InterprocessConnectionServer

friend class InterprocessConnectionServer
friend

Member Data Documentation

◆ on_connected

std::function<void()> pulp::events::InterprocessConnection::on_connected

Lambda-based callbacks (alternative to overriding).

Assign these directly before a connection starts. For already-connected instances, use the setter methods so the background read thread sees a synchronized callback update.

◆ on_disconnected

std::function<void()> pulp::events::InterprocessConnection::on_disconnected

◆ on_message

std::function<void(const void*, size_t)> pulp::events::InterprocessConnection::on_message

◆ on_text_message

std::function<void(std::string_view)> pulp::events::InterprocessConnection::on_text_message

The documentation for this class was generated from the following file: