Port driver memory free

Raimo Niskanen raimo@REDACTED
Tue Mar 22 13:06:13 CET 2005


Rather correct...

driver_entry->call() should return memory allocated with 
driver_alloc(), and the contents should be in external term format
as from the ei_* functions. You do not have to allocate memory
if the return value fits in the preallocated buffer.

driver_entry->control() should return memory allocated with
driver_alloc(), and the contents is interpreted as a list of
integers [0..255]. You do not have to allocate memory if the
return value fits in the preallocated buffer. 

If you set the PORT_CONTROL_FLAG_BINARY flag, 
driver_entry->control() should instead return a binary allocated 
with driver_alloc_binary() and it is interpreted as a binary (!), 
except if you (do not allocate a binary and) set the return buffer 
to NULL which is interpreted as an empty list (allowed from R10B).
The preallocated return buffer can not be used.

Note that you do not have to encode the result value using ei_*
functions when you use driver_entry->control(). The encoding
of the binary (or list) is entirely up to the driver and its
calling erlang code. It is probably faster to encode the data
in a suitable way of your own.



casper2000a@REDACTED (Casper) writes:

> Only difference is call use external term format, so need to use
> driver_alloc, but control doesn't so use driver_alloc_binary, Correct?
> 
> - Eranga
> 
> 
> -----Original Message-----
> From: owner-erlang-questions@REDACTED
> [mailto:owner-erlang-questions@REDACTED] On Behalf Of Casper
> Sent: Tuesday, March 22, 2005 5:03 PM
> To: 'Vance Shipley'
> Cc: erlang-questions@REDACTED; raimo@REDACTED
> Subject: RE: Port driver memory free
> 
> Vance,
> 
> Regarding port_call and port_control, I think both can use ei library
> functions to encode/decode terms, correct? If not, please advice how they've
> being done.
> 
> I am sorry if I did something offending. But to my understanding the code I
> published only carries a very generic Erlang-C port code. Even on the Erlang
> manuals or samples, the same method is shown.
> 
> Thanks!
> - Eranga
> 
> 
> 
> 
> -----Original Message-----
> From: Vance Shipley [mailto:vances@REDACTED] 
> Sent: Tuesday, March 22, 2005 10:44 AM
> To: casper2000a@REDACTED
> Cc: erlang-questions@REDACTED; raimo@REDACTED
> Subject: Re: Port driver memory free
> 
> Eranga,
> 
> Your problem is that you have copied my (copyrighted) code written
> for use with erlang:port_call/3 and reused it with erlang:port_control/3.
> The difference between the two is that port_call/3 uses the external 
> term format as encoded by the ei library while port_control/3 uses the
> driver binary format.
> 
> 	-Vance
> 
> 
> Motivity Telecom Inc.
> +1 519 240 3684
> vances@REDACTED
> 
> 

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list