-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.h
57 lines (40 loc) · 1.08 KB
/
Server.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
//
// Created by Administrator on 2019/9/24 0024.
//
#ifndef WEBSOCKET_SERVER_H
#define WEBSOCKET_SERVER_H
#include "public.h"
#include "SystemCallException.h"
#include "EventCallback.h"
#include "Event.h"
extern EventLoop global_event_loop;//event system
class Server : public EventCallback {
protected:
int port;//server port
Socket_t sock;//server listen socket
sockaddr_in addr;
socklen_t sock_len;
int back_log;
timeval time_out;
Socket_t client_connected;
void CreateSocket();
public:
Server() = default;
explicit Server(int port, uint32_t ad, int back_log) {
this->port = port;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(ad);
sock_len = sizeof(addr);
this->back_log = back_log;
time_out.tv_sec = 0;
time_out.tv_usec = 0;
}
void Bind();
void Listen();
void Loop();
void WaitClient();
bool Handle(bool socket_should_close, void *event_loop) override;
void CloseListenSocket();
};
#endif //WEBSOCKET_SERVER_H