Struct zmq::Socket

source ·
pub struct Socket { /* private fields */ }
Expand description

A socket, the central object in 0MQ.

Implementations§

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.

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.

Return the inner pointer to this Socket.

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

Accept connections on a socket.

Connect a socket.

Disconnect a previously connected socket

Configure the socket for monitoring

Send a &[u8] message.

Send a Message message.

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

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.

Receive a message into a fresh Message.

Receive a message as a byte vector.

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.

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.

Accessor for the ZMQ_IPV6 option.

Accessor for the ZMQ_IPV6 option.

Accessor for the ZMQ_IMMEDIATE option.

Accessor for the ZMQ_IMMEDIATE option.

Accessor for the ZMQ_PLAIN_SERVER option.

Accessor for the ZMQ_PLAIN_SERVER option.

Accessor for the ZMQ_CONFLATE option.

Accessor for the ZMQ_CONFLATE option.

Return the type of this socket.

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

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.

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.

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

Create a PollItem from the socket.

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§

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.