callback never invoked
schmorp at schmorp.de
Sun Oct 25 15:28:51 CET 2020
On Sun, Oct 18, 2020 at 02:46:44PM +0500, rustahm <rustahm at gmail.com> wrote:
> libev++ to watch a directory of files and call the callback function as
> soon as inotify gives at least one relevant event. And I don't want libev++
> to block my main program, that's why I tried to use it with NOWAIT.
All event libraries block at least one thread. You coulöd move that into
something other than your main thread, but that complicates things so I would
not reocmmend that.
> Am I doing it totally wrong? Is libev++ a right tool for the task?
I am not sure what you are trying to achieve, but libev (not libev++) does
kind of impose event-based programming on the user. You could use it
differently, but that would be very advanced, and possibly also painful.
So if you can't use an event-based approach and do you work in callbacks,
libev (or any other event library) would be the wrong tool.
> If I add ev_run(EV_A_ 0); to engage_watcher() I get use of undeclared
> identifier 'loop'.
You cna either use "ev_run (ev_default_loop (), 0)" or, if you have more
than one loop, pass the "struct ev_loop *" around. There is also a macro
you can use "ev_run (EV_DEFAULT_UC_ 0)" that is faster than calling
ev_default_loop if the loop is guartanteed to be initialiased already.
> and run the program but it gets blocked until I change a file in the
> directory being watched.
Yes, that's how it works. You need to cal ev_run in your main program and
do your work in callbacks, always returning to the main loop.
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
More information about the libev