pub struct PullSocket<S = TcpStream>{ /* private fields */ }Expand description
PULL socket for receiving tasks in a pipeline.
PULL sockets receive messages from connected PUSH sockets.
Implementations§
Source§impl PullSocket<TcpStream>
impl PullSocket<TcpStream>
Sourcepub async fn bind(addr: impl ToSocketAddrs) -> Result<(TcpListener, Self)>
pub async fn bind(addr: impl ToSocketAddrs) -> Result<(TcpListener, Self)>
Bind to addr, accept one connection, and return a ready PULL socket.
Returns the TcpListener so the caller can accept further PUSH connections.
§Example
use monocoque::zmq::PullSocket;
let (_listener, mut socket) = PullSocket::bind("127.0.0.1:5555").await?;
while let Ok(Some(msg)) = socket.recv().await {
println!("Got task: {:?}", msg);
}Sourcepub async fn connect(addr: impl ToSocketAddrs) -> Result<Self>
pub async fn connect(addr: impl ToSocketAddrs) -> Result<Self>
Connect to a PUSH socket at addr.
§Example
use monocoque::zmq::PullSocket;
let mut socket = PullSocket::connect("127.0.0.1:5555").await?;
while let Ok(Some(msg)) = socket.recv().await {
println!("Got task: {:?}", msg);
}Sourcepub async fn connect_with_options(
addr: impl ToSocketAddrs,
options: SocketOptions,
) -> Result<Self>
pub async fn connect_with_options( addr: impl ToSocketAddrs, options: SocketOptions, ) -> Result<Self>
Connect with custom options, storing the endpoint for automatic reconnection.
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<()>
pub async fn try_reconnect(&mut self) -> Result<()>
Try to reconnect to the stored endpoint.
Sourcepub async fn recv_with_reconnect(&mut self) -> Result<Option<Vec<Bytes>>>
pub async fn recv_with_reconnect(&mut self) -> Result<Option<Vec<Bytes>>>
Receive with automatic reconnection on EOF or network error.
Sourcepub async fn from_tcp(stream: TcpStream) -> Result<Self>
pub async fn from_tcp(stream: TcpStream) -> Result<Self>
Create a PULL socket from a TCP stream.
Sourcepub async fn from_tcp_with_options(
stream: TcpStream,
options: SocketOptions,
) -> Result<Self>
pub async fn from_tcp_with_options( stream: TcpStream, options: SocketOptions, ) -> Result<Self>
Create a PULL socket from a TCP stream with custom options.
Source§impl<S> PullSocket<S>
impl<S> PullSocket<S>
Sourcepub async fn with_options(stream: S, options: SocketOptions) -> Result<Self>
pub async fn with_options(stream: S, options: SocketOptions) -> Result<Self>
Create a PULL socket from any stream with custom options.
Sourcepub fn try_recv(&mut self) -> Result<Option<Vec<Bytes>>>
pub fn try_recv(&mut self) -> Result<Option<Vec<Bytes>>>
Try to receive a message from the already-buffered input without a kernel read.
Returns Ok(None) immediately when the receive buffer is empty. Use
after recv() to drain all messages delivered in one kernel read before
going back to the event loop. This reduces io_uring submissions for
throughput-bound pull loops.
if let Some(first) = pull.recv().await? {
drop(first);
while let Some(msg) = pull.try_recv()? {
drop(msg);
}
}Sourcepub async fn recv_into(&mut self, out: &mut Vec<Bytes>) -> Result<bool>
pub async fn recv_into(&mut self, out: &mut Vec<Bytes>) -> Result<bool>
Receive a message into a caller-provided buffer, reusing its allocation.
Like recv but the frames are written into out (cleared
first) instead of a freshly allocated Vec. Passing the same out on
every call removes the per-message allocation from a steady recv loop,
which is the dominant per-message cost for small messages. Returns
Ok(true) when a message was read, Ok(false) when the connection closed.
Sourcepub fn try_recv_into(&mut self, out: &mut Vec<Bytes>) -> Result<bool>
pub fn try_recv_into(&mut self, out: &mut Vec<Bytes>) -> Result<bool>
Try to receive a message into a caller-provided buffer without a kernel read.
The allocation-free counterpart to try_recv: returns
Ok(true) with the frames moved into out (reusing its capacity) when a
complete message is already buffered, or Ok(false) leaving out untouched
when none is. Use it with recv_into to drain a burst
from one kernel read without allocating per message.
Sourcepub async fn recv_batch(&mut self) -> Result<Option<Vec<Vec<Bytes>>>>
pub async fn recv_batch(&mut self) -> Result<Option<Vec<Vec<Bytes>>>>
Receive a batch of messages with a single .await.
Blocks until at least one message is available, then drains every further
message already decoded from the same kernel read. Returning a burst of
small messages from one .await amortizes per-await overhead; it is the
receive-side counterpart to PushSocket::send_batch.
Sourcepub fn monitor(&mut self) -> SocketMonitor
pub fn monitor(&mut self) -> SocketMonitor
Enable monitoring for this socket.
Sourcepub fn options_mut(&mut self) -> &mut SocketOptions
pub fn options_mut(&mut self) -> &mut SocketOptions
Get a mutable reference to this socket’s options.
Source§impl PullSocket<UnixStream>
impl PullSocket<UnixStream>
Sourcepub async fn from_unix_stream(stream: UnixStream) -> Result<Self>
pub async fn from_unix_stream(stream: UnixStream) -> Result<Self>
Create a PULL socket from a Unix domain socket stream (IPC).
Sourcepub async fn from_unix_stream_with_options(
stream: UnixStream,
options: SocketOptions,
) -> Result<Self>
pub async fn from_unix_stream_with_options( stream: UnixStream, options: SocketOptions, ) -> Result<Self>
Create a PULL socket from a Unix domain socket stream with custom options.
Auto Trait Implementations§
impl<S = TcpStream> !Freeze for PullSocket<S>
impl<S> RefUnwindSafe for PullSocket<S>where
S: RefUnwindSafe,
impl<S> Send for PullSocket<S>where
S: Send,
impl<S> Sync for PullSocket<S>where
S: Sync,
impl<S> Unpin for PullSocket<S>
impl<S> UnsafeUnpin for PullSocket<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for PullSocket<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