[erlang-questions] Linked-in drivers: output and control callbacks

Torben Hoffmann torben.lehoff@REDACTED
Fri Dec 14 08:51:56 CET 2007


On Dec 13, 2007 10:41 PM, Vance Shipley <vances@REDACTED> wrote:

> On Thu, Dec 13, 2007 at 06:31:06PM +0000, Joel Reymont wrote:
> }  My understanding is that Port ! {self(),  {command,  Data}} triggers
> }  output whereas port_command(Port, Data)  triggers control.
> }
> }  When should control be used?
>
> Joel,
>
> Consider a driver for a communications channel.  You will
> send data down the channel as erlang messages to the port and
> receive data from the channel as erlang messages from the port.
> When sending the messages may be enqueued within the driver (see
> the erl_driver function driver_enq).  Received messages are
> handled through the process mailbox as normal.
>
> }  Are there any reasons to use control at all?
>
> The port_control/3 bif is synchronous, it delivers a response to
> a question or a result of a control operation directly.  You
> could simulate this by sending a message and waiting on a reply
> however the process would wait in a receive.  The port_control/3
> bif returns a value directly.  It is more like a driver "ioctl".


I take it that you ment that port_control/2  is synchronous and
port_control/3 is asynchronous?

Since port_control/3 is undocumented I have a question regarding it: will it
send a message when it is done or is it a
send-message-and-hope-life-is-swell type of call?

<snip>

Joel, you probably know this already but for those yet to encounter the port
beast: if the external program takes too long to return when called through
port_command/2 you will get a timeout so your code should probably take that
into account if you want it to be fault tolerant.

Cheers,
Torben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071214/c75a1dfe/attachment.htm>


More information about the erlang-questions mailing list