-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSocketSet.h
More file actions
51 lines (43 loc) · 992 Bytes
/
SocketSet.h
File metadata and controls
51 lines (43 loc) · 992 Bytes
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
#ifndef SOCKETSET_H
#define SOCKETSET_H
#include "BasicLib.h"
#include "SocketLibTypes.h"
#include "SocketLibSocket.h"
#include <set>
namespace SocketLib
{
const int MAX = FD_SETSIZE;
class SocketSet
{
protected:
fd_set m_set;
fd_set m_activityset;
// for linux only since select()
// in linux require the largest decriptor+1
#ifndef WIN32
std::set<sock> m_socketdescs;
#endif
public:
SocketSet();
void AddSocket(const Socket& p_sock);
void RemoveSocket(const Socket& p_sock);
inline int Poll(long p_time = 0)
{
// how long will select() wait
struct timeval t = { 0,p_time * 1000 };
m_activityset = m_set;
#ifdef WIN32
return select(0, &m_activityset, 0, 0, &t);
#else
if (m_socketdescs.size() == 0)
return 0;
return select(*(m_socketdescs.rbegin()) + 1; &m_activityset, 0, 0, &t);
#endif // WIN32
}
inline bool HasActivity(const Socket& p_sock)
{
return FD_ISSET(p_sock.GetSock(), &m_activityset) != 0;
}
};
}
#endif