Driver_output_binary returns a list

I have written a port driver, and I am using ‘driver_output_binary’ to transfer a binary I allocated in the driver to the port owner. The documentation says that I should receive a message that looks like this [H1, H2 | <<T>>] (Erlang -- erl_driver).

I am getting [H1, H2 | T] instead, where T is a list and not a binary. This isn’t ideal because it takes a performance hit for me to convert the list T back into a binary. I am running on OTP 21, could that be causing the issue? Or do I have something wrong in my code? Below is an example code:

short int hdr = 0x1234; // Populate header information
ErlDrvBinary* pBinary = driver_alloc_binary(1000);

// Populate pBinary with a bunch of data
driver_output_binary(port, (char*)&hdr, sizeof(hdr), pBinary, 0, 1000);

1 Like


The port also needs to be in binary mode in order for it to be delivered as a binary. See erlang:open_port/2 for how to do that.

1 Like

Thank you, that was exactly my problem.

1 Like