forked from awwit/httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocketList.h
More file actions
41 lines (32 loc) · 879 Bytes
/
SocketList.h
File metadata and controls
41 lines (32 loc) · 879 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
#pragma once
#include "Socket.h"
#ifdef POSIX
#include <sys/epoll.h>
#include <netinet/in.h>
#endif
namespace HttpServer
{
class SocketList
{
protected:
#ifdef WIN32
HANDLE obj_list;
mutable std::vector<WSAPOLLFD> poll_events;
#elif POSIX
int obj_list;
mutable std::vector<struct ::epoll_event> epoll_events;
#else
#error "Undefine platform"
#endif
public:
SocketList();
bool create(const size_t startListSize = 1);
void destroy();
bool is_created() const;
bool addSocket(const Socket &sock);
bool removeSocket(const Socket &sock);
bool accept(std::vector<Socket> &sockets) const;
bool accept(std::vector<Socket> &sockets, std::vector<struct sockaddr_in> &socketsAddress) const;
bool recv(std::vector<Socket> &sockets, std::vector<Socket> &errors, std::chrono::milliseconds timeout = std::chrono::milliseconds(~0) ) const;
};
};