[erlang-questions] Treating data from open_port as an io_device()

Robert Virding <>
Tue Jul 1 01:53:37 CEST 2008


It is not difficult. An i/o server needs only handle 3 or 4 messages
from user code to be able to handle the whole interface from the io
module. Only the one which does input is mildly difficult. The whole
thing is rather simple actually.

I am in the middle of writing a document which describes some of the
more basic parts of Erlang and the rationale behind them. I/o will be
one part.

I can understand rewriting the io system to make it more efficient,
but not really to make it easier to implement servers in. All that is
missing is just some documentation.

I'll gladly help you actually as I feel that this is something which is lacking.

Robert

On 30/06/2008, Tom Werner <> wrote:
> Can anyone recommend a way to treat the output from an open_port call as an
> io_device() instead of as chunks of data that are delivered to the port's
> controlling process and fetched via receive?
>
> What I want is to use file:read/2 to read from the external process. The
> reason is that data going TO the process already has 4 byte length headers
> on it, so I can't use {packet, 4}. The data coming FROM the process also has
> the headers so I'll need to do length header management myself which is
> difficult (and inefficient) when dealing with chunked data.
>
> Alternatively, is there a way to just create an in-memory io_device() that I
> can use as a fifo? Then I could write the chunked data to the fifo and read
> off the other side. I tried using a posix fifo file but file:open/2 will not
> open it because of {error,eisdir}. It looks like I can open the fifo as a
> port but that leaves me with the same exact problem.
>
> I've looked all over the docs and asked in #erlang but I've seen no way to
> create a simple pipe that I can use for this purpose!
>
> Tom Preston-Werner
> github.com/mojombo
>



More information about the erlang-questions mailing list