pub struct Socket { /* private fields */ }
Expand description
A socket, the central object in 0MQ.
Implementations§
Source§impl Socket
impl Socket
Sourcepub fn into_raw(self) -> *mut c_void
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.
Sourcepub unsafe fn from_raw(sock: *mut c_void) -> Socket
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.
Sourcepub fn as_mut_ptr(&mut self) -> *mut c_void
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.
Sourcepub fn disconnect(&self, endpoint: &str) -> Result<()>
pub fn disconnect(&self, endpoint: &str) -> Result<()>
Disconnect a previously connected socket
Sourcepub fn monitor(&self, monitor_endpoint: &str, events: i32) -> Result<()>
pub fn monitor(&self, monitor_endpoint: &str, events: i32) -> Result<()>
Configure the socket for monitoring
Sourcepub fn send<T>(&self, data: T, flags: i32) -> Result<()>where
T: Sendable,
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.
Sourcepub fn send_msg(&self, msg: Message, flags: i32) -> Result<()>
👎Deprecated since 0.9.0: Use send
instead
pub fn send_msg(&self, msg: Message, flags: i32) -> Result<()>
send
insteadSend a Message
message.
pub fn send_str(&self, data: &str, flags: i32) -> Result<()>
send
insteadpub fn send_multipart<I, T>(&self, iter: I, flags: i32) -> Result<()>
Sourcepub fn recv(&self, msg: &mut Message, flags: i32) -> Result<()>
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.
Sourcepub fn recv_into(&self, bytes: &mut [u8], flags: i32) -> Result<usize>
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.
Sourcepub fn recv_string(&self, flags: i32) -> Result<Result<String, Vec<u8>>>
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.
Sourcepub fn recv_multipart(&self, flags: i32) -> Result<Vec<Vec<u8>>>
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.
Sourcepub fn is_immediate(&self) -> Result<bool>
pub fn is_immediate(&self) -> Result<bool>
Accessor for the ZMQ_IMMEDIATE
option.
Sourcepub fn set_immediate(&self, value: bool) -> Result<()>
pub fn set_immediate(&self, value: bool) -> Result<()>
Accessor for the ZMQ_IMMEDIATE
option.
Sourcepub fn is_plain_server(&self) -> Result<bool>
pub fn is_plain_server(&self) -> Result<bool>
Accessor for the ZMQ_PLAIN_SERVER
option.
Sourcepub fn set_plain_server(&self, value: bool) -> Result<()>
pub fn set_plain_server(&self, value: bool) -> Result<()>
Accessor for the ZMQ_PLAIN_SERVER
option.
Sourcepub fn is_conflate(&self) -> Result<bool>
pub fn is_conflate(&self) -> Result<bool>
Accessor for the ZMQ_CONFLATE
option.
Sourcepub fn set_conflate(&self, value: bool) -> Result<()>
pub fn set_conflate(&self, value: bool) -> Result<()>
Accessor for the ZMQ_CONFLATE
option.
pub fn is_probe_router(&self) -> Result<bool>
pub fn set_probe_router(&self, value: bool) -> Result<()>
pub fn is_router_mandatory(&self) -> Result<bool>
pub fn set_router_mandatory(&self, value: bool) -> Result<()>
pub fn is_router_handover(&self) -> Result<bool>
pub fn set_router_handover(&self, value: bool) -> Result<()>
pub fn is_curve_server(&self) -> Result<bool>
pub fn set_curve_server(&self, value: bool) -> Result<()>
pub fn is_gssapi_server(&self) -> Result<bool>
pub fn set_gssapi_server(&self, value: bool) -> Result<()>
pub fn is_gssapi_plaintext(&self) -> Result<bool>
pub fn set_gssapi_plaintext(&self, value: bool) -> Result<()>
pub fn set_req_relaxed(&self, value: bool) -> Result<()>
pub fn set_req_correlate(&self, value: bool) -> Result<()>
Sourcepub fn get_socket_type(&self) -> Result<SocketType>
pub fn get_socket_type(&self) -> Result<SocketType>
Return the type of this socket.
Sourcepub fn get_rcvmore(&self) -> Result<bool>
pub fn get_rcvmore(&self) -> Result<bool>
Return true if there are more frames of a multipart message to receive.
pub fn get_maxmsgsize(&self) -> Result<i64>
pub fn set_maxmsgsize(&self, value: i64) -> Result<()>
pub fn get_sndhwm(&self) -> Result<i32>
pub fn set_sndhwm(&self, value: i32) -> Result<()>
pub fn get_rcvhwm(&self) -> Result<i32>
pub fn set_rcvhwm(&self, value: i32) -> Result<()>
pub fn get_affinity(&self) -> Result<u64>
pub fn set_affinity(&self, value: u64) -> Result<()>
pub fn get_rate(&self) -> Result<i32>
pub fn set_rate(&self, value: i32) -> Result<()>
pub fn get_recovery_ivl(&self) -> Result<i32>
pub fn set_recovery_ivl(&self, value: i32) -> Result<()>
pub fn get_sndbuf(&self) -> Result<i32>
pub fn set_sndbuf(&self, value: i32) -> Result<()>
pub fn get_rcvbuf(&self) -> Result<i32>
pub fn set_rcvbuf(&self, value: i32) -> Result<()>
pub fn get_tos(&self) -> Result<i32>
pub fn set_tos(&self, value: i32) -> Result<()>
pub fn get_linger(&self) -> Result<i32>
pub fn set_linger(&self, value: i32) -> Result<()>
pub fn get_reconnect_ivl(&self) -> Result<i32>
pub fn set_reconnect_ivl(&self, value: i32) -> Result<()>
pub fn get_reconnect_ivl_max(&self) -> Result<i32>
pub fn set_reconnect_ivl_max(&self, value: i32) -> Result<()>
pub fn get_backlog(&self) -> Result<i32>
pub fn set_backlog(&self, value: i32) -> Result<()>
Sourcepub fn get_fd(&self) -> Result<RawFd>
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.
Sourcepub fn get_events(&self) -> Result<PollEvents>
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.
pub fn get_multicast_hops(&self) -> Result<i32>
pub fn set_multicast_hops(&self, value: i32) -> Result<()>
pub fn get_rcvtimeo(&self) -> Result<i32>
pub fn set_rcvtimeo(&self, value: i32) -> Result<()>
pub fn get_sndtimeo(&self) -> Result<i32>
pub fn set_sndtimeo(&self, value: i32) -> Result<()>
pub fn get_tcp_keepalive(&self) -> Result<i32>
pub fn set_tcp_keepalive(&self, value: i32) -> Result<()>
pub fn get_tcp_keepalive_cnt(&self) -> Result<i32>
pub fn set_tcp_keepalive_cnt(&self, value: i32) -> Result<()>
pub fn get_tcp_keepalive_idle(&self) -> Result<i32>
pub fn set_tcp_keepalive_idle(&self, value: i32) -> Result<()>
pub fn get_tcp_keepalive_intvl(&self) -> Result<i32>
pub fn set_tcp_keepalive_intvl(&self, value: i32) -> Result<()>
pub fn get_handshake_ivl(&self) -> Result<i32>
pub fn set_handshake_ivl(&self, value: i32) -> Result<()>
pub fn set_identity(&self, value: &[u8]) -> Result<()>
pub fn set_subscribe(&self, value: &[u8]) -> Result<()>
pub fn set_unsubscribe(&self, value: &[u8]) -> Result<()>
pub fn get_heartbeat_ivl(&self) -> Result<i32>
pub fn set_heartbeat_ivl(&self, value: i32) -> Result<()>
pub fn get_heartbeat_ttl(&self) -> Result<i32>
pub fn set_heartbeat_ttl(&self, value: i32) -> Result<()>
pub fn get_heartbeat_timeout(&self) -> Result<i32>
pub fn set_heartbeat_timeout(&self, value: i32) -> Result<()>
pub fn get_connect_timeout(&self) -> Result<i32>
pub fn set_connect_timeout(&self, value: i32) -> Result<()>
pub fn get_identity(&self) -> Result<Vec<u8>>
pub fn get_socks_proxy(&self) -> Result<Result<String, Vec<u8>>>
pub fn get_mechanism(&self) -> Result<Mechanism>
pub fn get_plain_username(&self) -> Result<Result<String, Vec<u8>>>
pub fn get_plain_password(&self) -> Result<Result<String, Vec<u8>>>
pub fn get_zap_domain(&self) -> Result<Result<String, Vec<u8>>>
Sourcepub fn get_last_endpoint(&self) -> Result<Result<String, Vec<u8>>>
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).
Sourcepub fn get_curve_publickey(&self) -> Result<Vec<u8>>
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.
Sourcepub fn get_curve_secretkey(&self) -> Result<Vec<u8>>
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.
Sourcepub fn get_curve_serverkey(&self) -> Result<Vec<u8>>
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.
pub fn get_gssapi_principal(&self) -> Result<Result<String, Vec<u8>>>
pub fn get_gssapi_service_principal(&self) -> Result<Result<String, Vec<u8>>>
pub fn set_socks_proxy(&self, value: Option<&str>) -> Result<()>
pub fn set_plain_username(&self, value: Option<&str>) -> Result<()>
pub fn set_plain_password(&self, value: Option<&str>) -> Result<()>
pub fn set_zap_domain(&self, value: &str) -> Result<()>
pub fn set_xpub_welcome_msg(&self, value: Option<&str>) -> Result<()>
pub fn set_xpub_verbose(&self, value: bool) -> Result<()>
pub fn set_curve_publickey(&self, value: &[u8]) -> Result<()>
pub fn set_curve_secretkey(&self, value: &[u8]) -> Result<()>
pub fn set_curve_serverkey(&self, value: &[u8]) -> Result<()>
pub fn set_gssapi_principal(&self, value: &str) -> Result<()>
pub fn set_gssapi_service_principal(&self, value: &str) -> Result<()>
Sourcepub fn as_poll_item(&self, events: PollEvents) -> PollItem<'_>
pub fn as_poll_item(&self, events: PollEvents) -> PollItem<'_>
Create a PollItem
from the socket.