[][src]Struct zmq::Socket

pub struct Socket { /* fields omitted */ }

A socket, the central object in 0MQ.

Methods

impl Socket[src]

pub fn into_raw(self) -> *mut c_void[src]

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.

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

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.

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

Return the inner pointer to this Socket.

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

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

Accept connections on a socket.

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

Connect a socket.

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

Disconnect a previously connected socket

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

Configure the socket for monitoring

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

Send a message.

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

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

Deprecated since 0.9.0:

Use send instead

Send a Message message.

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

Deprecated since 0.9.0:

Use send instead

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

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

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

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

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.

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

Receive a message into a fresh Message.

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

Receive a message as a byte vector.

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

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.

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

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.

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

Accessor for the ZMQ_IPV6 option.

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

Accessor for the ZMQ_IPV6 option.

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

Accessor for the ZMQ_IMMEDIATE option.

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

Accessor for the ZMQ_IMMEDIATE option.

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

Accessor for the ZMQ_PLAIN_SERVER option.

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

Accessor for the ZMQ_PLAIN_SERVER option.

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

Accessor for the ZMQ_CONFLATE option.

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

Accessor for the ZMQ_CONFLATE option.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Return the type of this socket.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.

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

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.

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

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.

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

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

pub fn as_poll_item(&self, events: PollEvents) -> PollItem[src]

Create a PollItem from the socket.

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

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

impl Send for Socket[src]

impl Drop for Socket[src]

Auto Trait Implementations

impl Unpin for Socket

impl !Sync for Socket

impl UnwindSafe for Socket

impl RefUnwindSafe for Socket

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]