-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathTimeoutServer.cpp
More file actions
executable file
·50 lines (38 loc) · 972 Bytes
/
TimeoutServer.cpp
File metadata and controls
executable file
·50 lines (38 loc) · 972 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
44
45
46
47
48
49
50
#include "TimeoutServer.h"
#include "HttpRequest.h"
#include "LibeventLog.h"
int g_flag = 1;
int times = 0;
TimeoutServer::TimeoutServer(void) {
timeout = NULL;
}
TimeoutServer::~TimeoutServer(void) {
if (timeout != NULL) {
event_free(timeout);
}
LibeventLog::userLog("TimeoutServer exit ...");
}
static void timeout_cb(evutil_socket_t fd, short event, void *arg) {
if (g_flag)
g_flag = 0;
times++;
if (times >= 5)
event_base_loopbreak((struct event_base *)arg);
}
int TimeoutServer::listen(struct event_base* base) {
timeout = event_new(base, -1, EV_PERSIST, timeout_cb, base);
evutil_timerclear(&tv);
tv.tv_sec = 3;
tv.tv_usec = 0;
int ret = event_add(timeout, &tv);
if (ret) {
printf("err init event: %d\n", ret);
return -1;
}
LibeventLog::userLog("TimeoutServer start ...");
return 0;
}
MessageHandler *TimeoutServer::createMsgHandler() {
//create MessageHandler
return NULL;
}