OLD | NEW |
1 /* | 1 /* |
2 * Compile with: | 2 * Compile with: |
3 * cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent | 3 * cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent |
4 */ | 4 */ |
5 #ifdef HAVE_CONFIG_H | 5 #ifdef HAVE_CONFIG_H |
6 #include "config.h" | 6 #include "config.h" |
7 #endif | 7 #endif |
8 | 8 |
9 | 9 |
10 #ifdef WIN32 | 10 #ifdef WIN32 |
11 #include <winsock2.h> | 11 #include <winsock2.h> |
12 #endif | 12 #endif |
13 #include <sys/types.h> | 13 #include <sys/types.h> |
14 #include <sys/stat.h> | 14 #include <sys/stat.h> |
| 15 #ifdef HAVE_SYS_TIME_H |
15 #include <sys/time.h> | 16 #include <sys/time.h> |
| 17 #endif |
16 #ifdef HAVE_SYS_SOCKET_H | 18 #ifdef HAVE_SYS_SOCKET_H |
17 #include <sys/socket.h> | 19 #include <sys/socket.h> |
18 #endif | 20 #endif |
19 #include <fcntl.h> | 21 #include <fcntl.h> |
20 #include <stdlib.h> | 22 #include <stdlib.h> |
21 #include <stdio.h> | 23 #include <stdio.h> |
22 #include <string.h> | 24 #include <string.h> |
| 25 #ifdef HAVE_UNISTD_H |
23 #include <unistd.h> | 26 #include <unistd.h> |
| 27 #endif |
24 #include <errno.h> | 28 #include <errno.h> |
25 | 29 |
26 #include <event.h> | 30 #include <event.h> |
27 #include <evutil.h> | 31 #include <evutil.h> |
28 | 32 |
29 int test_okay = 1; | 33 int test_okay = 1; |
30 int called = 0; | 34 int called = 0; |
31 | 35 |
32 static void | 36 static void |
33 read_cb(int fd, short event, void *arg) | 37 read_cb(int fd, short event, void *arg) |
34 { | 38 { |
35 char buf[256]; | 39 char buf[256]; |
36 int len; | 40 int len; |
37 | 41 |
38 » len = read(fd, buf, sizeof(buf)); | 42 » len = recv(fd, buf, sizeof(buf), 0); |
39 | 43 |
40 printf("%s: read %d%s\n", __func__, | 44 printf("%s: read %d%s\n", __func__, |
41 len, len ? "" : " - means EOF"); | 45 len, len ? "" : " - means EOF"); |
42 | 46 |
43 if (len) { | 47 if (len) { |
44 if (!called) | 48 if (!called) |
45 event_add(arg, NULL); | 49 event_add(arg, NULL); |
46 } else if (called == 1) | 50 } else if (called == 1) |
47 test_okay = 0; | 51 test_okay = 0; |
48 | 52 |
49 called++; | 53 called++; |
50 } | 54 } |
51 | 55 |
52 #ifndef SHUT_WR | 56 #ifndef SHUT_WR |
53 #define SHUT_WR 1 | 57 #define SHUT_WR 1 |
54 #endif | 58 #endif |
55 | 59 |
56 int | 60 int |
57 main (int argc, char **argv) | 61 main (int argc, char **argv) |
58 { | 62 { |
59 struct event ev; | 63 struct event ev; |
60 const char *test = "test string"; | 64 const char *test = "test string"; |
61 int pair[2]; | 65 int pair[2]; |
62 | 66 |
63 if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) | 67 if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) |
64 return (1); | 68 return (1); |
65 | 69 |
66 | 70 |
67 » write(pair[0], test, strlen(test)+1); | 71 » send(pair[0], test, strlen(test)+1, 0); |
68 shutdown(pair[0], SHUT_WR); | 72 shutdown(pair[0], SHUT_WR); |
69 | 73 |
70 /* Initalize the event library */ | 74 /* Initalize the event library */ |
71 event_init(); | 75 event_init(); |
72 | 76 |
73 /* Initalize one event */ | 77 /* Initalize one event */ |
74 event_set(&ev, pair[1], EV_READ, read_cb, &ev); | 78 event_set(&ev, pair[1], EV_READ, read_cb, &ev); |
75 | 79 |
76 event_add(&ev, NULL); | 80 event_add(&ev, NULL); |
77 | 81 |
78 event_dispatch(); | 82 event_dispatch(); |
79 | 83 |
80 return (test_okay); | 84 return (test_okay); |
81 } | 85 } |
82 | 86 |
OLD | NEW |