/usr/include/zmqpp/reactor.hpp is in libzmqpp-dev 4.1.2-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | /*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file is part of zmqpp.
* Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file.
*/
#pragma once
#include <unordered_map>
#include <vector>
#include <map>
#include <functional>
#include "compatibility.hpp"
#include "poller.hpp"
namespace zmqpp
{
class socket;
typedef socket socket_t;
/**
* Reactor object that helps to manage multiple socket by calling a user-defined handler for each socket
* when a watched event occurs.
*
* It uses zmq::poller as the underlying polling mechanism.
*/
class reactor
{
public:
typedef std::function<void (void) > Callable;
typedef std::pair<zmq_pollitem_t, Callable> PollItemCallablePair;
/**
* Construct an empty polling model.
*/
reactor();
/**
* Cleanup reactor.
*
* Any sockets will need to be closed separately.
*/
~reactor();
/**
* Add a socket to the reactor, providing a handler that will be called when the monitored events occur.
*
* \param socket the socket to monitor.
* \param callable the function that will be called by the reactor when a registered event occurs on socket.
* \param event the event flags to monitor on the socket.
*/
void add(socket_t& socket, Callable callable, short const event = poller::poll_in);
/*!
* Add a standard socket to the reactor, providing a handler that will be called when the monitored events occur.
*
* \param descriptor the standard socket to monitor (SOCKET under Windows, a file descriptor otherwise).
* \param callable the function that will be called by the reactor when a registered event occurs on fd.
* \param event the event flags to monitor.
*/
void add(raw_socket_t const descriptor, Callable callable, short const event = poller::poll_in | poller::poll_error);
/**
* Check if we are monitoring a given socket with this reactor.
*
* \param socket the socket to check.
* \return true if it is there.
*/
bool has(socket_t const& socket);
/**
* Check if we are monitoring a given standard socket with this reactor.
*
* \param descriptor the raw socket to check (SOCKET under Windows, a file descriptor otherwise).
* \return true if it is there.
*/
bool has(raw_socket_t const descriptor);
/**
* Stop monitoring a socket.
*
* \param socket the socket to stop monitoring.
*/
void remove(socket_t const& socket);
/**
* Stop monitoring a standard socket.
*
* \param descriptor the standard socket to stop monitoring.
*/
void remove(raw_socket_t const descriptor);
/**
* Update the monitored event flags for a given socket.
*
* \param socket the socket to update event flags.
* \param event the event flags to monitor on the socket.
*/
void check_for(socket_t const& socket, short const event);
/*!
* Update the monitored event flags for a given standard socket.
*
* \param descriptor the raw socket to update event flags (SOCKET under Windows, a file descriptor otherwise).
* \param event the event flags to monitor on the socket.
*/
void check_for(raw_socket_t const descriptor, short const event);
/**
* Poll for monitored events and call associated handler when needed.
*
* By default this method will block forever or until at least one of the monitored
* sockets or file descriptors has events.
*
* If a timeout is set and was reached then this function returns false.
*
* \param timeout milliseconds to timeout.
* \return true if there is an event..
*/
bool poll(long timeout = poller::wait_forever);
/**
* Get the event flags triggered for a socket.
*
* \param socket the socket to get triggered event flags for.
* \return the event flags.
*/
short events(socket_t const& socket) const;
/**
* Get the event flags triggered for a standard socket.
*
* \param descriptor the raw socket to get triggered event flags for (SOCKET under Windows, a file descriptor otherwise).
* \return the event flags.
*/
short events(raw_socket_t const descriptor) const;
/**
* Get a reference to the underlying poller object used by the reactor.
* Not sure this is useful.
*/
poller &get_poller();
/**
* Get a reference to the underlying poller object used by the reactor (const version).
* Not sure this is useful either.
*/
const poller &get_poller() const;
protected:
void add(const zmq_pollitem_t &item, Callable callable);
private:
std::vector<PollItemCallablePair> items_;
std::vector<const socket_t *> sockRemoveLater_;
std::vector<raw_socket_t> fdRemoveLater_;
/**
* Flush the fdRemoveLater_ and sockRemoveLater_ vector, effectively removing
* the item for the reactor and poller.
*/
void flush_remove_later();
poller poller_;
bool dispatching_;
};
}
|