Skip to main content

PushSocket

Struct PushSocket 

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

PUSH socket for distributing messages in a pipeline.

PUSH sockets send messages to connected PULL sockets in a round-robin fashion, providing load balancing for parallel processing.

Implementations§

Source§

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

Source

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

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

Source

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

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

Source

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

Send a message to a connected PULL socket.

Messages are distributed in a round-robin fashion when multiple PULL sockets are connected (in a multi-connection scenario).

By default each call writes to the kernel immediately (eager mode, one io_uring operation per message). For throughput-bound pipelines, enable write coalescing via SocketOptions::with_write_coalescing and call flush after the last send in each burst. In coalesced mode, bytes may remain in userspace until the 64 KB threshold fills or flush() is called explicitly.

§Errors

Returns an error if the socket is poisoned, disconnected, or if the write fails.

Source

pub async fn send_one(&mut self, frame: Bytes) -> Result<()>

Send a single-frame message without allocating a one-element Vec.

This is equivalent to send(vec![frame]), but keeps the hot path for single-frame PUSH/PULL pipelines from measuring the caller’s multipart container allocation.

Source

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

Flush any messages still buffered by write coalescing.

Call this after the last send() in a burst when write_coalescing is enabled to ensure all pending data is written to the kernel.

Source

pub async fn send_batch<I>(&mut self, msgs: I) -> Result<usize>
where I: IntoIterator<Item = Vec<Bytes>>,

Encode and send a batch of messages in a single kernel write.

Encodes every message in msgs into the send buffer, then flushes once. This gives the same kernel-call efficiency as write coalescing but with explicit batch boundaries - no threshold check and no flush() required.

Works independently of the write_coalescing option and can be mixed with send() calls freely.

Returns the number of messages sent.

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 PushSocket<TcpStream>

Source

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

Create a new PUSH 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 PUSH 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 PUSH 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 send_with_reconnect(&mut self, msg: Vec<Bytes>) -> Result<()>

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.

Trait Implementations§

Source§

impl ProxySocket for PushSocket

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 PushSocket<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 PushSocket<S>

§

impl<S> RefUnwindSafe for PushSocket<S>
where S: RefUnwindSafe,

§

impl<S> Send for PushSocket<S>
where S: Send,

§

impl<S> Sync for PushSocket<S>
where S: Sync,

§

impl<S> Unpin for PushSocket<S>

§

impl<S> UnsafeUnpin for PushSocket<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for PushSocket<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