Re: fdes (now fd) and port Duy Nguyen 06 Sep 2020 13:31 UTC

On Tue, Aug 18, 2020 at 3:42 AM Shiro Kawai <> wrote:
> fd->*-port can't be implemented portably, so each implementation must work on it, interacting with its own port system.  I'm not sure if a particular implementation has a difficulty to support either way.
> We don't need to worry about ports created by other means, so the implementation doesn't need to change their existing port handling.
> If we have implementations that already have native fd->*-port procedures, but some close fd automatically and others don't, then we have the compatibility problem and can't force either way.  Is it the case?  (Gauche has an optional argument to specify whether the port "owns" the fd or not; if the port owns it, closing port causes closing fd.   So it can support either way.)
> Initially I thought a proper protocol ensures safe closure of ports and fds regardless of the port's ownership of fd

Can fd->*-port dup() the file descriptor instead of reusing and then
the port owns the new fd? Then a port can and must close its fd when
it's closed. The original fd is up to the user to manage. And the OS
is in charge of actually closing the in-kernel file object when all
associated fds are closed.