[erlang-questions] Determine if a binary is ref-counted in port driver code

Gustav Simonsson gustav.simonsson@REDACTED
Fri May 13 14:18:07 CEST 2011


This post talks about how the SysIOVec field in ErlIOVec gets its value depending
on the properties of the binaries in the io list:

http://www1.erlang.org/pipermail/erlang-questions/2002-October/005859.html
and the reply
http://www1.erlang.org/pipermail/erlang-questions/2002-October/005860.html

It's from 2002 so the behaviour might be different, but the code
referenced in the post does checks on the binaries in the io list in order to determine what todo.

See erts_write_to_port (line 1085) and io_list_vec_len (line 999) in 
https://github.com/erlang/otp/blob/dev/erts/emulator/beam/io.c

Best Regards,
Gustav Simonsson



----- Original Message -----
From: "Tim Watson" <watson.timothy@REDACTED>
To: "Gustav Simonsson" <gustav.simonsson@REDACTED>
Cc: erlang-questions@REDACTED
Sent: Friday, May 13, 2011 1:06:45 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: Re: [erlang-questions] Determine if a binary is ref-counted in port driver code

> From http://www.erlang.org/doc/man/erl_driver.html
>
> "The ErlDrvBinary structure is a binary, as sent between the emulator and the driver. All binaries are reference counted"
>
> Also, this and the following functions might be of use:
> http://www.erlang.org/doc/man/erl_driver.html#driver_binary_get_refc

Thanks for the timely response Gustav. That seems to refer to the
ErlDrvBinary that is passed between the emulator and the driver. When
an iolist of binaries is passed to port_command, for each entry in the
ErlIOVec passed to driver_outputv, the data will only be stored in the
binv field *if* the binary is not heap allocated. If it is a
small/heap-allocated binary, then the data will appear in the iov
field instead. In this (latter) case, there is no ErlDrvBinary to
examine and the data is present in the iov_base field of the SysIOVec
stored in ev->iov[index].

What I'm trying to ascertain is whether or not there is a way to tell
whether a given entry in the ErlIOVec structure will reside in the
binv or iov field. Have I misunderstood the way this works? The
documentation is a little scant, but this thread appears to cover the
issue to some extent:
http://erlang.org/pipermail/erlang-questions/2006-August/021904.html.



More information about the erlang-questions mailing list