Poller

Basically, these classes provide poll() in a platform-independent way. To use the poller, create one or more Pollables, and register them to the stored::Poller, and call its poll() member function. It returns a list of pollables that have an event to be processed.

The inheritance of the Poller classes is shown below.

abstract Pollable
abstract TypedPollable
Pollable <|-- TypedPollable
TypedPollable <|-- PollableCallback
TypedPollable <|-- PollableFd
TypedPollable <|-- PollableFileLayer
TypedPollable <|-- PollableHandle
TypedPollable <|-- PollableSocket
TypedPollable <|-- PollableZmqLayer
TypedPollable <|-- PollableZmqSocket

abstract InheritablePoller
InheritablePoller <|-- Poller

Pollable <.. Poller

Pollables

stored::Pollable

struct Pollable

A pollable thing.

Subclassed by stored::TypedPollable

Public Types

typedef std::bitset<FlagCount> Events

Type of events and revents.

typedef unsigned long long Events_value
enum EventsFlags

Flags to be used with events and revents.

Values:

enumerator PollInIndex
enumerator PollOutIndex
enumerator PollErrIndex
enumerator PollPriIndex
enumerator PollHupIndex
enumerator FlagCount

Public Functions

inline explicit constexpr Pollable(Events const &e, void *user = nullptr) noexcept

Ctor.

Public Members

Events events

Events to poll.

Do not change these events after adding the Pollable to a Poller.

Not every Poller may support all flags.

Events revents

Returned events by a poll.

Do not set manually, let the Poller do that.

void *user_data

User data.

This can be changed, even after adding a Pollable to a Poller.

Public Static Attributes

static Events_value const PollErr = 1UL << PollErrIndex
static Events_value const PollHup = 1UL << PollHupIndex
static Events_value const PollIn = 1UL << PollInIndex
static Events_value const PollOut = 1UL << PollOutIndex
static Events_value const PollPri = 1UL << PollPriIndex

stored::PollableCallback

template<typename F = Pollable::Events (*)(Pollable const&)>
class PollableCallback : public stored::PollableCallbackBase

Use a callback function while polling.

The function type F must be compatible with Pollable::Events& (Pollable const&).

Public Types

using f_type = Events(Pollable const&)

Public Functions

inline PollableCallback(F f_, Events const &e, void *user = nullptr)
template<typename F_>
inline PollableCallback(F_ &&f_, Events const &e, void *user = nullptr)
inline virtual Events operator()() const noexcept final

Public Members

F f
inline PollableCallback stored::pollable(PollableCallback<>::f_type f, Pollable::Events const &events, void *user = nullptr)
template<typename F>
PollableCallback<typename std::decay<F>::type> stored::pollable(F &&f, Pollable::Events const &events, void *user = nullptr)

stored::PollableFd

class PollableFd : public stored::TypedPollable

Poll a file descriptor.

Do not use in Windows, as its file descriptors are not pollable.

Public Functions

inline constexpr PollableFd(int f, Events const &e, void *user = nullptr) noexcept

Public Members

int fd
inline PollableFd stored::pollable(int fd, Pollable::Events const &events, void *user = nullptr)

stored::PollableFileLayer

class PollableFileLayer : public stored::TypedPollable

Poll a stored::PolledFileLayer.

Public Functions

inline constexpr PollableFileLayer(PolledFileLayer &l, Events const &e, void *user = nullptr) noexcept

Public Members

PolledFileLayer *layer
inline PollableFileLayer stored::pollable(PolledFileLayer &l, Pollable::Events const &events, void *user = nullptr)

stored::PollableHandle

class PollableHandle : public stored::TypedPollable

Poll a Windows HANDLE.

Not all types of HANDLES are supported. Refer to WaitForSingleObject().

Public Functions

inline constexpr PollableHandle(HANDLE h, Events const &e, void *user = nullptr) noexcept

Public Members

HANDLE handle

stored::PollableSocket

class PollableSocket : public stored::TypedPollable

Poll a Windows SOCKET.

Public Functions

inline constexpr PollableSocket(SOCKET s, Events const &e, void *user = nullptr) noexcept

Public Members

SOCKET socket
inline PollableSocket stored::pollable(SOCKET s, Pollable::Events const &events, void *user = nullptr)

stored::PollableZmqLayer

class PollableZmqLayer : public stored::TypedPollable

Poll a stored::ZmqLayer.

Public Functions

inline constexpr PollableZmqLayer(ZmqLayer &l, Events const &e, void *user = nullptr) noexcept

Public Members

ZmqLayer *layer
inline PollableZmqLayer stored::pollable(ZmqLayer &l, Pollable::Events const &events, void *user = nullptr)

stored::PollableZmqSocket

class PollableZmqSocket : public stored::TypedPollable

Poll a ZeroMQ socket.

Public Functions

inline constexpr PollableZmqSocket(void *s, Events const &e, void *user = nullptr) noexcept

Public Members

void *socket
inline PollableZmqSocket stored::pollable(void *s, Pollable::Events const &events, void *user = nullptr)

stored::InheritablePoller

template<typename PollerImpl = PollerImpl>
class InheritablePoller : public stored::ZmqPoller

Subclassed by stored::Poller

Public Types

typedef Vector<Pollable*>::type Result

Public Functions

inline virtual ~InheritablePoller() override

Dtor.

inline virtual int add(Pollable &p) noexcept

Add a pollable object.

Once a pollable is added, do not modify its properties, except for user_data.

Returns:

0 on success, otherwise an errno

inline int add(std::initializer_list<std::reference_wrapper<Pollable>> l) noexcept
inline virtual void clear() noexcept
inline bool empty() const noexcept

Checks if there is any pollable registered.

inline virtual Result const &poll(int timeout_ms = -1) noexcept
inline virtual int remove(Pollable &p) noexcept

Remove a pollable object.

Returns:

0 on success, otherwise an errno

inline virtual void reserve(size_t more)

Reserve memory to add more pollables.

Throws:

std::bad_alloc – when allocation fails

stored::Poller

class Poller : public stored::InheritablePoller<>

Public Types

typedef InheritablePoller base

Public Functions

Poller() = default
inline Poller(std::initializer_list<std::reference_wrapper<Pollable>> l)
virtual ~Poller() final