closing fd while in loop

Marc Lehmann schmorp at schmorp.de
Sun Mar 2 21:05:51 CET 2014


On Sun, Mar 02, 2014 at 08:27:53PM +0100, Nicolas Van Eenaeme <nicolas at massivemedia.eu> wrote:
> Do we need to stop the watchers before closing the fd, or the way around?

Before.

> Since in the documentation it says for EVBACKEND_EPOLL:

> "Best performance from this backend is achieved by not unregistering all
> watchers for a file descriptor until it has been closed, if possible, i.e.

This is correct. Still, when you close it, you have to stop the watchers
first.

Stopping a watcher with a bad fd is a bug.

> Or doesn't it make that much difference?

This comment is clearly about performanc,e not correctness. You do get the
best performance by not unnecessarily stopping and starting watchers. Before
closing the fd, however, you must stop all watchers.

Not doing is is pretty much like clearing a memory region after it being
freed. With that image in mind, the comment about performance amounts to
reusing the memory area you got until you free it is best for performance.

-- 
                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 mailing list