Class MultiplexingDispatchable

Inheritance Relationships

Base Type

Class Documentation

class MultiplexingDispatchable : public mir::dispatch::Dispatchable

An adaptor that combines multiple Dispatchables into a single Dispatchable.

Note

Instances are fully thread-safe.

Public Functions

MultiplexingDispatchable()
MultiplexingDispatchable(std::initializer_list<std::shared_ptr<Dispatchable>> dispatchees)
virtual ~MultiplexingDispatchable() noexcept
MultiplexingDispatchable &operator=(MultiplexingDispatchable const&) = delete
MultiplexingDispatchable(MultiplexingDispatchable const&) = delete
virtual Fd watch_fd() const override

Get a poll()able file descriptor.

Returns:

A file descriptor usable with poll() or equivalent function calls. relevant_events() contains the set of event types to watch for.

virtual bool dispatch(FdEvents events) override

Dispatch one pending event.

Parameters:

events[in] The set of events current on the file-descriptor

Returns:

False iff no more events will be produced by this Dispatchable. Dispatch should no longer be called.

Note

This will dispatch at most one event. If there are multiple events specified in events (eg: readable | remote_closed) then dispatch will process only one.

Note

It is harmless to call dispatch() with an event that does not contain any of the events from relevant_events(). The function will do nothing in such a case.

Note

An implementation of dispatch() MUST handle FdEvent::error, if only to return false and terminate further event dispatch.

virtual FdEvents relevant_events() const override

The set of file-descriptor events this Dispatchable handles.

void add_watch(std::shared_ptr<Dispatchable> const &dispatchee)

Add a dispatchable to the adaptor.

Parameters:

dispatchee[in] Dispatchable to add. The Dispatchable’s dispatch() function will not be called reentrantly.

void add_watch(std::shared_ptr<Dispatchable> const &dispatchee, DispatchReentrancy reentrancy)

Add a dispatchable to the adaptor, specifying the reentrancy of dispatch()

void add_watch(Fd const &fd, std::function<void()> const &callback)

Add a simple callback to the adaptor.

Parameters:
  • fd[in] File descriptor to monitor for readability

  • callback[in] Callback to fire when fd becomes readable. This callback is not called reentrantly.

void remove_watch(std::shared_ptr<Dispatchable> const &dispatchee)

Remove a watch from the dispatchable.

Parameters:

dispatchee[in] Dispatchable to remove

void remove_watch(Fd const &fd)

Remove a watch by file-descriptor.

Parameters:

fd[in] File descriptor of watch to remove.