Monero
Loading...
Searching...
No Matches
net::zmq Namespace Reference

Classes

class  terminate
 Calls zmq_term. More...
struct  close
 Calls zmq_close. More...

Typedefs

using context = std::unique_ptr<void, terminate>
 Unique ZMQ context handle, calls zmq_term on destruction.
using socket = std::unique_ptr<void, close>
 Unique ZMQ socket handle, calls zmq_close on destruction.

Functions

const std::error_category & error_category () noexcept
expect< std::string > receive (void *const socket, const int flags)
expect< void > send (const epee::span< const std::uint8_t > payload, void *const socket, const int flags) noexcept
expect< void > send (epee::byte_slice &&payload, void *socket, int flags) noexcept
std::error_code make_error_code (int code) noexcept
std::error_code get_error_code () noexcept
template<typename F, typename... T>
expect< void > retry_op (F op, T &&... args) noexcept(noexcept(op(args...)))

Typedef Documentation

◆ context

using net::zmq::context = std::unique_ptr<void, terminate>

Unique ZMQ context handle, calls zmq_term on destruction.

◆ socket

using net::zmq::socket = std::unique_ptr<void, close>

Unique ZMQ socket handle, calls zmq_close on destruction.

Function Documentation

◆ error_category()

const std::error_category & net::zmq::error_category ( )
noexcept
Returns
Category for ZMQ errors.

◆ get_error_code()

std::error_code net::zmq::get_error_code ( )
inlinenoexcept
Returns
Error from zmq_errno() using net::zmq::error_category().

◆ make_error_code()

std::error_code net::zmq::make_error_code ( int code)
inlinenoexcept
Returns
code (usally from zmq_errno()) using net::zmq::error_category()`.

◆ receive()

expect< std::string > net::zmq::receive ( void * socket,
int flags = 0 )

Read all parts of the next message on socket. Blocks until the entire next message (all parts) are read, or until zmq_term is called on the zmq_context associated with socket. If the context is terminated, make_error_code(ETERM) is returned.

Note
This will automatically retry on EINTR, so exiting on interrupts requires context termination.
If non-blocking behavior is requested on socket or by flags, then net::zmq::make_error_code(EAGAIN) will be returned if this would block.
Parameters
socketHandle created with zmq_socket.
flagsSee zmq_msg_read for possible flags.
Returns
Message payload read from socket or ZMQ error.

◆ retry_op()

template<typename F, typename... T>
expect< void > net::zmq::retry_op ( F op,
T &&... args )
noexcept

Retry a ZMQ function on EINTR errors. F must return an int with values less than 0 on error.

Parameters
opThe ZMQ function to execute + retry
argsForwarded to op. Must be resuable in case of retry.
Returns
All errors except for EINTR.

◆ send() [1/2]

expect< void > net::zmq::send ( epee::span< const std::uint8_t > payload,
void * socket,
int flags = 0 )
noexcept

Sends payload on socket. Blocks until the entire message is queued for sending, or until zmq_term is called on the zmq_context associated with socket. If the context is terminated, make_error_code(ETERM) is returned.

Note
This will automatically retry on EINTR, so exiting on interrupts requires context termination.
If non-blocking behavior is requested on socket or by flags, then net::zmq::make_error_code(EAGAIN) will be returned if this would block.
Parameters
payloadsent as one message on socket.
socketHandle created with zmq_socket.
flagsSee zmq_send for possible flags.
Returns
success() if sent, otherwise ZMQ error.

◆ send() [2/2]

expect< void > net::zmq::send ( epee::byte_slice && payload,
void * socket,
int flags = 0 )
noexcept

Sends payload on socket. Blocks until the entire message is queued for sending, or until zmq_term is called on the zmq_context associated with socket. If the context is terminated, make_error_code(ETERM) is returned.

Note
This will automatically retry on EINTR, so exiting on interrupts requires context termination.
If non-blocking behavior is requested on socket or by flags, then net::zmq::make_error_code(EAGAIN) will be returned if this would block.
Parameters
payloadsent as one message on socket.
socketHandle created with zmq_socket.
flagsSee zmq_msg_send for possible flags.
Postcondition
payload.emtpy() - ownership is transferred to zmq.
Returns
success() if sent, otherwise ZMQ error.