-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.cpp
57 lines (49 loc) · 1.2 KB
/
server.cpp
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
/*
* 程序名:tcpepoll.cpp,此程序用于演示采用epoll模型实现网络通讯的服务端。
*/
/*
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/fcntl.h>
#include <sys/epoll.h>
#include <netinet/tcp.h> // TCP_NODELAY需要包含这个头文件。
#include "InetAddress.h"
#include "Socket.h"
#include "Epoll.h"
#include "Channel.h"
#include "EventLoop.h"
*/
#include "EchoServer.h"
#include <signal.h>
//设置2和15的信号 , 在信号处理函数中停止主从事件循环 3程序主动退出
EchoServer *server;
void Stop(int sig)
{
printf("sig=%d\n",sig);
printf("server stoping...\n");
server->stop();
delete server;
printf("delete server.\n");
exit(0);
}
int main(int argc,char *argv[])
{
if (argc != 3)
{
printf("usage: ./tcpepoll ip port\n");
printf("example: ./tcpepoll 192.168.150.128 5085\n\n");
return -1;
}
signal(SIGTERM,Stop);
signal(SIGINT,Stop);
//参数对应ip,port,IO线程数,Work线程数
server = new EchoServer(argv[1],atoi(argv[2]),32,0);
server->start();
return 0;
}