[erlang-questions] Passing Filehandles Between Processes

Paul Mineiro paul-trapexit@REDACTED
Sat Oct 10 18:36:43 CEST 2009


I had to do this as a hack once.  I grabbed the port out of the record and
called erlang:port_connect/2 on it.

------
  #file_descriptor { module = prim_file, data = { Port, _ } } = Device,
  try
    erlang:port_connect (Port, Pid),
    ok
  catch
    error : badarg ->
      { error, badarg }
  end.
------

-- p

On Sat, 10 Oct 2009, Jayson Vantuyl wrote:

> Are there any plans to add something like gen_tcp:controlling_process
> for files?  I don't see any easy way to do it, looking at file.erl
> (and gen_tcp hands it off to some magic in inet).
>
> On Oct 9, 2009, at 4:45 PM, Scott Lystig Fritchie wrote:
>
> > Davide Marquês <nesrait@REDACTED> wrote:
> >
> > dm> - finally, *the process that opened the file must be alive for
> > dm> read/write operations to succeed*.
> >
> > This behavior is pretty clearly documented in the R13B02's reference
> > for
> > the file:open/2 function.  The process linking (for non-raw file
> > handles) or port linking (for raw file handles) is an important way to
> > avoid leaking file handles when processes crash.  It doesn't prevent
> > leaks if a process lives forever but never closes a file handle (or
> > socket, for that matter), but 9/10ths of a pastrami sandwich is better
> > than no sandwich.  :-)
> >
> > -Scott
> >
> > ________________________________________________________________
> > erlang-questions mailing list. See http://www.erlang.org/faq.html
> > erlang-questions (at) erlang.org
>
> --
> Jayson Vantuyl
> kagato@REDACTED
>
>
>
>
>
>



More information about the erlang-questions mailing list