|Date Added:||18 November 2018|
|File Size:||67.78 Mb|
|Operating Systems:||Windows NT/2000/XP/2003/2003/7/8/10 MacOS 10/X|
|Price:||Free* [*Free Regsitration Required]|
Erlang — Ports and Port Drivers
The linked-in driver looks like a port from the Erlang programmer’s point of view and is called a port driver. Data is received from the external program. Erlang truly is a useful language. Please mark this question answered. The scenario is illustrated in the following figure: The underlying implementation previously delivered messages to ports synchronously. Some additional BIFs that apply to port drivers: Sets the port owner of Port to NewPid.
Both send a message to the complex process and receive the following reply:. While I only used it for retrieving web page content into memory I figure I’ll be able erlajg wrap all of libcurl in the future.
14 Ports and Port Drivers
The C driver is a module that is compiled and linked into a shared library. All communication to and from the linkedd must go through the port owner.
The functions oinked receiving and sending data are combined into a function, pointed out by the driver structure. The port driver can also send data to Erlang.
This section outlines an example of how to solve the example problem in Problem Example by using a linked-in port driver. See my comments for explanation. The resulting Erlang program, including functions for stopping the port and detecting port failures, is as follows:. If the port owner terminates, so does the port and the external program, if it is written correctly. Posting this answer based on Justin’s follow-up question herewhich contains a slightly different but working answer.
The external program resides in another OS process.
C from erlang via linked-in driver
C from erlang via linked-in driver –
If binaries should be used instead of lists of bytes, the option binary must be included. It is customary to use an allocated driver-defined structure for this one, and to pass a pointer back as a reference. Like a port program, the port pport with an Erlang process.
An erroneous port driver will cause the entire Erlang runtime system to leak memory, hang or crash. Returns information as specified by Item. In fact, any process can send the messages to the port, but the port owner must be identified in the message. I’ve started with the Erlang C port example, which works fine: When a port has been created, Erlang can communicate with it by sending and receiving lists of bytes, including binaries.