unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* sharing a file descriptor with a port
@ 2010-09-17  9:30 Cedric Cellier
  2010-09-17 21:03 ` Thien-Thi Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: Cedric Cellier @ 2010-09-17  9:30 UTC (permalink / raw)
  To: guile-user

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
processing...)

Any idea someone ?




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sharing a file descriptor with a port
  2010-09-17  9:30 sharing a file descriptor with a port Cedric Cellier
@ 2010-09-17 21:03 ` Thien-Thi Nguyen
  2010-09-18  6:29   ` rixed
  0 siblings, 1 reply; 4+ messages in thread
From: Thien-Thi Nguyen @ 2010-09-17 21:03 UTC (permalink / raw)
  To: Cedric Cellier; +Cc: guile-user

() Cedric Cellier <rixed@happyleptic.org>
() Fri, 17 Sep 2010 11:30:46 +0200

   Any idea someone ?

Perhaps you can make a port first; then use ‘port->fdes’
for file-descriptor based access; then close the port.
IOW, start w/ the higher abstraction (port) and let gc DTRT.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sharing a file descriptor with a port
  2010-09-17 21:03 ` Thien-Thi Nguyen
@ 2010-09-18  6:29   ` rixed
  2010-09-18 18:57     ` Thien-Thi Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: rixed @ 2010-09-18  6:29 UTC (permalink / raw)
  To: guile-user

-[ Fri, Sep 17, 2010 at 11:03:13PM +0200, Thien-Thi Nguyen ]----
> Perhaps you can make a port first; then use ???port->fdes???
> for file-descriptor based access; then close the port.

Wait a minute, you can close a port ?
... check check check ...
Ooooooookay. I might be blind somehow : Althoug I did see the fport_close()
function, I though it was only called by fport_free(). Of course
there is this nice scm_close_port function that calls it too, and
then destroys the port.
This is what I was after. Now I can close the file and destroy the port
too.

Thank you for the hint ! :)

Ashamedly yours,




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sharing a file descriptor with a port
  2010-09-18  6:29   ` rixed
@ 2010-09-18 18:57     ` Thien-Thi Nguyen
  0 siblings, 0 replies; 4+ messages in thread
From: Thien-Thi Nguyen @ 2010-09-18 18:57 UTC (permalink / raw)
  To: rixed; +Cc: guile-user

() rixed@happyleptic.org
() Sat, 18 Sep 2010 08:29:28 +0200

   Wait a minute, you can close a port ?

You can try; whether or not (and how) Guile obliges your request
is always a separate matter.

   [...]
   Thank you for the hint ! :)

   Ashamedly yours,

No worries.  I see your shame and raise it: my own for having so much
Guile hacking on my plate for so long (announced, scheduled, but not yet
manifested).  Helping you is my way of procrastinating / repenting.

Actually, to be honest, i see no shame in missing things.  All those
neutrinos don't seem to mind, despite their direction and energy...



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-09-18 18:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-17  9:30 sharing a file descriptor with a port Cedric Cellier
2010-09-17 21:03 ` Thien-Thi Nguyen
2010-09-18  6:29   ` rixed
2010-09-18 18:57     ` Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).