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

Vance Shipley <>
Thu Dec 13 22:41:44 CET 2007


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".

}  Are there any reasons to prefer output over control or vise versa?

The port_command/2 bif should be preferred for message passing.
The driver_entry ouputv() callback function handles vectorized
data so receiving an iolist() or binary() is more effecient.

	-Vance



More information about the erlang-questions mailing list