pub struct PairSocket<S = TcpStream>{ /* private fields */ }Expand description
PAIR socket for exclusive peer-to-peer communication.
PAIR sockets connect exactly two endpoints and provide bidirectional message passing without any routing or filtering logic.
Implementations§
Source§impl<S> PairSocket<S>
impl<S> PairSocket<S>
Sourcepub async fn new(stream: S) -> Result<PairSocket<S>, Error>
pub async fn new(stream: S) -> Result<PairSocket<S>, Error>
Create a new PAIR socket from a stream with default buffer configuration.
Sourcepub async fn with_options(
stream: S,
options: SocketOptions,
) -> Result<PairSocket<S>, Error>
pub async fn with_options( stream: S, options: SocketOptions, ) -> Result<PairSocket<S>, Error>
Create a new PAIR socket with custom buffer configuration and socket options.
Sourcepub async fn send(&mut self, msg: Vec<Bytes>) -> Result<(), Error>
pub async fn send(&mut self, msg: Vec<Bytes>) -> Result<(), Error>
Send a message to the paired socket.
§Errors
Returns an error if the socket is poisoned, disconnected, or if the write fails.
Sourcepub async fn recv(&mut self) -> Result<Option<Vec<Bytes>>, Error>
pub async fn recv(&mut self) -> Result<Option<Vec<Bytes>>, Error>
Receive a message from the paired socket.
Returns Ok(Some(msg)) if a message was received, Ok(None) if the
connection was closed, or an error.
Sourcepub async fn close(self) -> Result<(), Error>
pub async fn close(self) -> Result<(), Error>
Close the socket gracefully by shutting down the underlying stream.
Sourcepub const fn options(&self) -> &SocketOptions
pub const fn options(&self) -> &SocketOptions
Get a reference to the socket options.
Sourcepub fn options_mut(&mut self) -> &mut SocketOptions
pub fn options_mut(&mut self) -> &mut SocketOptions
Get a mutable reference to the socket options.
Sourcepub fn set_options(&mut self, options: SocketOptions)
pub fn set_options(&mut self, options: SocketOptions)
Set socket options (builder-style).
Sourcepub const fn socket_type(&self) -> SocketType
pub const fn socket_type(&self) -> SocketType
Sourcepub fn last_endpoint(&self) -> Option<&Endpoint>
pub fn last_endpoint(&self) -> Option<&Endpoint>
Get the endpoint this socket is connected/bound to, if available.
Returns None if the socket was created from a raw stream.
§ZeroMQ Compatibility
Corresponds to ZMQ_LAST_ENDPOINT (32) option.
Sourcepub fn has_more(&self) -> bool
pub fn has_more(&self) -> bool
Check if the last received message has more frames coming.
Returns true if there are more frames in the current multipart message.
§ZeroMQ Compatibility
Corresponds to ZMQ_RCVMORE (13) option.
Sourcepub fn events(&self) -> u32
pub fn events(&self) -> u32
Get the event state of the socket.
Returns a bitmask indicating ready-to-receive and ready-to-send states.
§Returns
1(POLLIN) - Socket is ready to receive2(POLLOUT) - Socket is ready to send3(POLLIN | POLLOUT) - Socket is ready for both
§ZeroMQ Compatibility
Corresponds to ZMQ_EVENTS (15) option.
Source§impl PairSocket
impl PairSocket
Sourcepub async fn bind(
addr: impl ToSocketAddrsAsync,
) -> Result<(TcpListener, PairSocket), Error>
pub async fn bind( addr: impl ToSocketAddrsAsync, ) -> Result<(TcpListener, PairSocket), Error>
Bind to an address and accept the first connection.
PAIR sockets form an exclusive pair with exactly one peer.
§Returns
A tuple of (listener, socket) where:
listenercan be used to accept additional connections if neededsocketis ready to send/receive with the first peer
§Example
use monocoque_zmtp::pair::PairSocket;
let (listener, mut socket) = PairSocket::bind("127.0.0.1:5555").await?;Sourcepub async fn connect(addr: impl ToSocketAddrsAsync) -> Result<PairSocket, Error>
pub async fn connect(addr: impl ToSocketAddrsAsync) -> Result<PairSocket, Error>
Connect to a remote PAIR socket, storing the endpoint for automatic reconnection.
§Example
use monocoque_zmtp::pair::PairSocket;
let mut socket = PairSocket::connect("127.0.0.1:5555").await?;Sourcepub async fn connect_with_options(
addr: impl ToSocketAddrsAsync,
options: SocketOptions,
) -> Result<PairSocket, Error>
pub async fn connect_with_options( addr: impl ToSocketAddrsAsync, options: SocketOptions, ) -> Result<PairSocket, Error>
Connect with custom options, storing the endpoint for reconnection.
Sourcepub async fn from_tcp(stream: TcpStream) -> Result<PairSocket, Error>
pub async fn from_tcp(stream: TcpStream) -> Result<PairSocket, Error>
Create a new PAIR socket from a TCP stream with TCP_NODELAY enabled.
Sourcepub async fn from_tcp_with_options(
stream: TcpStream,
options: SocketOptions,
) -> Result<PairSocket, Error>
pub async fn from_tcp_with_options( stream: TcpStream, options: SocketOptions, ) -> Result<PairSocket, Error>
Create a new PAIR socket from a TCP stream with TCP_NODELAY and custom options.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if the socket is currently connected.
Sourcepub async fn try_reconnect(&mut self) -> Result<(), Error>
pub async fn try_reconnect(&mut self) -> Result<(), Error>
Try to reconnect to the stored endpoint.
Sourcepub async fn recv_with_reconnect(&mut self) -> Result<Option<Vec<Bytes>>, Error>
pub async fn recv_with_reconnect(&mut self) -> Result<Option<Vec<Bytes>>, Error>
Receive a message with automatic reconnection on EOF or network error.
If the socket was created with connect() and stores an endpoint, this
method loops: on EOF or broken-pipe it clears the stream and calls
try_reconnect() (which applies exponential backoff), then retries recv().
Respects max_reconnect_attempts - returns NotConnected when exhausted.
Sourcepub async fn send_with_reconnect(
&mut self,
msg: Vec<Bytes>,
) -> Result<(), Error>
pub async fn send_with_reconnect( &mut self, msg: Vec<Bytes>, ) -> Result<(), Error>
Send a message with automatic reconnection on network error.
On BrokenPipe / ConnectionReset, write_from_buf() already sets
stream = None, so the next loop iteration reconnects automatically.
Respects max_reconnect_attempts - returns NotConnected when exhausted.
Source§impl PairSocket<InprocStream>
impl PairSocket<InprocStream>
Sourcepub fn bind_inproc(endpoint: &str) -> Result<PairSocket<InprocStream>, Error>
pub fn bind_inproc(endpoint: &str) -> Result<PairSocket<InprocStream>, Error>
Bind to an inproc endpoint.
Creates a new inproc endpoint that other sockets can connect to. Inproc endpoints must be bound before they can be connected to.
§Arguments
endpoint- Inproc URI (e.g., “inproc://my-endpoint”)
§Example
use monocoque_zmtp::pair::PairSocket;
let socket = PairSocket::bind_inproc("inproc://my-pair")?;Sourcepub fn bind_inproc_with_options(
endpoint: &str,
options: SocketOptions,
) -> Result<PairSocket<InprocStream>, Error>
pub fn bind_inproc_with_options( endpoint: &str, options: SocketOptions, ) -> Result<PairSocket<InprocStream>, Error>
Bind to an inproc endpoint with custom configuration and options.
Sourcepub fn connect_inproc(endpoint: &str) -> Result<PairSocket<InprocStream>, Error>
pub fn connect_inproc(endpoint: &str) -> Result<PairSocket<InprocStream>, Error>
Sourcepub fn connect_inproc_with_options(
endpoint: &str,
options: SocketOptions,
) -> Result<PairSocket<InprocStream>, Error>
pub fn connect_inproc_with_options( endpoint: &str, options: SocketOptions, ) -> Result<PairSocket<InprocStream>, Error>
Connect to an inproc endpoint with custom configuration and options.
Trait Implementations§
Source§impl ProxySocket for PairSocket
impl ProxySocket for PairSocket
Source§fn recv_multipart<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Bytes>>, Error>> + 'async_trait>>where
'life0: 'async_trait,
PairSocket: 'async_trait,
fn recv_multipart<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Bytes>>, Error>> + 'async_trait>>where
'life0: 'async_trait,
PairSocket: 'async_trait,
Source§fn send_multipart<'life0, 'async_trait>(
&'life0 mut self,
msg: Vec<Bytes>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'async_trait>>where
'life0: 'async_trait,
PairSocket: 'async_trait,
fn send_multipart<'life0, 'async_trait>(
&'life0 mut self,
msg: Vec<Bytes>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'async_trait>>where
'life0: 'async_trait,
PairSocket: 'async_trait,
Source§fn socket_desc(&self) -> &'static str
fn socket_desc(&self) -> &'static str
Source§impl<S> Socket for PairSocket<S>
impl<S> Socket for PairSocket<S>
Source§fn send<'life0, 'async_trait>(
&'life0 mut self,
msg: Vec<Bytes>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'async_trait>>where
'life0: 'async_trait,
PairSocket<S>: 'async_trait,
fn send<'life0, 'async_trait>(
&'life0 mut self,
msg: Vec<Bytes>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'async_trait>>where
'life0: 'async_trait,
PairSocket<S>: 'async_trait,
Source§fn recv<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Bytes>>, Error>> + 'async_trait>>where
'life0: 'async_trait,
PairSocket<S>: 'async_trait,
fn recv<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Bytes>>, Error>> + 'async_trait>>where
'life0: 'async_trait,
PairSocket<S>: 'async_trait,
Source§fn socket_type(&self) -> SocketType
fn socket_type(&self) -> SocketType
Auto Trait Implementations§
impl<S = TcpStream> !Freeze for PairSocket<S>
impl<S> RefUnwindSafe for PairSocket<S>where
S: RefUnwindSafe,
impl<S> Send for PairSocket<S>where
S: Send,
impl<S> Sync for PairSocket<S>where
S: Sync,
impl<S> Unpin for PairSocket<S>
impl<S> UnsafeUnpin for PairSocket<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for PairSocket<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more