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

Event loop for managing sockets and timers. More...

#include <chrono>
#include <cstddef>
#include <functional>
#include <list>
#include <map>
#include <zmq.hpp>
#include "cppzmqzoltanext/czze_export.h"
#include "poller.h"
Include dependency graph for loop.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  zmqzext::loop_t
 Event loop for managing socket and timer events. More...
 

Typedefs

using zmqzext::timer_id_t = std::size_t
 Unique identifier for timer instances.
 
using zmqzext::fn_socket_handler_t = std::function< bool(loop_t &, zmq::socket_ref)>
 Socket event handler callback type.
 
using zmqzext::fn_timer_handler_t = std::function< bool(loop_t &, timer_id_t)>
 Timer event handler callback type.
 

Detailed Description

Event loop for managing sockets and timers.

This header provides the loop_t class, which implements a complete event loop for managing socket I/O and timer-based events. The event loop combines socket polling (via poller_t) with timer management to create a reactive event-driven architecture.

The event loop monitors registered sockets for readiness and fires callbacks when sockets become ready. Timers can be registered to trigger callbacks at specified intervals, either once or repeatedly. This enables building complex applications with concurrent I/O operations and time-based scheduling.

Note
The event loop runs synchronously and blocks until terminated. Use callbacks that return false to stop finish the loop.
See also
poller_t for underlying socket polling mechanism
install_interrupt_handler() for signal handling integration

Key features:

  • Socket registration with I/O callbacks
  • One-shot and recurring timer support
  • Event loop with interruptible operation
  • Configurable interrupt checking intervals
  • Automatic timer management and expiration
  • Integration with interrupt signal handling
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 loop.h.

Typedef Documentation

◆ fn_socket_handler_t

using zmqzext::fn_socket_handler_t = typedef std::function<bool(loop_t&, zmq::socket_ref)>

Socket event handler callback type.

Function signature for socket event handlers. The handler is called when a registered socket becomes ready for receiving. Returning false finishes the loop; returning true continues processing.

Parameters
loopReference to the event loop
socketThe socket that is ready for receiving
Returns
false to finish the loop, true to continue

Definition at line 91 of file loop.h.

◆ fn_timer_handler_t

using zmqzext::fn_timer_handler_t = typedef std::function<bool(loop_t&, timer_id_t)>

Timer event handler callback type.

Function signature for timer event handlers. The handler is called when a registered timer expires. Returning false finishes the loop; returning true continues processing.

Parameters
loopReference to the event loop
timer_idThe unique identifier of the timer that expired
Returns
false to finish the loop, true to continue

Definition at line 104 of file loop.h.

◆ timer_id_t

using zmqzext::timer_id_t = typedef std::size_t

Unique identifier for timer instances.

Definition at line 78 of file loop.h.