-
Notifications
You must be signed in to change notification settings - Fork 0
/
Poll.cpp
78 lines (61 loc) · 2.69 KB
/
Poll.cpp
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
/*******************************************************************************
* libunix++: C++ wrapper for Linux system calls
* Polling operations
*
* © 2020—2021, Sauron <[email protected]>
******************************************************************************/
#include "exception.hppi"
#include "Poll.hpp"
using namespace upp;
using std::vector;
static unsigned _poll(pollfd * pollfds, size_t count, int timeout) {
NORMAL_IO_WRAPPER(int, unsigned, ::poll(pollfds, count, timeout));
}
static unsigned _poll(bool &interrupted, pollfd * pollfds, size_t count, int timeout) {
INTERRUPTED_IO_WRAPPER(int, unsigned, ::poll(pollfds, count, timeout));
}
static unsigned _poll(pollfd * pollfds, size_t count, const timespec * tmo_p, const sigset_t * sigmask) {
NORMAL_IO_WRAPPER(int, unsigned, ::ppoll(pollfds, count, tmo_p, sigmask));
}
static unsigned _poll(bool &interrupted, pollfd * pollfds, size_t count, const timespec * tmo_p, const sigset_t * sigmask) {
INTERRUPTED_IO_WRAPPER(int, unsigned, ::ppoll(pollfds, count, tmo_p, sigmask));
}
Poll::Poll(const vector<Stream> &streams, short events) : pollfds(streams.size()) {
for (size_t i=0; i<streams.size(); i++)
pollfds[i]={streams[i].fd, events, 0};
}
void Poll::add(const Stream &stream, short events) {
pollfds.push_back({stream.fd, events, 0});
}
unsigned Poll::poll(int timeout) {
return _poll(pollfds.data(), pollfds.size(), timeout);
}
unsigned Poll::poll(bool &interrupted, int timeout) {
return _poll(interrupted, pollfds.data(), pollfds.size(), timeout);
}
unsigned Poll::poll(const timespec * tmo_p, const sigset_t * sigmask) {
return _poll(pollfds.data(), pollfds.size(), tmo_p, sigmask);
}
unsigned Poll::poll(bool &interrupted, const timespec * tmo_p, const sigset_t * sigmask) {
return _poll(interrupted, pollfds.data(), pollfds.size(), tmo_p, sigmask);
}
short Poll::poll(Stream &stream, short events, int timeout) {
struct pollfd pollfd={stream.fd, events, 0};
_poll(&pollfd, 1, timeout);
return pollfd.revents;
}
short Poll::poll(bool &interrupted, Stream &stream, short events, int timeout) {
struct pollfd pollfd={stream.fd, events, 0};
_poll(interrupted, &pollfd, 1, timeout);
return pollfd.revents;
}
short Poll::poll(Stream &stream, short events, const timespec * tmo_p, const sigset_t * sigmask) {
struct pollfd pollfd={stream.fd, events, 0};
_poll(&pollfd, 1, tmo_p, sigmask);
return pollfd.revents;
}
short Poll::poll(bool &interrupted, Stream &stream, short events, const timespec * tmo_p, const sigset_t * sigmask) {
struct pollfd pollfd={stream.fd, events, 0};
_poll(interrupted, &pollfd, 1, tmo_p, sigmask);
return pollfd.revents;
}