2004-02-12 18:55:09 +03:00
|
|
|
/*
|
|
|
|
* Compile with:
|
|
|
|
* cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent
|
|
|
|
*/
|
|
|
|
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2004-02-12 18:55:09 +03:00
|
|
|
#include <sys/types.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-02-12 18:55:09 +03:00
|
|
|
#include <sys/stat.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
2004-02-12 18:55:09 +03:00
|
|
|
#include <sys/time.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
2004-02-12 18:55:09 +03:00
|
|
|
#include <sys/socket.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-02-12 18:55:09 +03:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <signal.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-02-12 18:55:09 +03:00
|
|
|
#include <unistd.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-02-12 18:55:09 +03:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <event.h>
|
|
|
|
|
|
|
|
int pair[2];
|
|
|
|
int test_okay = 1;
|
|
|
|
int called = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
write_cb(int fd, short event, void *arg)
|
|
|
|
{
|
|
|
|
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)
|
2005-07-04 03:09:55 +04:00
|
|
|
opal_event_add(arg, NULL);
|
2004-02-12 18:55:09 +03:00
|
|
|
close(pair[0]);
|
|
|
|
} else if (called == 1)
|
|
|
|
test_okay = 0;
|
|
|
|
|
|
|
|
called++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2005-07-04 03:09:55 +04:00
|
|
|
struct opal_event ev;
|
2004-02-12 18:55:09 +03:00
|
|
|
|
|
|
|
if (signal(SIGPIPE, SIG_IGN) == SIG_IGN)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
/* Initalize the event library */
|
2005-07-04 03:09:55 +04:00
|
|
|
opal_event_init();
|
2004-02-12 18:55:09 +03:00
|
|
|
|
|
|
|
/* Initalize one event */
|
2005-07-04 03:09:55 +04:00
|
|
|
opal_event_set(&ev, pair[1], OPAL_EV_WRITE, write_cb, &ev);
|
|
|
|
opal_event_add(&ev, NULL);
|
|
|
|
opal_event_dispatch();
|
2004-02-12 18:55:09 +03:00
|
|
|
|
|
|
|
return (test_okay);
|
|
|
|
}
|
|
|
|
|