-
Notifications
You must be signed in to change notification settings - Fork 0
/
connections_thread.h
57 lines (43 loc) · 1.23 KB
/
connections_thread.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
#ifndef CONNECTIONTHREAD_H
#define CONNECTIONTHREAD_H
#include<list>
#include<unordered_map>
#include<mutex>
#include<thread>
#include <functional>
#include <memory>
#include<sys/epoll.h>
#include"connection.h"
using namespace std;
using ConnectionFunc=function<void(shared_ptr<Connection>conn)>;
class ConnectionsThread
{
public:
ConnectionsThread(const ConnectionsThread& ) = delete;
ConnectionsThread& operator = (const ConnectionsThread& ) = delete;
ConnectionsThread(Rester* server, int max_connection);
~ConnectionsThread()
{
running_= false;
connections_new_.clear();
//connections_removed_.clear();
//connections_.clear();
connection_thread_.join();
}
void Init();
void AddConnection(ConnectionPtr conn);
void DeleteConnection(ConnectionPtr conn);
Rester* server_;
thread connection_thread_;
atomic<bool> running_{true};
int max_connection_;
int epoll_fd_;
mutex mutex_new_;
list<ConnectionPtr> connections_new_;
unordered_map<int,ConnectionPtr> fds_connections_;
// mutex mutex_removed_;
// list<ConnectionPtr> connections_removed_;
private:
int AddConnectionTrue(ConnectionPtr conn);
};
#endif // CONNECTIONTHREAD_H