pub struct PushSocket<S = TcpStream>{ /* private fields */ }Expand description
PUSH socket for distributing tasks in a pipeline.
PUSH sockets send messages in a round-robin fashion to connected PULL sockets.
Implementations§
Source§impl PushSocket<TcpStream>
impl PushSocket<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 PUSH socket.
Returns the TcpListener so the caller can accept further PULL connections.
§Example
use monocoque::zmq::PushSocket;
use bytes::Bytes;
let (_listener, mut socket) = PushSocket::bind("127.0.0.1:5555").await?;
socket.send(vec![Bytes::from("task")]).await?;Sourcepub async fn connect(addr: impl ToSocketAddrs) -> Result<Self>
pub async fn connect(addr: impl ToSocketAddrs) -> Result<Self>
Connect to a PULL socket at addr.
§Example
use monocoque::zmq::PushSocket;
use bytes::Bytes;
let mut socket = PushSocket::connect("127.0.0.1:5555").await?;
socket.send(vec![Bytes::from("task")]).await?;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 send_with_reconnect(&mut self, msg: Vec<Bytes>) -> Result<()>
pub async fn send_with_reconnect(&mut self, msg: Vec<Bytes>) -> Result<()>
Send with automatic reconnection on network error.
Sourcepub async fn from_tcp(stream: TcpStream) -> Result<Self>
pub async fn from_tcp(stream: TcpStream) -> Result<Self>
Create a PUSH 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 PUSH socket from a TCP stream with custom options.
Source§impl<S> PushSocket<S>
impl<S> PushSocket<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 PUSH socket from any stream with custom options.
Sourcepub async fn send(&mut self, msg: Vec<Bytes>) -> Result<()>
pub async fn send(&mut self, msg: Vec<Bytes>) -> Result<()>
Send a message.
By default each call writes to the kernel immediately (eager mode). For
throughput-bound pipelines, enable write coalescing via
SocketOptions::with_write_coalescing and call flush after
the last send in each burst. See docs/performance.md for measured numbers and
an explanation of when each mode is appropriate.
Sourcepub async fn send_one(&mut self, frame: Bytes) -> Result<()>
pub async fn send_one(&mut self, frame: Bytes) -> Result<()>
Send a single-frame message without allocating a multipart Vec.
Equivalent to send(vec![frame]), but avoids the per-message container
allocation in single-frame hot paths.
Sourcepub async fn flush(&mut self) -> Result<()>
pub async fn flush(&mut self) -> Result<()>
Flush any messages still buffered by write coalescing.
Required after the last send() in a burst when write_coalescing is enabled.
In coalesced mode, bytes accumulate in a userspace buffer and are not guaranteed
to reach the peer until this is called (or the 64 KB threshold fills naturally).
Has no effect in eager mode (the default).
Sourcepub async fn send_batch<I>(&mut self, msgs: I) -> Result<usize>
pub async fn send_batch<I>(&mut self, msgs: I) -> Result<usize>
Send a batch of messages in a single kernel write.
Encodes all messages into the send buffer and flushes once, regardless of
whether write_coalescing is enabled. Use this when you have a collection
of messages ready to send and want to minimize syscall count without managing
flush() calls manually:
use bytes::Bytes;
let batch: Vec<Vec<Bytes>> = (0..100)
.map(|i| vec![Bytes::from(format!("msg-{i}").into_bytes())])
.collect();
push.send_batch(batch).await?;Returns the number of messages sent.
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 PushSocket<UnixStream>
impl PushSocket<UnixStream>
Sourcepub async fn from_unix_stream(stream: UnixStream) -> Result<Self>
pub async fn from_unix_stream(stream: UnixStream) -> Result<Self>
Create a PUSH 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 PUSH socket from a Unix domain socket stream with custom options.
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> 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