[−][src]Trait libzmq::prelude::Socket
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>,
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.
- The iterator must not be empty.
Returned Errors
InvalidInput
(invalid endpoint or empty iterator)IncompatTransport
(transport not supported)CtxTerminated
fn connected(&self) -> Vec<Endpoint>
Returns a snapshot of the list of connected Endpoint
.
Example
use libzmq::{prelude::*, Client, addr::{InprocAddr, Endpoint}}; use std::convert::TryInto; let addr: InprocAddr = "test".try_into()?; let client = Client::new()?; assert!(client.connected().is_empty()); client.connect(&addr)?; let endpoint = Endpoint::from(&addr); assert!(client.connected().contains((&endpoint).into())); client.disconnect(addr)?; assert!(client.connected().is_empty());
fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
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. The behaviour for
discarding messages depends on the value of linger
.
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.
- The iterator must not be empty.
Returned Errors
InvalidInput
(invalid endpoint or empty iterator)NotFound
(endpoint not connected to)CtxTerminated
fn bind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
Schedules a bind 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
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.
- The iterator must not be empty.
Returned Errors
InvalidInput
(invalid endpoint or empty iterator)IncompatTransport
(transport is not supported)AddrInUse
(addr already in use)AddrNotAvailable
(not local)CtxTerminated
fn bound(&self) -> Vec<Endpoint>
Returns a snapshot of the list of bound Endpoint
.
use libzmq::{prelude::*, Radio, addr::{InprocAddr, Endpoint}}; use std::convert::TryInto; let first: InprocAddr = "test1".try_into()?; let second: InprocAddr = "test2".try_into()?; let radio = Radio::new()?; assert!(radio.bound().is_empty()); radio.bind(vec![&first, &second])?; { let bound = radio.bound(); let first = Endpoint::from(&first); assert!(bound.contains(&first)); let second = Endpoint::from(&second); assert!(bound.contains(&second)); } radio.unbind(&first)?; { let bound = radio.bound(); let first = Endpoint::from(&first); assert!(!bound.contains((&first).into())); let second = Endpoint::from(&second); assert!(bound.contains((&second).into())); }
fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
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. The behaviour for
discarding messages depends on the value of linger
.
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.
- The iterator must not be empty.
Returned Errors
InvalidInput
(invalid endpoint or empty iterator)CtxTerminated
NotFound
(endpoint was not bound to)
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, addr::*}; 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 backlog(&self) -> Result<i32, Error>
Retrieve the maximum length of the queue of outstanding peer connections.
See ZMQ_BLACKLOG
in zmq_getsockopt
.
fn set_backlog(&self, value: i32) -> Result<(), Error>
Set the maximum length of the queue of outstanding peer connections for the specified socket; this only applies to connection-oriented transports.
See ZMQ_BACKLOG
in zmq_setsockopt
.
Default Value
100
Applicable Socket Type
All (Connection Oriented Transports)
fn heartbeat_interval(&self) -> Result<Duration, Error>
The interval between sending ZMTP heartbeats.
fn set_heartbeat_interval(&self, duration: Duration) -> Result<(), Error>
Sets the interval between sending ZMTP PINGs (aka. heartbeats).
Default Value
None
Applicable Socket Type
All (connection oriented transports)
fn heartbeat_timeout(&self) -> Result<Duration, Error>
How long to wait before timing-out a connection after sending a PING ZMTP command and not receiving any traffic.
fn set_heartbeat_timeout(&self, duration: Duration) -> Result<(), Error>
How long to wait before timing-out a connection after sending a PING ZMTP command and not receiving any traffic.
Default Value
0
. If heartbeat_interval
is set, then it uses the same value
by default.
fn heartbeat_ttl(&self) -> Result<Duration, Error>
The timeout on the remote peer for ZMTP heartbeats.
If this option and heartbeat_interval
is not None
the remote
side shall time out the connection if it does not receive any more
traffic within the TTL period.
fn set_heartbeat_ttl(&self, duration: Duration) -> Result<(), Error>
Set timeout on the remote peer for ZMTP heartbeats.
If this option and heartbeat_interval
is not None
the remote
side shall time out the connection if it does not receive any more
traffic within the TTL period.
Default value
None
fn linger(&self) -> Result<Option<Duration>, Error>
Returns the linger period for the socket shutdown.
fn set_linger(&self, maybe: Option<Duration>) -> Result<(), Error>
Sets the linger period for the socket shutdown.
The linger period determines how long pending messages which have yet to be sent to a peer shall linger in memory after a socket is disconnected or dropped.
A value of None
means an infinite period.
Default Value
30 secs
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>,
M: Into<Mechanism>,
Set the socket's Mechanism
.
Example
use libzmq::{prelude::*, Client, auth::{PlainClientCreds, Mechanism}}; let username = "some name".to_owned(); let password = "some password".to_owned(); let creds = PlainClientCreds { username, password, }; let client = Client::new()?; assert_eq!(client.mechanism(), Mechanism::Null); client.set_mechanism(&creds)?; assert_eq!(client.mechanism(), Mechanism::PlainClient(creds));
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]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
fn connected(&self) -> Vec<Endpoint>
[src]
fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
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>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
fn bound(&self) -> Vec<Endpoint>
[src]
fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
fn last_endpoint(&self) -> Result<Option<Endpoint>, Error>
[src]
fn backlog(&self) -> Result<i32, Error>
[src]
fn set_backlog(&self, value: i32) -> Result<(), Error>
[src]
fn heartbeat_interval(&self) -> Result<Duration, Error>
[src]
fn set_heartbeat_interval(&self, duration: Duration) -> Result<(), Error>
[src]
fn heartbeat_timeout(&self) -> Result<Duration, Error>
[src]
fn set_heartbeat_timeout(&self, duration: Duration) -> Result<(), Error>
[src]
fn heartbeat_ttl(&self) -> Result<Duration, Error>
[src]
fn set_heartbeat_ttl(&self, duration: Duration) -> Result<(), Error>
[src]
fn linger(&self) -> Result<Option<Duration>, Error>
[src]
fn set_linger(&self, maybe: Option<Duration>) -> Result<(), Error>
[src]
fn mechanism(&self) -> Mechanism
[src]
fn set_mechanism<M>(&self, mechanism: M) -> Result<(), Error> where
M: Into<Mechanism>,
[src]
M: Into<Mechanism>,
impl Socket for Dish
[src]
fn connect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
fn connected(&self) -> Vec<Endpoint>
[src]
fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
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>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
fn bound(&self) -> Vec<Endpoint>
[src]
fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
fn last_endpoint(&self) -> Result<Option<Endpoint>, Error>
[src]
fn backlog(&self) -> Result<i32, Error>
[src]
fn set_backlog(&self, value: i32) -> Result<(), Error>
[src]
fn heartbeat_interval(&self) -> Result<Duration, Error>
[src]
fn set_heartbeat_interval(&self, duration: Duration) -> Result<(), Error>
[src]
fn heartbeat_timeout(&self) -> Result<Duration, Error>
[src]
fn set_heartbeat_timeout(&self, duration: Duration) -> Result<(), Error>
[src]
fn heartbeat_ttl(&self) -> Result<Duration, Error>
[src]
fn set_heartbeat_ttl(&self, duration: Duration) -> Result<(), Error>
[src]
fn linger(&self) -> Result<Option<Duration>, Error>
[src]
fn set_linger(&self, maybe: Option<Duration>) -> Result<(), Error>
[src]
fn mechanism(&self) -> Mechanism
[src]
fn set_mechanism<M>(&self, mechanism: M) -> Result<(), Error> where
M: Into<Mechanism>,
[src]
M: Into<Mechanism>,
impl Socket for Radio
[src]
fn connect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
fn connected(&self) -> Vec<Endpoint>
[src]
fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
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>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
fn bound(&self) -> Vec<Endpoint>
[src]
fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
fn last_endpoint(&self) -> Result<Option<Endpoint>, Error>
[src]
fn backlog(&self) -> Result<i32, Error>
[src]
fn set_backlog(&self, value: i32) -> Result<(), Error>
[src]
fn heartbeat_interval(&self) -> Result<Duration, Error>
[src]
fn set_heartbeat_interval(&self, duration: Duration) -> Result<(), Error>
[src]
fn heartbeat_timeout(&self) -> Result<Duration, Error>
[src]
fn set_heartbeat_timeout(&self, duration: Duration) -> Result<(), Error>
[src]
fn heartbeat_ttl(&self) -> Result<Duration, Error>
[src]
fn set_heartbeat_ttl(&self, duration: Duration) -> Result<(), Error>
[src]
fn linger(&self) -> Result<Option<Duration>, Error>
[src]
fn set_linger(&self, maybe: Option<Duration>) -> Result<(), Error>
[src]
fn mechanism(&self) -> Mechanism
[src]
fn set_mechanism<M>(&self, mechanism: M) -> Result<(), Error> where
M: Into<Mechanism>,
[src]
M: Into<Mechanism>,
impl Socket for Server
[src]
fn connect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
fn connected(&self) -> Vec<Endpoint>
[src]
fn disconnect<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
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>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
fn bound(&self) -> Vec<Endpoint>
[src]
fn unbind<I, E>(&self, endpoints: I) -> Result<(), Error<usize>> where
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
[src]
I: IntoIterator<Item = E>,
E: Into<Endpoint>,
fn last_endpoint(&self) -> Result<Option<Endpoint>, Error>
[src]
fn backlog(&self) -> Result<i32, Error>
[src]
fn set_backlog(&self, value: i32) -> Result<(), Error>
[src]
fn heartbeat_interval(&self) -> Result<Duration, Error>
[src]
fn set_heartbeat_interval(&self, duration: Duration) -> Result<(), Error>
[src]
fn heartbeat_timeout(&self) -> Result<Duration, Error>
[src]
fn set_heartbeat_timeout(&self, duration: Duration) -> Result<(), Error>
[src]
fn heartbeat_ttl(&self) -> Result<Duration, Error>
[src]
fn set_heartbeat_ttl(&self, duration: Duration) -> Result<(), Error>
[src]
fn linger(&self) -> Result<Option<Duration>, Error>
[src]
fn set_linger(&self, maybe: Option<Duration>) -> Result<(), Error>
[src]
fn mechanism(&self) -> Mechanism
[src]
fn set_mechanism<M>(&self, mechanism: M) -> Result<(), Error> where
M: Into<Mechanism>,
[src]
M: Into<Mechanism>,