[erlang-questions] Port is NULL verification in the start callback of a linked-in driver

Zhemzhitsky Sergey <>
Mon Sep 3 10:23:58 CEST 2012


Hi erlangers,

I'm wondering whether it’s necessary to check that port is not NULL in the start callback of the driver:
ErlDrvData (*start)(ErlDrvPort port, char *command);

I’m asking because there are some samples that do such a verification, i.e.
https://github.com/dlfen/erlang-db-driver/blob/master/c_src/base/AsyncDrv.cpp#L29
https://github.com/norton/lets/blob/master/c_src/lets_drv.cc#L251
and a lot of port drivers that do not.

As I understand (according to the otp sources) port parameter is only a number of the port in the erts_port array (https://github.com/erlang/otp/blob/maint/erts/emulator/beam/io.c#L60) and 0 (zero) is a valid value for it.

So I have two questions:


1.       Is it necessary to check that the port parameter in the start callback of the driver is not NULL (not 0) and why?

2.       If 0 (zero) is a legal value for the port parameter in the start callback of the driver, why there are drivers which require that parameter to be not NULL (or this is a kind of a bug)?


Best Regards,
Sergey


_______________________________________________________

The information contained in this message may be privileged and conf idential and protected from disclosure. If you are not the original intended recipient, you are hereby notified that any review, retransmission, dissemination, or other use of, or taking of any action in reliance upon, this information is prohibited. If you have received this communication in error, please notify the sender immediately by replying to this message and delete it from your computer. Thank you for your cooperation. Troika Dialog, Russia. 
If you need assistance please contact our Contact Center  (+7495) 258 0500 or go to www.troika.ru/eng/Contacts/system.wbp  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120903/16b8bef7/attachment.html>


More information about the erlang-questions mailing list