forked from gozfree/gear-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_libgevent.c
49 lines (44 loc) · 1.11 KB
/
test_libgevent.c
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
/******************************************************************************
* Copyright (C) 2014-2015
* file: test_libgevent.c
* author: gozfree <[email protected]>
* created: 2016-04-10 12:51
* updated: 2016-04-10 12:51
******************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/sysinfo.h>
#include <liblog.h>
#include "libgevent.h"
static void on_input(int fd, void *arg)
{
logi("input %d", fd);
}
static int foo(void)
{
int fd = 0;
struct gevent_base *evbase = gevent_base_create();
if (!evbase) {
loge("gevent_base_create failed!\n");
return -1;
}
struct gevent *event = gevent_create(fd, on_input, NULL, NULL, NULL);
if (!event) {
loge("gevent_create failed!\n");
return -1;
}
if (-1 == gevent_add(evbase, event)) {
loge("gevent_add failed!\n");
return -1;
}
gevent_base_loop(evbase);
gevent_del(evbase, event);
gevent_base_destroy(evbase);
return 0;
}
int main(int argc, char **argv)
{
foo();
return 0;
}