Struct zmq::Socket
[−]
[src]
pub struct Socket { /* fields omitted */ }
A socket, the central object in 0MQ.
Methods
impl Socket
[src]
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.
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.
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.
fn bind(&self, endpoint: &str) -> Result<()>
Accept connections on a socket.
fn connect(&self, endpoint: &str) -> Result<()>
Connect a socket.
fn send(&self, data: &[u8], flags: i32) -> Result<()>
Send a &[u8]
message.
fn send_msg(&self, msg: Message, flags: i32) -> Result<()>
Send a Message
message.
fn send_str(&self, data: &str, flags: i32) -> Result<()>
fn send_multipart(&self, parts: &[&[u8]], flags: i32) -> Result<()>
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.
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.
fn recv_msg(&self, flags: i32) -> Result<Message>
Receive a message into a fresh Message
.
fn recv_bytes(&self, flags: i32) -> Result<Vec<u8>>
Receive a message as a byte vector.
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.
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.
fn is_ipv6(&self) -> Result<bool>
Accessor for the ZMQ_IPV6
option.
fn set_ipv6(&self, value: bool) -> Result<()>
Accessor for the ZMQ_IPV6
option.
fn is_immediate(&self) -> Result<bool>
Accessor for the ZMQ_IMMEDIATE
option.
fn set_immediate(&self, value: bool) -> Result<()>
Accessor for the ZMQ_IMMEDIATE
option.
fn is_plain_server(&self) -> Result<bool>
Accessor for the ZMQ_PLAIN_SERVER
option.
fn set_plain_server(&self, value: bool) -> Result<()>
Accessor for the ZMQ_PLAIN_SERVER
option.
fn is_conflate(&self) -> Result<bool>
Accessor for the ZMQ_CONFLATE
option.
fn set_conflate(&self, value: bool) -> Result<()>
Accessor for the ZMQ_CONFLATE
option.
fn is_curve_server(&self) -> Result<bool>
fn set_curve_server(&self, value: bool) -> Result<()>
fn get_socket_type(&self) -> Result<SocketType>
Return the type of this socket.
fn get_rcvmore(&self) -> Result<bool>
Return true if there are more frames of a multipart message to receive.
fn get_maxmsgsize(&self) -> Result<i64>
fn set_maxmsgsize(&self, value: i64) -> Result<()>
fn get_sndhwm(&self) -> Result<i32>
fn set_sndhwm(&self, value: i32) -> Result<()>
fn get_rcvhwm(&self) -> Result<i32>
fn set_rcvhwm(&self, value: i32) -> Result<()>
fn get_affinity(&self) -> Result<u64>
fn set_affinity(&self, value: u64) -> Result<()>
fn get_rate(&self) -> Result<i32>
fn set_rate(&self, value: i32) -> Result<()>
fn get_recovery_ivl(&self) -> Result<i32>
fn set_recovery_ivl(&self, value: i32) -> Result<()>
fn get_sndbuf(&self) -> Result<i32>
fn set_sndbuf(&self, value: i32) -> Result<()>
fn get_rcvbuf(&self) -> Result<i32>
fn set_rcvbuf(&self, value: i32) -> Result<()>
fn get_tos(&self) -> Result<i32>
fn set_tos(&self, value: i32) -> Result<()>
fn get_linger(&self) -> Result<i32>
fn set_linger(&self, value: i32) -> Result<()>
fn get_reconnect_ivl(&self) -> Result<i32>
fn set_reconnect_ivl(&self, value: i32) -> Result<()>
fn get_reconnect_ivl_max(&self) -> Result<i32>
fn set_reconnect_ivl_max(&self, value: i32) -> Result<()>
fn get_backlog(&self) -> Result<i32>
fn set_backlog(&self, value: i32) -> Result<()>
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.
fn get_events(&self) -> Result<i32>
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() as zmq::PollEvents; if (events & zmq::POLLIN) != 0 { 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.
fn get_multicast_hops(&self) -> Result<i32>
fn set_multicast_hops(&self, value: i32) -> Result<()>
fn get_rcvtimeo(&self) -> Result<i32>
fn set_rcvtimeo(&self, value: i32) -> Result<()>
fn get_sndtimeo(&self) -> Result<i32>
fn set_sndtimeo(&self, value: i32) -> Result<()>
fn get_tcp_keepalive(&self) -> Result<i32>
fn set_tcp_keepalive(&self, value: i32) -> Result<()>
fn get_tcp_keepalive_cnt(&self) -> Result<i32>
fn set_tcp_keepalive_cnt(&self, value: i32) -> Result<()>
fn get_tcp_keepalive_idle(&self) -> Result<i32>
fn set_tcp_keepalive_idle(&self, value: i32) -> Result<()>
fn get_tcp_keepalive_intvl(&self) -> Result<i32>
fn set_tcp_keepalive_intvl(&self, value: i32) -> Result<()>
fn get_handshake_ivl(&self) -> Result<i32>
fn set_handshake_ivl(&self, value: i32) -> Result<()>
fn set_identity(&self, value: &[u8]) -> Result<()>
fn set_subscribe(&self, value: &[u8]) -> Result<()>
fn set_unsubscribe(&self, value: &[u8]) -> Result<()>
fn get_identity(&self) -> Result<Result<String, Vec<u8>>>
fn get_socks_proxy(&self) -> Result<Result<String, Vec<u8>>>
fn get_mechanism(&self) -> Result<Mechanism>
fn get_plain_username(&self) -> Result<Result<String, Vec<u8>>>
fn get_plain_password(&self) -> Result<Result<String, Vec<u8>>>
fn get_zap_domain(&self) -> Result<Result<String, Vec<u8>>>
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).
fn get_curve_publickey(&self) -> Result<Result<String, Vec<u8>>>
fn get_curve_secretkey(&self) -> Result<Result<String, Vec<u8>>>
fn get_curve_serverkey(&self) -> Result<Result<String, Vec<u8>>>
fn set_socks_proxy(&self, value: Option<&str>) -> Result<()>
fn set_plain_username(&self, value: Option<&str>) -> Result<()>
fn set_plain_password(&self, value: Option<&str>) -> Result<()>
fn set_zap_domain(&self, value: &str) -> Result<()>
fn set_curve_publickey(&self, value: &str) -> Result<()>
fn set_curve_secretkey(&self, value: &str) -> Result<()>
fn set_curve_serverkey(&self, value: &str) -> Result<()>
fn as_poll_item(&self, events: PollEvents) -> PollItem
Create a PollItem
from the socket.
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).