Hey all, I'm using libev as a part of a larger project. In this project I have a library that does some asynchronous work directly over FDs and timers. While I understand that it's not exactly recommended, these FDs can also be of local files as well as sockets.
As a part of the process, I have an EV_READ event set on a file, in that handler I stop the event handler and close the FD. I then set a timer and in that timer, open another file and set a read event on it. The issue is that the read event on the second file is never called. I've attached a sample code file to show this happening. I'm using libev 4.11 on Ubuntu 12.04 LTS compiling with gcc as follows: gcc ev_test.c -o ev_test -lev I also tried to locally compile 4.15 but the issue reproduced there as well (assuming I did so correctly). It's worth mentioning that if I disable the timer and create the second read event in the first's handler (undef USE_TIMER) everything works as expected. I also tried not closing the FD (commenting out line 36), thus making the second file get a different FD, and that also worked. Changing the timeout value from 0 to anything else didn't help. Can anyone please tell me why this happens? Or, better yet, how I can fix it? Thanks, Assaf
#include <stdlib.h> #include <stdio.h> #include <sys/fcntl.h> #include <ev.h> #define USE_TIMER static ev_io io1, io2; #ifdef USE_TIMER static ev_timer timer1; #endif static char *file1 = "/bin/cp", *file2 = "/bin/mv"; static int fd1, fd2; static void io2_cb(EV_P_ ev_io *w, int revents) { printf("Got read event 2\n"); ev_io_stop(EV_DEFAULT, w); close(fd2); } #ifdef USE_TIMER static void timer1_cb(EV_P_ ev_timer *w, int revents) { fd2 = open(file2, O_RDONLY | O_NONBLOCK); printf("%d\n", fd2); ev_io_init(&io2, io2_cb, fd2, EV_READ); ev_io_start(EV_DEFAULT, &io2); } #endif static void io1_cb(EV_P_ ev_io *w, int revents) { printf("Got read event 1\n"); ev_io_stop(EV_DEFAULT, w); close(fd1); #ifdef USE_TIMER ev_timer_init(&timer1, timer1_cb, 0., 0.); ev_timer_start(EV_DEFAULT, &timer1); #else fd2 = open(file2, O_RDONLY | O_NONBLOCK); printf("%d\n", fd2); ev_io_init(&io2, io2_cb, fd2, EV_READ); ev_io_start(EV_DEFAULT, &io2); #endif } int main (void) { fd1 = open(file1, O_RDONLY | O_NONBLOCK); printf("%d\n", fd1); ev_io_init(&io1, io1_cb, fd1, EV_READ); ev_io_start(EV_DEFAULT, &io1); ev_loop(EV_DEFAULT, 0); return 0; }
_______________________________________________ libev mailing list libev@lists.schmorp.de http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev