[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sharing a file descriptor with a port

From: Cedric Cellier
Subject: sharing a file descriptor with a port
Date: Fri, 17 Sep 2010 11:30:46 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

Support I open a file, then make a port with the file description (with
scm_fdopen), then I close the file description. When the port will be
garbage collected the GC will attempt to close the port->fdes, ignoring
the EBADF error, so everything is OK.

Now supose I do this in a loop. The next open will probably return me
the same fd number. If the GC is triggered now, the previous port might
be collected and it's fdes closed, thus closing my new file !

To circumvent this problem I was setting the revealed count to 1, but
then the port are no more garbage collected. I can't find a way out of
this trap, so I'm looking for a way to either force the garbage
collection of a given port when I know that it's safe to close the port,
or a way to reset port->fdes to -1 so that the destruction of this port
in the future won't lead to a close.

So now I'm planning to never close my files and let the GC do this, but
this causes all kind of problems (apart from fdes exhaustion, some other
programs use the close of these files as a trigger to some

Any idea someone ?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]