-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
43 lines (36 loc) · 995 Bytes
/
main.cpp
File metadata and controls
43 lines (36 loc) · 995 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
42
43
#include "epoll.h"
#include "util.h"
int main()
{
int port = 8888;
ignSigpipe();
std::shared_ptr<ner_epoll> epoll(new ner_epoll());
if(epoll->epoll_init(EVENTS_SIZE) < 0){
fprintf(stderr, "epoll_init is fail.\n");
return 1;
}
ner_threadpool* pool;
if((pool = threadpool_create(1)) == NULL){
fprintf(stderr, "threadpool_init is fail.\n");
return 1;
}
int server_fd = serverfdInit(port);
if(server_fd == -1){
fprintf(stderr, "serverfdInit is fail.\n");
return 1;
}
if(setNonblocking(server_fd) == -1){
fprintf(stderr, "setNonblocking is fail.\n");
return 1;
}
con_ptr t_con(new ner_connect());
t_con->setFd(server_fd);
if(epoll->epoll_add(server_fd, t_con, EPOLLIN | EPOLLET) == -1){
fprintf(stderr, "epoll_add() is fail.\n");
return 1;
}
while(1){
epoll->ner_poll_wait(server_fd, EVENTS_SIZE, -1, pool);
}
return 0;
}