-
Notifications
You must be signed in to change notification settings - Fork 4
/
fdset.h
72 lines (64 loc) · 1.04 KB
/
fdset.h
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
/**
* FdSet.h
*
* Simple wrapper class around a fd-set
*
* @author Toon Schoenmakers <[email protected]>
* @copyright 2015 Copernica BV
*/
/**
* Include guard
*/
#pragma once
/**
* Dependencies
*/
#include <set>
#include <sys/select.h>
/**
* Class definition
*/
class FdSet
{
private:
/**
* The fd-set
* @var fd_set
*/
fd_set _set;
public:
/**
* Constructor
* @param fds
*/
FdSet(const std::set<int> &fds)
{
// set set to all zero's
FD_ZERO(&_set);
// iterate over the fds
for (auto fd : fds) FD_SET(fd, &_set);
}
/**
* Destructor
*/
virtual ~FdSet() = default;
/**
* Cast to fd-set
* @return fd_set*
*/
operator fd_set* ()
{
// expose member
return &_set;
}
/**
* Check if a filedescriptor is included
* @param fd
* @return bool
*/
bool contains(int fd) const
{
// check
return FD_ISSET(fd, &_set);
}
};