[][src]Trait libzmq::prelude::Socket

pub trait Socket: GetRawSocket {
    fn connect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>>
    where
        I: IntoIterator<Item = E>,
        E: Into<Endpoint>
, { ... }
fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>>
    where
        I: IntoIterator<Item = E>,
        E: Into<Endpoint>
, { ... }
fn bind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>>
    where
        I: IntoIterator<Item = E>,
        E: Into<Endpoint>
, { ... }
fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>>
    where
        I: IntoIterator<Item = E>,
        E: Into<Endpoint>
, { ... }
fn last_endpoint(&self) -> Result<Option<Endpoint>, Error> { ... }
fn mechanism(&self) -> Mechanism { ... }
fn set_mechanism<M>(&self, mechanism: M) -> Result<(), Error>
    where
        M: Into<Mechanism>
, { ... }
fn heartbeat(&self) -> Option<Heartbeat> { ... }
fn set_heartbeat(&self, maybe: Option<Heartbeat>) -> Result<(), Error> { ... } }

Methods shared by all thread-safe sockets.

Provided methods

fn connect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 

Schedules a connection to one or more Endpoints and then accepts incoming connections.

Since ØMQ handles all connections behind the curtain, one cannot know exactly when the connection is truly established a blocking send or recv call is made on that connection.

When any of the connection attempt fail, the Error will contain the position of the iterator before the failure. This represents the number of connections that succeeded before the failure.

See zmq_connect.

Usage Contract

  • The endpoint(s) must be valid (Endpoint does not do any validation atm).
  • The endpoint's protocol must be supported by the socket.

Returned Errors

fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 

Disconnect the socket from one or more Endpoints.

Any outstanding messages physically received from the network but not yet received by the application are discarded.

When any of the connection attempt fail, the Error will contain the position of the iterator before the failure. This represents the number of disconnections that succeeded before the failure.

See zmq_disconnect.

Usage Contract

  • The endpoint must be valid (Endpoint does not do any validation atm).
  • The endpoint must be already connected to.

Returned Errors

fn bind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 

Schedules a bind to one or more Endpoints and then accepts incoming connections.

As opposed to connect, the socket will straight await and start accepting connections.

When any of the connection attempt fail, the Error will contain the position of the iterator before the failure. This represents the number of binds that succeeded before the failure.

See zmq_bind.

Usage Contract

  • The endpoint must be valid (Endpoint does not do any validation atm).
  • The transport must be supported by socket type.
  • The endpoint must not be in use.
  • The endpoint must be local.

Returned Errors

fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 

Unbinds the socket from one or more Endpoints.

Any outstanding messages physically received from the network but not yet received by the application are discarded.

See zmq_unbind.

When any of the connection attempt fail, the Error will contain the position of the iterator before the failure. This represents the number of unbinds that succeeded before the failure.

When a socket is dropped, it is unbound from all its associated endpoints so that they become available for binding immediately.

Usage Contract

  • The endpoint must be valid (Endpoint does not do any validation atm).
  • The endpoint must be currently bound.

Returned Errors

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

Retrieve the last endpoint connected or bound to.

This is the only way to retreive the value of a bound Dynamic port.

Example

use libzmq::{prelude::*, Server, TcpAddr, addr::Endpoint};
use std::convert::TryInto;

// We create a tcp addr with an unspecified port.
// This port will be assigned by the OS upon connection.
let addr: TcpAddr = "127.0.0.1:*".try_into()?;
assert!(addr.host().port().is_unspecified());

let server = Server::new()?;
assert!(server.last_endpoint()?.is_none());

server.bind(&addr)?;

if let Endpoint::Tcp(tcp) = server.last_endpoint()?.unwrap() {
    // The port was indeed assigned by the OS.
    assert!(tcp.host().port().is_specified());
} else {
    unreachable!();
}

fn mechanism(&self) -> Mechanism

Returns the socket's Mechanism.

Example

use libzmq::{prelude::*, Server, auth::Mechanism};

let server = Server::new()?;
assert_eq!(server.mechanism(), Mechanism::Null);

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

Set the socket's Mechanism.

Example

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

let client = Client::new()?;
assert_eq!(client.mechanism(), Mechanism::Null);

let server_cert = CurveCert::new_unique();
// We do not specify a client certificate, so it
// will be automatically generated.
let creds = CurveClientCreds::new(server_cert.public());

client.set_mechanism(&creds)?;

if let Mechanism::CurveClient(creds) = client.mechanism() {
    assert_eq!(creds.server(), server_cert.public());
    assert!(creds.cert().is_some());
} else {
    unreachable!()
}

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

Returns a the socket's heartbeat configuration.

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

Set the socket's heartbeat configuration.

Only applies to connection based transports such as TCP. A value of None means no heartbeating.

Contract

  • timeout and interval duration in ms cannot exceed i32::MAX
  • ttl duration in ms cannot exceed 6553599

Default value

None

Return Errors

Example

use libzmq::{prelude::*, Client, Heartbeat, auth::*};
use std::time::Duration;

let client = Client::new()?;
assert_eq!(client.heartbeat(), None);

let duration = Duration::from_millis(300);
let hb = Heartbeat::new(duration)
    .add_timeout(2 * duration);
let expected = hb.clone();

client.set_heartbeat(Some(hb))?;
assert_eq!(client.heartbeat(), Some(expected));
Loading content...

Implementors

impl Socket for Client[src]

fn connect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn bind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn last_endpoint(&self) -> Result<Option<Endpoint>, Error>[src]

fn mechanism(&self) -> Mechanism[src]

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

fn heartbeat(&self) -> Option<Heartbeat>[src]

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

impl Socket for Dish[src]

fn connect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn bind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn last_endpoint(&self) -> Result<Option<Endpoint>, Error>[src]

fn mechanism(&self) -> Mechanism[src]

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

fn heartbeat(&self) -> Option<Heartbeat>[src]

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

impl Socket for Gather[src]

fn connect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn bind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn last_endpoint(&self) -> Result<Option<Endpoint>, Error>[src]

fn mechanism(&self) -> Mechanism[src]

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

fn heartbeat(&self) -> Option<Heartbeat>[src]

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

impl Socket for Radio[src]

fn connect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn bind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn last_endpoint(&self) -> Result<Option<Endpoint>, Error>[src]

fn mechanism(&self) -> Mechanism[src]

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

fn heartbeat(&self) -> Option<Heartbeat>[src]

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

impl Socket for Scatter[src]

fn connect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn bind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn last_endpoint(&self) -> Result<Option<Endpoint>, Error>[src]

fn mechanism(&self) -> Mechanism[src]

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

fn heartbeat(&self) -> Option<Heartbeat>[src]

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

impl Socket for Server[src]

fn connect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn bind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
    I: IntoIterator<Item = E>,
    E: Into<Endpoint>, 
[src]

fn last_endpoint(&self) -> Result<Option<Endpoint>, Error>[src]

fn mechanism(&self) -> Mechanism[src]

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

fn heartbeat(&self) -> Option<Heartbeat>[src]

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

Loading content...