-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSocket_Poll.h
112 lines (74 loc) · 2.05 KB
/
Socket_Poll.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef SOCKET_POLL
#define SOCKET_POLL
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <vector>
#include "Allocator_Manager.h"
#include "ServiceObj.h"
#include <sys/time.h>
#define T_ACCEPT 1
#define T_CONNECT 2
#define SOCKET_TYPE_DATA 0
#define SOCKET_TYPE_CONNECT 1
#define SOCKET_TYPE_CLOSE 2
#define SOCKET_TYPE_CTRL 3
#define SOCKET_TYPE_TIMEOUT 4
struct connection_st
{
int sock;
int epfd;
int type;
int service_handle;
bool isclose;
Stream_Base* rbuf;
Stream_Base* wbuf;
connection_st()
{
memset(this, 0, sizeof(connection_st));
}
};
#define EPOLL_NUM 6
#define WORKER_PER_GROUP 8
#define NUM_WORKER (EPOLL_NUM * WORKER_PER_GROUP)
static long RecvNums = 0;
static long AllRecv = 0;
static long PerRecv = 0;
static long MaxRecv = 0;
static int CurTimes = 0;
struct socket_server {
socket_server()
{
memset(this, 0, sizeof(socket_server));
}
struct connection_st* slot[65536];
int lisfd_serverid[65536];
int epfd[EPOLL_NUM];
bool shut_server;
pthread_t worker[NUM_WORKER];
};
extern socket_server SOCKET_SERVER;
static void records(int per_recv, int max_recv);
void sigroutine(int signo);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
Stream_Base* make_stream_packet(char *data, int len);
extern int sendData(connection_st* conn, char *data, int len);
static bool parse_stream_head(int fd, Stream_Base& stream, std::vector<Message>& vstream);
static int handleReadEvent(connection_st* conn);
static int handleWriteEvent(connection_st* conn);
extern void closeConnection(int fd);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
extern int do_listen(int handle, int port, int block);
extern int do_accept(connection_st* conn);
extern void do_poll(int epfd);
#endif