Change version number and update docs about stability.
[eventxx.git] / test / test-eof.cpp
blobc1c05db59219f0cf8bf73258ed5f34e51b5da102
1 /*
2 * Compile with:
3 * c++ -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent
6 * Wed 2006-12-27 - Modified by Leandro Lucarella <llucax+eventxx@gmail.com>
8 * Adapted to test the C++ inteface.
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <sys/time.h>
15 #include <sys/socket.h>
16 #include <fcntl.h>
17 #include <unistd.h>
18 #include <cstdlib>
19 #include <cstdio>
20 #include <cstring>
21 #include <cerrno>
23 #include <eventxx>
25 int test_okay = 1;
26 int called = 0;
27 eventxx::dispatcher d;
28 eventxx::cevent* ev;
30 void
31 read_cb(int fd, short event, void *arg)
33 char buf[256];
34 int len;
36 len = read(fd, buf, sizeof(buf));
38 printf("%s: read %d%s\n", __func__,
39 len, len ? "" : " - means EOF");
41 if (len) {
42 if (!called)
43 d.add(*ev);
44 } else if (called == 1)
45 test_okay = 0;
47 called++;
50 int
51 main (int argc, char **argv)
53 const char* test = "test string";
54 int pair[2];
56 if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
57 return (1);
59 write(pair[0], test, strlen(test)+1);
60 shutdown(pair[0], SHUT_WR);
62 /* Initalize one event */
63 ev = new eventxx::cevent(pair[1], eventxx::READ, read_cb, NULL);
65 d.add(*ev);
67 d.dispatch();
69 delete ev;
71 return (test_okay);