CppZmqZoltanExt 0.0.1
Loading...
Searching...
No Matches
helpers.h File Reference

Helper utilities for robust ZMQ message sending and receiving. More...

#include <zmq.hpp>
#include "cppzmqzoltanext/czze_export.h"
Include dependency graph for helpers.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename T >
CZZE_EXPORT zmq::send_result_t zmqzext::send_retry_on_eintr (T &socket, zmq::const_buffer const &buf, zmq::send_flags flags=zmq::send_flags::none)
 Send a message buffer with automatic retry on EINTR.
 
template<typename T >
CZZE_EXPORT zmq::send_result_t zmqzext::send_retry_on_eintr (T &socket, zmq::message_t &msg, zmq::send_flags flags=zmq::send_flags::none)
 Send a ZMQ message with automatic retry on EINTR.
 
template<typename T >
CZZE_EXPORT zmq::send_result_t zmqzext::send_retry_on_eintr (T &socket, zmq::message_t &&msg, zmq::send_flags flags=zmq::send_flags::none)
 Send a ZMQ message (rvalue) with automatic retry on EINTR.
 
template<typename T >
CZZE_EXPORT zmq::recv_buffer_result_t zmqzext::recv_retry_on_eintr (T &socket, zmq::mutable_buffer const &buf, zmq::recv_flags flags=zmq::recv_flags::none)
 Receive data into a buffer with automatic retry on EINTR.
 
template<typename T >
CZZE_EXPORT zmq::recv_result_t zmqzext::recv_retry_on_eintr (T &socket, zmq::message_t &msg, zmq::recv_flags flags=zmq::recv_flags::none)
 Receive a message with automatic retry on EINTR.
 

Detailed Description

Helper utilities for robust ZMQ message sending and receiving.

This header provides utility functions that wrap ZMQ send and receive operations with automatic retry logic for handling EINTR errors. These helpers ensure that signal interruptions do not prematurely terminate socket operations.

The module implements retrying operations that are interrupted by signals, allowing applications to safely use signal handlers without compromising message delivery.

Key features:

  • Transparent EINTR handling for send operations
  • Transparent EINTR handling for receive operations
  • Support for multiple buffer and message types
  • Configurable send/receive flags
  • Returns original ZMQ result types for integration
Authors
Luan Young (luanp.nosp@m.y@gm.nosp@m.ail.c.nosp@m.om)

Distributed under the MIT License (MIT) (See accompanying file LICENSE or copy at http://opensource.org/licenses/MIT)

Definition in file helpers.h.

Function Documentation

◆ recv_retry_on_eintr() [1/2]

template<typename T >
CZZE_EXPORT zmq::recv_result_t zmqzext::recv_retry_on_eintr ( T &  socket,
zmq::message_t &  msg,
zmq::recv_flags  flags = zmq::recv_flags::none 
)

Receive a message with automatic retry on EINTR.

Receives a ZMQ message from a socket, automatically retrying if the operation is interrupted by a signal. The message object is populated with the received data.

Parameters
socketThe ZMQ socket to receive data from
msgReference to the message object to populate with received data
flagsOptional ZMQ receive flags (default: none)
Returns
The receive result containing the number of bytes received
Exceptions
zmq::error_tif an error occurs (other than EINTR)
Note
Overloads are provided for socket parameter types zmq::socket_t and zmq::socket_ref
See also
recv_retry_on_eintr(T&, zmq::mutable_buffer const&, zmq::recv_flags)

Definition at line 103 of file helpers.cpp.

◆ recv_retry_on_eintr() [2/2]

template<typename T >
CZZE_EXPORT zmq::recv_buffer_result_t zmqzext::recv_retry_on_eintr ( T &  socket,
zmq::mutable_buffer const &  buf,
zmq::recv_flags  flags = zmq::recv_flags::none 
)

Receive data into a buffer with automatic retry on EINTR.

Receives data from a ZMQ socket into a mutable buffer, automatically retrying if the operation is interrupted by a signal.

Parameters
socketThe ZMQ socket to receive data from
bufThe mutable buffer to receive data into
flagsOptional ZMQ receive flags (default: none)
Returns
The receive result containing the number of bytes received and the actual buffer used
Exceptions
zmq::error_tif an error occurs (other than EINTR)
Note
Overloads are provided for socket parameter types zmq::socket_t and zmq::socket_ref
See also
recv_retry_on_eintr(T&, zmq::message_t&, zmq::recv_flags)

Definition at line 85 of file helpers.cpp.

◆ send_retry_on_eintr() [1/3]

template<typename T >
CZZE_EXPORT zmq::send_result_t zmqzext::send_retry_on_eintr ( T &  socket,
zmq::const_buffer const &  buf,
zmq::send_flags  flags = zmq::send_flags::none 
)

Send a message buffer with automatic retry on EINTR.

Sends data from a const buffer through a ZMQ socket, automatically retrying if the operation is interrupted by a signal.

Parameters
socketThe ZMQ socket to send data through
bufThe constant buffer containing data to send
flagsOptional ZMQ send flags (default: none)
Returns
The send result containing the number of bytes sent
Exceptions
zmq::error_tif an error occurs (other than EINTR)
Note
Overloads are provided for socket parameter types zmq::socket_t and zmq::socket_ref
See also
send_retry_on_eintr(T&, zmq::message_t&, zmq::send_flags)
send_retry_on_eintr(T&, zmq::message_t&&, zmq::send_flags)

Definition at line 43 of file helpers.cpp.

◆ send_retry_on_eintr() [2/3]

template<typename T >
CZZE_EXPORT zmq::send_result_t zmqzext::send_retry_on_eintr ( T &  socket,
zmq::message_t &&  msg,
zmq::send_flags  flags = zmq::send_flags::none 
)

Send a ZMQ message (rvalue) with automatic retry on EINTR.

Sends a temporary ZMQ message through a socket, automatically retrying if the operation is interrupted by a signal.

Parameters
socketThe ZMQ socket to send data through
msgRvalue reference to the message to send
flagsOptional ZMQ send flags (default: none)
Returns
The send result containing the number of bytes sent
Exceptions
zmq::error_tif an error occurs (other than EINTR)
Note
Overloads are provided for socket parameter types zmq::socket_t and zmq::socket_ref
See also
send_retry_on_eintr(T&, zmq::const_buffer const&, zmq::send_flags)
send_retry_on_eintr(T&, zmq::message_t&, zmq::send_flags)

Definition at line 79 of file helpers.cpp.

◆ send_retry_on_eintr() [3/3]

template<typename T >
CZZE_EXPORT zmq::send_result_t zmqzext::send_retry_on_eintr ( T &  socket,
zmq::message_t &  msg,
zmq::send_flags  flags = zmq::send_flags::none 
)

Send a ZMQ message with automatic retry on EINTR.

Sends a ZMQ message object through a socket, automatically retrying if the operation is interrupted by a signal.

Parameters
socketThe ZMQ socket to send data through
msgReference to the message to send
flagsOptional ZMQ send flags (default: none)
Returns
The send result containing the number of bytes sent
Exceptions
zmq::error_tif an error occurs (other than EINTR)
Note
Overloads are provided for socket parameter types zmq::socket_t and zmq::socket_ref
See also
send_retry_on_eintr(T&, zmq::const_buffer const&, zmq::send_flags)
send_retry_on_eintr(T&, zmq::message_t&&, zmq::send_flags)

Definition at line 61 of file helpers.cpp.