Skip to main content

PullSocket

Struct PullSocket 

Source
pub struct PullSocket<S = TcpStream>
where S: AsyncRead + AsyncWrite + Unpin,
{ /* private fields */ }
Expand description

PULL socket for receiving messages in a pipeline.

PULL sockets receive messages from connected PUSH sockets, providing the worker side of the pipeline pattern.

Implementations§

Source§

impl<S> PullSocket<S>
where S: AsyncRead + AsyncWrite + Unpin,

Source

pub async fn new(stream: S) -> Result<Self>

Create a new PULL socket from a stream with default buffer configuration.

Source

pub async fn with_options(stream: S, options: SocketOptions) -> Result<Self>

Create a new PULL socket with custom buffer configuration and socket options.

Source

pub fn try_recv(&mut self) -> Result<Option<Vec<Bytes>>>

Try to receive a message from the already-buffered input without doing a kernel read.

Decodes from bytes already present in the receive buffer. Returns Ok(None) immediately when the buffer is empty rather than suspending. Use this after recv() to drain all messages from a single read batch before returning to the io_uring submission loop:

// One kernel read may deliver many messages - drain them all before
// going back to the event loop.
if let Some(first) = pull.recv().await? {
    process(first);
    while let Some(msg) = pull.try_recv()? {
        process(msg);
    }
}

When a PING heartbeat command is decoded the corresponding PONG is queued in the send buffer; the next recv() call flushes it. For pure pipeline throughput benchmarks (where heartbeats are inactive) this is never triggered.

Source

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: on a complete message the frames are moved into out (reusing its capacity) and Ok(true) is returned; when no complete message is buffered it returns Ok(false) and leaves out untouched. Partial frames stay in the socket’s accumulator, so it interleaves correctly with recv_into for multipart messages split across reads.

Source

pub async fn recv(&mut self) -> Result<Option<Vec<Bytes>>>

Receive a message from a connected PUSH socket.

When multiple PUSH sockets are connected, messages are received in a fair-queued manner (in a multi-connection scenario).

Returns Ok(Some(msg)) if a message was received, Ok(None) if the connection was closed, or an error.

Source

pub async fn recv_into(&mut self, out: &mut Vec<Bytes>) -> Result<bool>

Receive a message into a caller-provided buffer, reusing its allocation.

Identical to recv except the message frames are pushed straight into out instead of a freshly allocated Vec. The caller keeps one Vec and passes it on every call, so a steady recv loop performs no per-message heap allocation (the dominant per-message cost at small message sizes). out is cleared on entry.

Returns Ok(true) when a complete message was read into out, Ok(false) when the connection was closed.

Source

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 (like recv), then drains every further message already decoded from the same kernel read(s) without suspending again. One read frequently delivers many small messages; returning them all from one .await amortizes the per-await overhead that becomes a real fraction of the budget at multi-million-msg/s rates. It is the receive-side counterpart to PushSocket::send_batch.

Returns Ok(Some(batch)) with one or more messages (in arrival order), or Ok(None) if the connection was closed before any message arrived.

Source

pub async fn close(self) -> Result<()>

Close the socket gracefully by shutting down the underlying stream.

Source

pub const fn options(&self) -> &SocketOptions

Get a reference to the socket options.

Source

pub fn options_mut(&mut self) -> &mut SocketOptions

Get a mutable reference to the socket options.

Source

pub fn set_options(&mut self, options: SocketOptions)

Set socket options (builder-style).

Source§

impl PullSocket<TcpStream>

Source

pub async fn from_tcp(stream: TcpStream) -> Result<Self>

Create a new PULL socket from a TCP stream with TCP_NODELAY enabled.

Source

pub async fn from_tcp_with_options( stream: TcpStream, options: SocketOptions, ) -> Result<Self>

Create a new PULL socket from a TCP stream with TCP_NODELAY and custom options.

Source

pub async fn connect(addr: impl ToSocketAddrs) -> Result<Self>

Connect to a remote PULL socket, storing the endpoint for automatic reconnection.

Source

pub async fn connect_with_options( addr: impl ToSocketAddrs, options: SocketOptions, ) -> Result<Self>

Connect with custom options, storing the endpoint for reconnection.

Source

pub fn is_connected(&self) -> bool

Check if the socket is currently connected.

Source

pub async fn try_reconnect(&mut self) -> Result<()>

Try to reconnect to the stored endpoint.

Source

pub async fn recv_with_reconnect(&mut self) -> Result<Option<Vec<Bytes>>>

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.

Trait Implementations§

Source§

impl ProxySocket for PullSocket

Source§

async fn recv_multipart(&mut self) -> Result<Option<Vec<Bytes>>>

Receive a multipart message from the socket. Read more
Source§

async fn send_multipart(&mut self, _msg: Vec<Bytes>) -> Result<()>

Send a multipart message to the socket. Read more
Source§

fn socket_desc(&self) -> &'static str

Get a description of the socket for logging.
Source§

impl<S> Socket for PullSocket<S>
where S: AsyncRead + AsyncWrite + Unpin + 'static,

Source§

async fn send(&mut self, _msg: Vec<Bytes>) -> Result<()>

Send a multipart message on the socket. Read more
Source§

async fn recv(&mut self) -> Result<Option<Vec<Bytes>>>

Receive a multipart message from the socket. Read more
Source§

fn socket_type(&self) -> SocketType

Get the socket type. Read more
Source§

fn has_more(&self) -> bool

Check if socket has more message frames pending. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more