-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoll.cc
49 lines (40 loc) · 899 Bytes
/
poll.cc
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
#include "poll.h"
void MY_fd_set::set( int s, short status )
{
std::unordered_map<int,int>::const_iterator it = fd_to_pollfd.find( s );
if( it == fd_to_pollfd.end() )
{
fd_to_pollfd.insert( std::unordered_map<int,int>::value_type( s, pollfds.size() ) );
struct pollfd pollfd;
pollfd.fd = s;
pollfd.events = status;
pollfd.revents = 0;
pollfds.push_back( pollfd );
}
else
{
pollfds[it->second].events |= status;
}
}
bool MY_fd_set::isset( int s, short status )
{
std::unordered_map<int,int>:: const_iterator it = fd_to_pollfd.find( s );
if( it == fd_to_pollfd.end() )
{
return false;
}
return pollfds[it->second].revents & status;
}
void MY_fd_set::clear()
{
pollfds.clear();
fd_to_pollfd.clear();
}
int MY_fd_set::size()
{
return pollfds.size();
}
pollfd * MY_fd_set::data()
{
return pollfds.data();
}