eventxx  1.0.1
test-eof.cpp

This is some kind of test of EOF ported from libevent.

/*
* Compile with:
* c++ -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent
*
*
* Wed 2006-12-27 - Modified by Leandro Lucarella <llucax+eventxx@gmail.com>
*
* Adapted to test the C++ inteface.
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cerrno>
#include <eventxx>
int test_okay = 1;
int called = 0;
void
read_cb(int fd, short event, void *arg)
{
char buf[256];
int len;
len = read(fd, buf, sizeof(buf));
printf("%s: read %d%s\n", __func__,
len, len ? "" : " - means EOF");
if (len) {
if (!called)
d.add(*ev);
} else if (called == 1)
test_okay = 0;
called++;
}
int
main (int argc, char **argv)
{
const char* test = "test string";
int pair[2];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
return (1);
write(pair[0], test, strlen(test)+1);
shutdown(pair[0], SHUT_WR);
/* Initalize one event */
ev = new eventxx::cevent(pair[1], eventxx::READ, read_cb, NULL);
d.add(*ev);
d.dispatch();
delete ev;
return (test_okay);
}
eventxx::event< ccallback_type > cevent
Shortcut to C-style event.
Definition: eventxx:488
@ READ
Read event.
Definition: eventxx:194
Event dispatcher.
Definition: eventxx:549
int dispatch(int flags=0)
Main dispatcher loop.
Definition: eventxx:764
void add(basic_event &e, int priority=DEFAULT_PRIORITY)
Adds an event to the dispatcher.
Definition: eventxx:588
This is the specialization of eventxx::event for C-style callbacks.
Definition: eventxx:336