-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoll.hpp
70 lines (63 loc) · 2.64 KB
/
Poll.hpp
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
/*******************************************************************************
* libunix++: C++ wrapper for Linux system calls
* Polling operations
*
* © 2020—2021, Sauron <[email protected]>
******************************************************************************/
#ifndef __UNIXPP_POLL_HPP
#define __UNIXPP_POLL_HPP
#include <poll.h>
#include <vector>
#include "Stream.hpp"
namespace upp {
class Poll {
public:
/** There is data to read **/
static const short IN=POLLIN;
/** There is some exceptional condition on the file descriptor **/
static const short PRI=POLLPRI;
/** Writing is now possible **/
static const short OUT=POLLOUT;
/** Stream socket peer closed connection **/
static const short RDHUP=POLLRDHUP;
/** Error condition **/
static const short ERR=POLLERR;
/** Hang up **/
static const short HUP=POLLHUP;
/** Invalid request: fd not open **/
static const short NVAL=POLLNVAL;
/**/
typedef std::vector<struct pollfd>::const_iterator Iterator;
/**/
Poll() {}
/**/
Poll(const std::vector<Stream> &streams, short events);
/** Returns number of supervised streams **/
size_t count() const { return pollfds.size(); }
/**/
void add(const Stream &stream, short events);
/** Wait for events on file descriptors **/
unsigned poll(int timeout);
/** Wait for events on file descriptors **/
unsigned poll(bool &interrupted, int timeout);
/** Wait for events on file descriptors, waiting for a signal safely **/
unsigned poll(const timespec * tmo_p, const sigset_t * sigmask);
/** Wait for events on file descriptors, waiting for a signal safely **/
unsigned poll(bool &interrupted, const timespec * tmo_p, const sigset_t * sigmask);
/** Returns returned events for the specified stream **/
short revents(size_t index) const { return pollfds[index].revents; }
/** Shorthand for revents() **/
short operator [](size_t index) const { return revents(index); }
/** Poll just one file descriptor **/
static short poll(Stream &stream, short events, int timeout);
/** Poll just one file descriptor **/
static short poll(bool &interrupted, Stream &stream, short events, int timeout);
/** Poll just one file descriptor, waiting for a signal safely **/
static short poll(Stream &stream, short events, const timespec * tmo_p, const sigset_t * sigmask);
/** Poll just one file descriptor, waiting for a signal safely **/
static short poll(bool &interrupted, Stream &stream, short events, const timespec * tmo_p, const sigset_t * sigmask);
private:
std::vector<struct pollfd> pollfds;
};
}
#endif