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 |
Interprocess connection — send and receive length-prefixed messages.
Messages are framed as: [4-byte little-endian length][payload bytes]
| pulp::events::InterprocessConnection::InterprocessConnection | ( | ) |
|
virtual |
|
delete |
| 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.
| 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.
|
inlinevirtual |
Called when the connection is lost.
|
inlinevirtual |
Called when a connection is established.
| 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.
| void pulp::events::InterprocessConnection::disconnect | ( | ) |
Disconnect and clean up.
|
inline |
Whether currently connected.
| 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.
|
inline |
|
inlinevirtual |
Called when a message is received. Called on the background read thread.
|
inlinevirtual |
Convenience: called with string view for text messages.
|
delete |
| 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.
| bool pulp::events::InterprocessConnection::send_message | ( | std::string_view | message | ) |
Send a string message.
| 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.
| 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.
| 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.
| void pulp::events::InterprocessConnection::set_on_connected | ( | std::function< void()> | callback | ) |
| void pulp::events::InterprocessConnection::set_on_disconnected | ( | std::function< void()> | callback | ) |
| void pulp::events::InterprocessConnection::set_on_message | ( | std::function< void(const void *, size_t)> | callback | ) |
| void pulp::events::InterprocessConnection::set_on_text_message | ( | std::function< void(std::string_view)> | callback | ) |
| 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.
| 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.
|
inline |
Current state.
|
friend |
| 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.
| std::function<void()> pulp::events::InterprocessConnection::on_disconnected |
| std::function<void(const void*, size_t)> pulp::events::InterprocessConnection::on_message |
| std::function<void(std::string_view)> pulp::events::InterprocessConnection::on_text_message |