#include <assert.h>
#include <ev.h>
#include <ev.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
static void
child_read_cb(struct ev_loop *loop, ev_io *w, int revents)
{
int fd = w->fd;
char s[1024];
ssize_t n = read(fd, s, 1023);
assert(n >= 0);
s[n] = '\0';
printf(">>> Got line <%s>\n", s);
}
int
main(int argc, char *argv[])
{
struct ev_loop *loop = ev_default_loop(0);
ev_io read_ev;
int fds[2], psock, csock;
assert(socketpair(PF_UNIX, SOCK_STREAM, 0, fds) == 0);
psock = fds[0];
csock = fds[1];
assert(fcntl(psock, F_SETFD, FD_CLOEXEC) == 0);
assert(fcntl(psock, F_SETFD, O_NONBLOCK) == 0);
if (fork() == 0)
sleep(5);
close(csock);
ev_io_init(&read_ev, child_read_cb, psock, EV_READ);
ev_io_start(loop, &read_ev);
ev_loop(loop, 0);
}