On Tue, May 31, 2011 at 09:01:25PM +0000, David Golombek
<[email protected]> wrote:
> I'm seeing a situation where I get a read callback for a watcher on a socket
> that was recently closed due to a write error. This is with 4.03, testing on
> my Mac 10.6.7 laptop. The sequence I'm seeing:
>
> 1) Writing to the socket fails
> 2) I call ev_io_stop for that connection
> 3) I call close on the associated FD
> 4) I free the memory for the watcher
> 5) My read callback is later called with the now-freed watcher, revents ==
> EV_READ
> 6) I try to read the FD again, that fails
> 7) I double free the watcher (after calling ev_io_stop again)
> 8) Fun ensues
>
> I'm calling ev_io_init with only EV_READ, not EV_WRITE, and I suspect that's
> part of the problem here, but this behavior still seems poor. Why would my
> callback still be invoked after I call ev_io_stop on the watcher? Is there
> any way to stop the watcher when writing fails?
I do not believe what you describe actually happens - when you call
ev_io_stop on a watcher, then this watcher will not invoke its callback
anymore.
If you still get invocations, then you didn't stop the watcher, started it
again somewhere, or corrupted some internal libev data structure or the
watcher.
In all cases, this indicates a bug in your code somewhere.
Make sure you do not call ev_init on a started watcher, do not move the
watcher as long as it is active, or free it as long as it is active -
always make sure that the watcher is stopped and not pending before you
do any of these things (ev_TYPE_stop ensures both, but requires a valid
watcher).
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / [email protected]
-=====/_/_//_/\_,_/ /_/\_\
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev