Another test of EOF ported from libevent.
#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 <csignal>
#include <cerrno>
#include <eventxx>
typedef void (cb_t)(int, short);
int pair[2];
int test_okay = 1;
int called = 0;
void
write_cb(int fd, short event)
{
const char* test = "test string";
int len;
len = write(fd, test, strlen(test) + 1);
printf("%s: write %d%s\n", __func__,
len, len ? "" : " - means EOF");
if (len > 0) {
if (!called)
close(pair[0]);
} else if (called == 1)
test_okay = 0;
called++;
}
int
main (int argc, char **argv)
{
if (signal(SIGPIPE, SIG_IGN) == SIG_IGN)
return (1);
if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
return (1);
delete ev;
return (test_okay);
}
@ WRITE
Write event.
Definition: eventxx:195
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
Generic event object.
Definition: eventxx:301