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