3 * cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent
5 #include "event2/event-config.h"
12 #include <sys/types.h>
14 #ifdef _EVENT_HAVE_SYS_TIME_H
17 #ifdef _EVENT_HAVE_SYS_SOCKET_H
18 #include <sys/socket.h>
29 #ifdef _EVENT___func__
30 #define __func__ _EVENT___func__
35 struct timeval timeout
= {60, 0};
38 read_cb(evutil_socket_t fd
, short event
, void *arg
)
43 if (EV_TIMEOUT
& event
) {
44 printf("%s: Timeout!\n", __func__
);
48 len
= recv(fd
, buf
, sizeof(buf
), 0);
50 printf("%s: read %d%s\n", __func__
,
51 len
, len
? "" : " - means EOF");
55 event_add(arg
, &timeout
);
56 } else if (called
== 1)
67 main(int argc
, char **argv
)
70 const char *test
= "test string";
71 evutil_socket_t pair
[2];
74 WORD wVersionRequested
;
78 wVersionRequested
= MAKEWORD(2, 2);
80 err
= WSAStartup(wVersionRequested
, &wsaData
);
83 if (evutil_socketpair(AF_UNIX
, SOCK_STREAM
, 0, pair
) == -1)
87 send(pair
[0], test
, (int)strlen(test
)+1, 0);
88 shutdown(pair
[0], SHUT_WR
);
90 /* Initalize the event library */
93 /* Initalize one event */
94 event_set(&ev
, pair
[1], EV_READ
| EV_TIMEOUT
, read_cb
, &ev
);
96 event_add(&ev
, &timeout
);