zmq

Struct Socket

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

A socket, the central object in 0MQ.

Implementations§

Source§

impl Socket

Source

pub fn into_raw(self) -> *mut c_void

Consume the Socket and return the raw socket pointer.

Failure to close the raw socket manually or call from_raw will lead to a memory leak. Also note that is function relinquishes the reference on the context is was created from.

Source

pub unsafe fn from_raw(sock: *mut c_void) -> Socket

Create a Socket from a raw socket pointer.

The Socket assumes ownership of the pointer and will close the socket when it is dropped. The returned socket will not reference any context.

§Safety

The socket pointer must be a socket created via the into_raw method. The ownership of the socket is transferred the returned Socket, so any other pointers to the same socket may only be used until it is dropped.

Source

pub fn as_mut_ptr(&mut self) -> *mut c_void

Return the inner pointer to this Socket.

WARNING: It is your responsibility to make sure that the underlying memory is not freed too early.

Source

pub fn bind(&self, endpoint: &str) -> Result<()>

Accept connections on a socket.

Source

pub fn unbind(&self, endpoint: &str) -> Result<()>

Stop accepting connections on a socket

Source

pub fn connect(&self, endpoint: &str) -> Result<()>

Connect a socket.

Source

pub fn disconnect(&self, endpoint: &str) -> Result<()>

Disconnect a previously connected socket

Source

pub fn monitor(&self, monitor_endpoint: &str, events: i32) -> Result<()>

Configure the socket for monitoring

Source

pub fn send<T>(&self, data: T, flags: i32) -> Result<()>
where T: Sendable,

Send a message.

Due to the provided From implementations, this works for &[u8], Vec<u8> and &str Message itself.

Source

pub fn send_msg(&self, msg: Message, flags: i32) -> Result<()>

👎Deprecated since 0.9.0: Use send instead

Send a Message message.

Source

pub fn send_str(&self, data: &str, flags: i32) -> Result<()>

👎Deprecated since 0.9.0: Use send instead
Source

pub fn send_multipart<I, T>(&self, iter: I, flags: i32) -> Result<()>
where I: IntoIterator<Item = T>, T: Into<Message>,

Source

pub fn recv(&self, msg: &mut Message, flags: i32) -> Result<()>

Receive a message into a Message. The length passed to zmq_msg_recv is the length of the buffer.

Source

pub fn recv_into(&self, bytes: &mut [u8], flags: i32) -> Result<usize>

Receive bytes into a slice. The length passed to zmq_recv is the length of the slice. The return value is the number of bytes in the message, which may be larger than the length of the slice, indicating truncation.

Source

pub fn recv_msg(&self, flags: i32) -> Result<Message>

Receive a message into a fresh Message.

Source

pub fn recv_bytes(&self, flags: i32) -> Result<Vec<u8>>

Receive a message as a byte vector.

Source

pub fn recv_string(&self, flags: i32) -> Result<Result<String, Vec<u8>>>

Receive a String from the socket.

If the received message is not valid UTF-8, it is returned as the original Vec in the Err part of the inner result.

Source

pub fn recv_multipart(&self, flags: i32) -> Result<Vec<Vec<u8>>>

Receive a multipart message from the socket.

Note that this will allocate a new vector for each message part; for many applications it will be possible to process the different parts sequentially and reuse allocations that way.

Source

pub fn is_ipv6(&self) -> Result<bool>

Accessor for the ZMQ_IPV6 option.

Source

pub fn set_ipv6(&self, value: bool) -> Result<()>

Accessor for the ZMQ_IPV6 option.

Source

pub fn is_immediate(&self) -> Result<bool>

Accessor for the ZMQ_IMMEDIATE option.

Source

pub fn set_immediate(&self, value: bool) -> Result<()>

Accessor for the ZMQ_IMMEDIATE option.

Source

pub fn is_plain_server(&self) -> Result<bool>

Accessor for the ZMQ_PLAIN_SERVER option.

Source

pub fn set_plain_server(&self, value: bool) -> Result<()>

Accessor for the ZMQ_PLAIN_SERVER option.

Source

pub fn is_conflate(&self) -> Result<bool>

Accessor for the ZMQ_CONFLATE option.

Source

pub fn set_conflate(&self, value: bool) -> Result<()>

Accessor for the ZMQ_CONFLATE option.

Source

pub fn is_probe_router(&self) -> Result<bool>

Source

pub fn set_probe_router(&self, value: bool) -> Result<()>

Source

pub fn is_router_mandatory(&self) -> Result<bool>

Source

pub fn set_router_mandatory(&self, value: bool) -> Result<()>

Source

pub fn is_router_handover(&self) -> Result<bool>

Source

pub fn set_router_handover(&self, value: bool) -> Result<()>

Source

pub fn is_curve_server(&self) -> Result<bool>

Source

pub fn set_curve_server(&self, value: bool) -> Result<()>

Source

pub fn is_gssapi_server(&self) -> Result<bool>

Source

pub fn set_gssapi_server(&self, value: bool) -> Result<()>

Source

pub fn is_gssapi_plaintext(&self) -> Result<bool>

Source

pub fn set_gssapi_plaintext(&self, value: bool) -> Result<()>

Source

pub fn set_req_relaxed(&self, value: bool) -> Result<()>

Source

pub fn set_req_correlate(&self, value: bool) -> Result<()>

Source

pub fn get_socket_type(&self) -> Result<SocketType>

Return the type of this socket.

Source

pub fn get_rcvmore(&self) -> Result<bool>

Return true if there are more frames of a multipart message to receive.

Source

pub fn get_maxmsgsize(&self) -> Result<i64>

Source

pub fn set_maxmsgsize(&self, value: i64) -> Result<()>

Source

pub fn get_sndhwm(&self) -> Result<i32>

Source

pub fn set_sndhwm(&self, value: i32) -> Result<()>

Source

pub fn get_rcvhwm(&self) -> Result<i32>

Source

pub fn set_rcvhwm(&self, value: i32) -> Result<()>

Source

pub fn get_affinity(&self) -> Result<u64>

Source

pub fn set_affinity(&self, value: u64) -> Result<()>

Source

pub fn get_rate(&self) -> Result<i32>

Source

pub fn set_rate(&self, value: i32) -> Result<()>

Source

pub fn get_recovery_ivl(&self) -> Result<i32>

Source

pub fn set_recovery_ivl(&self, value: i32) -> Result<()>

Source

pub fn get_sndbuf(&self) -> Result<i32>

Source

pub fn set_sndbuf(&self, value: i32) -> Result<()>

Source

pub fn get_rcvbuf(&self) -> Result<i32>

Source

pub fn set_rcvbuf(&self, value: i32) -> Result<()>

Source

pub fn get_tos(&self) -> Result<i32>

Source

pub fn set_tos(&self, value: i32) -> Result<()>

Source

pub fn get_linger(&self) -> Result<i32>

Source

pub fn set_linger(&self, value: i32) -> Result<()>

Source

pub fn get_reconnect_ivl(&self) -> Result<i32>

Source

pub fn set_reconnect_ivl(&self, value: i32) -> Result<()>

Source

pub fn get_reconnect_ivl_max(&self) -> Result<i32>

Source

pub fn set_reconnect_ivl_max(&self, value: i32) -> Result<()>

Source

pub fn get_backlog(&self) -> Result<i32>

Source

pub fn set_backlog(&self, value: i32) -> Result<()>

Source

pub fn get_fd(&self) -> Result<RawFd>

Get the event notification file descriptor.

Getter for the ZMQ_FD option. Note that the returned type is platform-specific; it aliases either std::os::unix::io::RawFd and or std::os::windows::io::RawSocket.

Note that the returned file desciptor has special semantics: it should only used with an operating system facility like Unix poll() to check its readability.

Source

pub fn get_events(&self) -> Result<PollEvents>

Get the currently pending events.

Note that the result of this function can also change due to receiving or sending a message on the socket, without the signalling FD (see Socket::get_fd()).

§Examples
use zmq;
let ctx = zmq::Context::new();
let socket = ctx.socket(zmq::REQ).unwrap();
let events = socket.get_events().unwrap();
if events.contains(zmq::POLLIN) {
  println!("socket readable")
}
drop(socket);
§Compatibility

This function currently returns the bitmask as an i32 for backwards compatibility; in effect it should have been using the same type as PollItem::get_revents() all along.

In the 0.9 series, this will be rectified.

Source

pub fn get_multicast_hops(&self) -> Result<i32>

Source

pub fn set_multicast_hops(&self, value: i32) -> Result<()>

Source

pub fn get_rcvtimeo(&self) -> Result<i32>

Source

pub fn set_rcvtimeo(&self, value: i32) -> Result<()>

Source

pub fn get_sndtimeo(&self) -> Result<i32>

Source

pub fn set_sndtimeo(&self, value: i32) -> Result<()>

Source

pub fn get_tcp_keepalive(&self) -> Result<i32>

Source

pub fn set_tcp_keepalive(&self, value: i32) -> Result<()>

Source

pub fn get_tcp_keepalive_cnt(&self) -> Result<i32>

Source

pub fn set_tcp_keepalive_cnt(&self, value: i32) -> Result<()>

Source

pub fn get_tcp_keepalive_idle(&self) -> Result<i32>

Source

pub fn set_tcp_keepalive_idle(&self, value: i32) -> Result<()>

Source

pub fn get_tcp_keepalive_intvl(&self) -> Result<i32>

Source

pub fn set_tcp_keepalive_intvl(&self, value: i32) -> Result<()>

Source

pub fn get_handshake_ivl(&self) -> Result<i32>

Source

pub fn set_handshake_ivl(&self, value: i32) -> Result<()>

Source

pub fn set_identity(&self, value: &[u8]) -> Result<()>

Source

pub fn set_subscribe(&self, value: &[u8]) -> Result<()>

Source

pub fn set_unsubscribe(&self, value: &[u8]) -> Result<()>

Source

pub fn get_heartbeat_ivl(&self) -> Result<i32>

Source

pub fn set_heartbeat_ivl(&self, value: i32) -> Result<()>

Source

pub fn get_heartbeat_ttl(&self) -> Result<i32>

Source

pub fn set_heartbeat_ttl(&self, value: i32) -> Result<()>

Source

pub fn get_heartbeat_timeout(&self) -> Result<i32>

Source

pub fn set_heartbeat_timeout(&self, value: i32) -> Result<()>

Source

pub fn get_connect_timeout(&self) -> Result<i32>

Source

pub fn set_connect_timeout(&self, value: i32) -> Result<()>

Source

pub fn get_identity(&self) -> Result<Vec<u8>>

Source

pub fn get_socks_proxy(&self) -> Result<Result<String, Vec<u8>>>

Source

pub fn get_mechanism(&self) -> Result<Mechanism>

Source

pub fn get_plain_username(&self) -> Result<Result<String, Vec<u8>>>

Source

pub fn get_plain_password(&self) -> Result<Result<String, Vec<u8>>>

Source

pub fn get_zap_domain(&self) -> Result<Result<String, Vec<u8>>>

Source

pub fn get_last_endpoint(&self) -> Result<Result<String, Vec<u8>>>

Return the address of the last endpoint this socket was bound to.

Note that the returned address is not guaranteed to be the same as the one used with bind, and might also not be directly usable with connect. In particular, when bind is used with the wildcard address ("*"), in the address returned, the wildcard will be expanded into the any address (i.e. 0.0.0.0 with IPv4).

Source

pub fn get_curve_publickey(&self) -> Result<Vec<u8>>

Set the ZMQ_CURVE_PUBLICKEY option value.

The key is returned as raw bytes. Use z85_encode on the resulting data to get the Z85-encoded string representation of the key.

Source

pub fn get_curve_secretkey(&self) -> Result<Vec<u8>>

Get the ZMQ_CURVE_SECRETKEY option value.

The key is returned as raw bytes. Use z85_encode on the resulting data to get the Z85-encoded string representation of the key.

Source

pub fn get_curve_serverkey(&self) -> Result<Vec<u8>>

Get ZMQ_CURVE_SERVERKEY option value.

Note that the key is returned as raw bytes, as a 32-byte vector. Use z85_encode() explicitly to obtain the Z85-encoded string variant.

Source

pub fn get_gssapi_principal(&self) -> Result<Result<String, Vec<u8>>>

Source

pub fn get_gssapi_service_principal(&self) -> Result<Result<String, Vec<u8>>>

Source

pub fn set_socks_proxy(&self, value: Option<&str>) -> Result<()>

Source

pub fn set_plain_username(&self, value: Option<&str>) -> Result<()>

Source

pub fn set_plain_password(&self, value: Option<&str>) -> Result<()>

Source

pub fn set_zap_domain(&self, value: &str) -> Result<()>

Source

pub fn set_xpub_welcome_msg(&self, value: Option<&str>) -> Result<()>

Source

pub fn set_xpub_verbose(&self, value: bool) -> Result<()>

Source

pub fn set_curve_publickey(&self, value: &[u8]) -> Result<()>

Source

pub fn set_curve_secretkey(&self, value: &[u8]) -> Result<()>

Source

pub fn set_curve_serverkey(&self, value: &[u8]) -> Result<()>

Source

pub fn set_gssapi_principal(&self, value: &str) -> Result<()>

Source

pub fn set_gssapi_service_principal(&self, value: &str) -> Result<()>

Source

pub fn as_poll_item(&self, events: PollEvents) -> PollItem<'_>

Create a PollItem from the socket.

Source

pub fn poll(&self, events: PollEvents, timeout_ms: i64) -> Result<i32>

Do a call to zmq_poll with only this socket.

The return value on success will be either zero (no event) or one (some event was signaled).

Trait Implementations§

Source§

impl AsRawFd for Socket

Source§

fn as_raw_fd(&self) -> UnixRawFd

Extracts the raw file descriptor. Read more
Source§

impl Drop for Socket

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Socket

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> 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, 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.