10 #include <sys/types.h>
13 #include <sys/queue.h>
28 fifo_read(
int fd,
short event,
void *arg)
32 struct event *ev = arg;
40 fprintf(stderr,
"fifo_read called with fd: %d, event: %d, arg: %p\n",
43 len = ReadFile((HANDLE)fd, buf,
sizeof(buf) - 1, &dwBytesRead, NULL);
46 if(len && dwBytesRead == 0) {
47 fprintf(stderr,
"End Of File");
52 buf[dwBytesRead] =
'\0';
54 len = read(fd, buf,
sizeof(buf) - 1);
59 }
else if (len == 0) {
60 fprintf(stderr,
"Connection closed\n");
66 fprintf(stdout,
"Read: %s\n", buf);
70 main (
int argc,
char **argv)
76 socket = CreateFile(
"test.txt",
81 FILE_ATTRIBUTE_NORMAL,
84 if(socket == INVALID_HANDLE_VALUE)
89 const char *fifo =
"event.fifo";
92 if (lstat (fifo, &st) == 0) {
93 if ((st.st_mode & S_IFMT) == S_IFREG) {
101 if (mkfifo (fifo, 0600) == -1) {
108 socket = open (fifo, O_RDWR | O_NONBLOCK, 0);
110 socket = open (fifo, O_RDONLY | O_NONBLOCK, 0);
118 fprintf(stderr,
"Write data to %s\n", fifo);
125 event_set(&evfifo, (
int)socket, EV_READ, fifo_read, &evfifo);
127 event_set(&evfifo, socket, EV_READ, fifo_read, &evfifo);
131 event_add(&evfifo, NULL);