<br><br><div class="gmail_quote">On Dec 13, 2007 10:41 PM, Vance Shipley <<a href="mailto:vances@motivity.ca">vances@motivity.ca</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Thu, Dec 13, 2007 at 06:31:06PM +0000, Joel Reymont wrote:<br>} My understanding is that Port ! {self(), {command, Data}} triggers<br>} output whereas port_command(Port, Data) triggers control.
<br>}<br>} When should control be used?<br><br></div>Joel,<br><br>Consider a driver for a communications channel. You will<br>send data down the channel as erlang messages to the port and<br>receive data from the channel as erlang messages from the port.
<br>When sending the messages may be enqueued within the driver (see<br>the erl_driver function driver_enq). Received messages are<br>handled through the process mailbox as normal.<br><div class="Ih2E3d"><br>} Are there any reasons to use control at all?
<br><br></div>The port_control/3 bif is synchronous, it delivers a response to<br>a question or a result of a control operation directly. You<br>could simulate this by sending a message and waiting on a reply<br>however the process would wait in a receive. The port_control/3
<br>bif returns a value directly. It is more like a driver "ioctl".</blockquote><div><br>I take it that you ment that port_control/2 is synchronous and port_control/3 is asynchronous?<br><br>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?
<br><br><snip><br></div></div><br>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.
<br><br>Cheers,<br>Torben<br><br><br><br>