Class AsioEventLoop

Inheritance Relationships

Base Type

Class Documentation

class AsioEventLoop : public netio3::BaseEventLoop

The AsioEventLoop class represents an event loop using Boost.Asio.

This class uses the asio io service as the event loop driver. File descriptors are registered as stream descriptors with the io service.

Although supporting arbitrary file descriptors (like for exaple libfabric ones), this event loop is designed to be used with the asyncmsg backend.

Public Functions

explicit AsioEventLoop(std::function<void()> cb_init = nullptr)
~AsioEventLoop() override
AsioEventLoop(const AsioEventLoop &other) = delete
AsioEventLoop &operator=(const AsioEventLoop &other) = delete
AsioEventLoop(AsioEventLoop &&other) = delete
AsioEventLoop &operator=(AsioEventLoop &&other) = delete
virtual void register_fd(const EventContext &ctx) override

Registers an event with the event loop.

This function is used to register a file descriptor with the event loop. The registered file descriptor will be monitored for read events.

Parameters:

ctx – The event context to register

virtual void remove_fd(int fd, bool close_fd = false, bool wait = false) override

Removes an event from the event loop.

This function is used to remove a file descriptor from the event loop. The file descriptor will no longer be monitored for events.

If close_fd is true, the file descriptor is closed. Otherwise, it is only removed from the event loop.

close_fd is ignored as all FDs are handled by ASIO.

Parameters:
  • fd – The file descriptor to remove

  • close_fd – Whether to close the file descriptor

  • wait – Whether to wait for outstanding events to finish

virtual void run() override

Runs the event loop.

The event loop is executed in the caling thread. The function blocks until the event loop is stopped.

The on_init callback is executed before the event loop starts.

virtual void run_for(std::uint64_t sec) override

Runs the event loop for a given time.

The event loop is executed in the calling thread. The function blocks until the event loop is stopped or the given time has passed.

Parameters:

sec – The time to run the event loop in seconds

virtual void stop() override

Stops the event loop.

virtual bool is_running() const override

Checks if the event loop is running.

Returns:

True if the event loop is running, false otherwise

inline boost::asio::io_service &get_io_service()

Get the io service.

Returns:

The io service

Public Static Functions

static void process_event(const EventContext &evc)

Process the given event context.

Call the callback registered with a file descriptor if a callback was registered.

Parameters:

evc – The event context to process