This file is indexed.

/usr/include/zmqpp/poller.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
 * 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.
 */

/**
 * \file
 *
 * \date   9 Aug 2011
 * \author Ben Gray (\@benjamg)
 */

#ifndef ZMQPP_POLLER_HPP_
#define ZMQPP_POLLER_HPP_

#include <unordered_map>
#include <vector>

#include "compatibility.hpp"

namespace zmqpp
{

class socket;
typedef socket socket_t;

/**
 * Polling wrapper.
 *
 * Allows access to polling for any number of zmq sockets or standard sockets.
 */
class poller
{
public:
	static const long wait_forever; /*!< Block forever flag, default setting. */

	static const short poll_none;   /*!< No polling flags set. */
	static const short poll_in;     /*!< Monitor inbound flag. */
	static const short poll_out;    /*!< Monitor output flag. */
	static const short poll_error;  /*!< Monitor error flag.\n Only for file descriptors. */

#if ((ZMQ_VERSION_MAJOR == 4 && ZMQ_VERSION_MINOR >= 2) || ZMQ_VERSION_MAJOR > 4)
        static const short poll_pri;    /*!< Priority input flag.\n Only for file descriptors. See POLLPRI) */
#endif

	/**
	 * Construct an empty polling model.
	 */
	poller();

	/**
	 * Cleanup poller.
	 *
	 * Any sockets will need to be closed separately.
	 */
	~poller();

	/**
	 * Add a socket to the polling model and set which events to monitor.
	 *
	 * \param socket the socket to monitor.
	 * \param event the event flags to monitor on the socket.
	 */
	void add(socket_t& socket, short const event = poll_in);

	/**
	 * Add a standard socket to the polling model and set which events to monitor.
	 *
	 * \param descriptor the raw socket to monitor (SOCKET under Windows, a file descriptor otherwise).
	 * \param event the event flags to monitor.
	 */
	void add(raw_socket_t const descriptor, short const event = poll_in | poll_error);

	/**
	 * Add a zmq_pollitem_t to the poller; Events to monitor are already configured.
	 * If the zmq_pollitem_t has a null socket pointer it is added to the fdindex,
	 * otherwise it is added to the socket index.
	 *
	 * \param item the pollitem to be added
	 */
	void add(zmq_pollitem_t const& item);

	 /**
	  * Check if we are monitoring a given socket with this poller.
	  *
	  * \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 poller.
	 *
	 * \param descriptor the raw socket to check for.
	 * \return true if it is there.
	 */
	 bool has(raw_socket_t const descriptor);

	/**
	 * Check if we are monitoring a given pollitem.
	 * We assume the pollitem is a socket if it's socket is a non null pointer; otherwise,
	 * it is considered as a file descriptor.
	 *
	 * \param item the pollitem to check for
	 * \return true if it is there.
	 */
	bool has(zmq_pollitem_t const& item);

	/**
	 * 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 raw socket to stop monitoring (SOCKET under Windows, a file descriptor otherwise).
	 */
	void remove(raw_socket_t const descriptor);

	/**
	 * Stop monitoring a zmq_pollitem_t
	 *
	 * \param item the pollitem to stop monitoring.
	 */
	void remove(zmq_pollitem_t const& item);

	/**
	 * 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);
	
	/**
	 * Update the monitored event flags for a given zmq_pollitem_t
	 *
	 * \param item the item to change event flags for.
	 * \param event the event flags to monitor on the socket.
	 */
	void check_for(zmq_pollitem_t const& item, short const event);
	
	/**
	 * Poll for monitored events.
	 *
	 * 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 = 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 the event flags triggered for a zmq_pollitem_t
	 *
	 * \param item the pollitem to get triggered event flags for.
	 * \return the event flags.
	 */
	short events(zmq_pollitem_t const& item) const;

	/**
	 * Check either a standard socket or zmq socket for input events.
	 *
	 * Templated helper method that calls through to event and checks for a given flag
	 *
	 * \param watchable either a standard socket or socket known to the poller.
	 * \return true if there is input.
	 */
	template<typename Watched>
	bool has_input(Watched const& watchable) const { return (events(watchable) & poll_in) != 0; }

	/**
	 * Check either a standard socket or zmq socket for output events.
	 *
	 * Templated helper method that calls through to event and checks for a given flag
	 *
	 * \param watchable either a standard socket or zmq socket known to the poller.
	 * \return true if there is output.
	 */
	template<typename Watched>
	bool has_output(Watched const& watchable) const { return (events(watchable) & poll_out) != 0; }

	/**
	 * Check a standard socket (file descriptor or SOCKET).
	 *
	 * Templated helper method that calls through to event and checks for a given flag
	 *
	 * Technically this template works for sockets as well but the error flag is never set for
	 * sockets so I have no idea why someone would call it.
	 *
	 * \param watchable a standard socket known to the poller.
	 * \return true if there is an error.
	 */
	template<typename Watched>
	bool has_error(Watched const& watchable) const { return (events(watchable) & poll_error) != 0; }

private:
	std::vector<zmq_pollitem_t> _items;
	std::unordered_map<void *, size_t> _index;
	std::unordered_map<raw_socket_t, size_t> _fdindex;

	void reindex(size_t const index);
};

}

#endif /* ZMQPP_POLLER_HPP_ */