MiniDLNA update: 1.0.19.1 to 1.0.20
[tomato.git] / release / src / router / libevent / test / test-weof.c
blobb20f27e1847452d71943baaf976bcf9bd723b625
1 /*
2 * Compile with:
3 * cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent
4 */
5 #include "event2/event-config.h"
7 #ifdef WIN32
8 #include <winsock2.h>
9 #else
10 #include <unistd.h>
11 #endif
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #ifdef _EVENT_HAVE_SYS_TIME_H
15 #include <sys/time.h>
16 #endif
17 #ifdef _EVENT_HAVE_SYS_SOCKET_H
18 #include <sys/socket.h>
19 #endif
20 #include <fcntl.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <signal.h>
25 #include <errno.h>
27 #include "event2/event.h"
28 #include "event2/event_struct.h"
29 #include "event2/event_compat.h"
30 #include "event2/util.h"
32 #ifdef _EVENT___func__
33 #define __func__ _EVENT___func__
34 #endif
36 evutil_socket_t pair[2];
37 int test_okay = 1;
38 int called = 0;
40 static void
41 write_cb(evutil_socket_t fd, short event, void *arg)
43 const char *test = "test string";
44 int len;
46 len = send(fd, test, (int)strlen(test) + 1, 0);
48 printf("%s: write %d%s\n", __func__,
49 len, len ? "" : " - means EOF");
51 if (len > 0) {
52 if (!called)
53 event_add(arg, NULL);
54 evutil_closesocket(pair[0]);
55 } else if (called == 1)
56 test_okay = 0;
58 called++;
61 int
62 main(int argc, char **argv)
64 struct event ev;
66 #ifdef WIN32
67 WORD wVersionRequested;
68 WSADATA wsaData;
69 int err;
71 wVersionRequested = MAKEWORD(2, 2);
73 err = WSAStartup(wVersionRequested, &wsaData);
74 #endif
76 #ifndef WIN32
77 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
78 return (1);
79 #endif
81 if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
82 return (1);
84 /* Initalize the event library */
85 event_init();
87 /* Initalize one event */
88 event_set(&ev, pair[1], EV_WRITE, write_cb, &ev);
90 event_add(&ev, NULL);
92 event_dispatch();
94 return (test_okay);