Struct Server

Source
pub struct Server { /* private fields */ }
Expand description

A Server socket is a socket used for advanced request-reply messaging.

A Server socket talks to a set of Client sockets. The Client must first initiate the conversation, which generates a routing_id associated with the connection. Each message received from a Server will have this routing_id. To send messages back to the server, you must associate them to a RoutingId either manually using set_routing_id or via the route convenience method. If the routing_id is not specified, or does not refer to a connected server peer, the send call will fail with HostUnreachable.

§Mute State

When a Server socket enters the mute state due to having reached the high water mark for all servers, or if there are no servers at all, then any send operations on the socket shall block until the mute state ends or at least one downstream node becomes available for sending; messages are not discarded.

§Summary of Characteristics

CharacteristicValue
Compatible peer socketsServer
DirectionBidirectional
PatternUnrestricted
Incoming routing strategyFair-queued
Outgoing routing strategySee text
Action in mute stateBlock

§Example

use libzmq::{prelude::*, *};

let addr: TcpAddr = "127.0.0.1:*".try_into()?;

let server = ServerBuilder::new()
    .bind(addr)
    .build()?;

let bound = server.last_endpoint()?;

let client = ClientBuilder::new()
    .connect(bound)
    .build()?;

// The client initiates the conversation so it is assigned a `routing_id`.
client.send("request")?;
let msg = server.recv_msg()?;
assert_eq!("request", msg.to_str()?);
let id = msg.routing_id().unwrap();

// Using this `routing_id`, we can now route as many replies as we
// want to the client.
server.route("reply 1", id)?;
server.route("reply 2", id)?;

// The `routing_id` is discarted when the message is sent to the client.
let mut msg = client.recv_msg()?;
assert_eq!("reply 1", msg.to_str()?);
assert!(msg.routing_id().is_none());
client.recv(&mut msg)?;
assert_eq!("reply 2", msg.to_str()?);
assert!(msg.routing_id().is_none());

Implementations§

Source§

impl Server

Source

pub fn new() -> Result<Self, Error>

Create a Server socket from the global context

§Returned Error Variants
Source

pub fn with_ctx(handle: CtxHandle) -> Result<Server, Error>

Create a Server socket associated with a specific context from a CtxHandle.

§Returned Error Variants
Source

pub fn ctx(&self) -> CtxHandle

Returns a reference to the context of the socket.

Source

pub fn route<M>(&self, msg: M, id: RoutingId) -> Result<(), Error<Msg>>
where M: Into<Msg>,

Push a message into the outgoing socket queue with the specified RoutingId.

This is a convenience function that sets the Msg’s RoutingId then sends it.

See send for more information.

Source

pub fn try_route<M>(&self, msg: M, id: RoutingId) -> Result<(), Error<Msg>>
where M: Into<Msg>,

Try to push a message into the outgoing socket queue with the specified RoutingId.

This is a convenience function that sets the Msg’s RoutingId then tries sends it.

See try_send for more information.

Trait Implementations§

Source§

impl Clone for Server

Source§

fn clone(&self) -> Server

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Server

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a Server> for Pollable<'a>

Source§

fn from(server: &'a Server) -> Self

Converts to this type from the input type.
Source§

impl Heartbeating for Server

Source§

fn heartbeat(&self) -> Option<Heartbeat>

Returns a the socket’s heartbeating configuration.
Source§

fn set_heartbeat(&self, maybe: Option<Heartbeat>) -> Result<(), Error>

Sets the socket’s heartbeating configuration.
Source§

impl PartialEq for Server

Source§

fn eq(&self, other: &Server) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RecvMsg for Server

Source§

fn recv(&self, msg: &mut Msg) -> Result<(), Error>

Retreive a message from the inbound socket queue. Read more
Source§

fn try_recv(&self, msg: &mut Msg) -> Result<(), Error>

Try to retrieve a message from the inbound socket queue without blocking. Read more
Source§

fn recv_msg(&self) -> Result<Msg, Error>

A convenience function that allocates a Msg with the same properties as recv.
Source§

fn try_recv_msg(&self) -> Result<Msg, Error>

A convenience function that allocates a Msg with the same properties as try_recv.
Source§

fn recv_hwm(&self) -> Result<i32, Error>

The high water mark for incoming messages on the specified socket. Read more
Source§

fn set_recv_hwm(&self, hwm: i32) -> Result<(), Error>

Set the high water mark for inbound messages on the specified socket. Read more
Source§

fn recv_timeout(&self) -> Result<Period, Error>

The timeout for [recv] on the socket. Read more
Source§

fn set_recv_timeout<P>(&self, period: P) -> Result<(), Error>
where P: Into<Period>,

Sets the timeout for [recv] on the socket. Read more
Source§

impl SendMsg for Server

Source§

fn send<M>(&self, msg: M) -> Result<(), Error<Msg>>
where M: Into<Msg>,

Push a message into the outgoing socket queue. Read more
Source§

fn try_send<M>(&self, msg: M) -> Result<(), Error<Msg>>
where M: Into<Msg>,

Try to push a message into the outgoing socket queue without blocking. Read more
Source§

fn send_hwm(&self) -> Result<i32, Error>

The high water mark for outbound messages on the specified socket. Read more
Source§

fn set_send_hwm(&self, hwm: i32) -> Result<(), Error>

Set the high water mark for outbound messages on the specified socket. Read more
Source§

fn send_timeout(&self) -> Result<Period, Error>

Sets the timeout for [send] on the socket. Read more
Source§

fn set_send_timeout<P>(&self, period: P) -> Result<(), Error>
where P: Into<Period>,

Sets the timeout for [send] on the socket. Read more
Source§

impl Socket for Server

Source§

fn connect<E>(&self, endpoint: E) -> Result<(), Error>
where E: Into<Endpoint>,

Schedules a connection to a Endpoint. Read more
Source§

fn bind<E>(&self, endpoint: E) -> Result<(), Error>
where E: Into<Endpoint>,

Schedules a bind to a Endpoint and then accepts incoming connections. Read more
Source§

fn disconnect<E>(&self, endpoint: E) -> Result<(), Error>
where E: Into<Endpoint>,

Disconnect the socket from a Endpoint. Read more
Source§

fn unbind<I, E>(&self, endpoint: E) -> Result<(), Error>
where E: Into<Endpoint>,

Unbind the socket from a Endpoint. Read more
Source§

fn last_endpoint(&self) -> Result<Endpoint, Error>

Retrieve the last endpoint connected or bound to. Read more
Source§

fn mechanism(&self) -> Mechanism

Returns the socket’s Mechanism. Read more
Source§

fn set_mechanism<M>(&self, mechanism: M) -> Result<(), Error>
where M: Into<Mechanism>,

Set the socket’s Mechanism. Read more
Source§

impl Eq for Server

Source§

impl Send for Server

Source§

impl StructuralPartialEq for Server

Source§

impl Sync for Server

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.