| 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> |
| 23 #include <signal.h> | 25 #include <signal.h> |
| 26 #ifdef HAVE_UNISTD_H |
| 24 #include <unistd.h> | 27 #include <unistd.h> |
| 28 #endif |
| 25 #include <errno.h> | 29 #include <errno.h> |
| 26 | 30 |
| 27 #include <event.h> | 31 #include <event.h> |
| 28 #include <evutil.h> | 32 #include <evutil.h> |
| 29 | 33 |
| 30 int pair[2]; | 34 int pair[2]; |
| 31 int test_okay = 1; | 35 int test_okay = 1; |
| 32 int called = 0; | 36 int called = 0; |
| 33 | 37 |
| 34 static void | 38 static void |
| 35 write_cb(int fd, short event, void *arg) | 39 write_cb(int fd, short event, void *arg) |
| 36 { | 40 { |
| 37 const char *test = "test string"; | 41 const char *test = "test string"; |
| 38 int len; | 42 int len; |
| 39 | 43 |
| 40 » len = write(fd, test, strlen(test) + 1); | 44 » len = send(fd, test, strlen(test) + 1, 0); |
| 41 | 45 |
| 42 printf("%s: write %d%s\n", __func__, | 46 printf("%s: write %d%s\n", __func__, |
| 43 len, len ? "" : " - means EOF"); | 47 len, len ? "" : " - means EOF"); |
| 44 | 48 |
| 45 if (len > 0) { | 49 if (len > 0) { |
| 46 if (!called) | 50 if (!called) |
| 47 event_add(arg, NULL); | 51 event_add(arg, NULL); |
| 48 » » close(pair[0]); | 52 » » EVUTIL_CLOSESOCKET(pair[0]); |
| 49 } else if (called == 1) | 53 } else if (called == 1) |
| 50 test_okay = 0; | 54 test_okay = 0; |
| 51 | 55 |
| 52 called++; | 56 called++; |
| 53 } | 57 } |
| 54 | 58 |
| 55 int | 59 int |
| 56 main (int argc, char **argv) | 60 main (int argc, char **argv) |
| 57 { | 61 { |
| 58 struct event ev; | 62 struct event ev; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 71 /* Initalize one event */ | 75 /* Initalize one event */ |
| 72 event_set(&ev, pair[1], EV_WRITE, write_cb, &ev); | 76 event_set(&ev, pair[1], EV_WRITE, write_cb, &ev); |
| 73 | 77 |
| 74 event_add(&ev, NULL); | 78 event_add(&ev, NULL); |
| 75 | 79 |
| 76 event_dispatch(); | 80 event_dispatch(); |
| 77 | 81 |
| 78 return (test_okay); | 82 return (test_okay); |
| 79 } | 83 } |
| 80 | 84 |
| OLD | NEW |