empty loop, adding watchers, one minute idle

Zoltán Lajos Kis zoltan.lajos.kis at gmail.com
Mon Mar 19 21:58:24 CET 2012


In my application I am capturing packets from ethernet ports; where the
ports are dynamically (de)selected. For this task I have a dedicated
thread, running a libev event loop.

Initially I spawn a pthread, and start an event loop in it with no attached
watchers. I use the ev_ref() call just before ev_run() to prevent the empty
loop from exiting.
Then, when a request arrives, I open a packet-socket for an ethernet port,
create an io watcher for the socket, and start the socket on the started
loop. (note: the request processing, and watcher preparation is done on
another thread.)
What I am experiencing is that if I send packets to the monitored ports, I
get no immediate results. However, roughly after one minute (since starting
the loop?) the events show up as they were buffered, and from that time
packets are
received as expected. My speculation is that the loop - being empty - goes
into some sort of idle mode, and only comes back after 60 seconds to check
if any watchers were added in the meantime. Is this correct?

What I do now is that I set up an async watcher and a message queue to the
thread. Then instead of starting the watcher, I put the watcher ('s
pointer) to the queue, and notify the loop about this using the async
watcher. Then
the watcher is started in the async's callback (running in the loop's
thread). This seems to work, but looks a lot more complex than I'd expect
it to be.

My question is whether someone could explain me what is actually going on,
and what would be a cleaner solution for the problem.

Thank you,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20120319/39eccbae/attachment.html>

More information about the libev mailing list