Type Specification of net:getnameinfo()

Micael Karlberg micael.karlberg@REDACTED
Tue Jan 26 15:55:33 CET 2021


Hi,

It is possible to configure (and build) otp *without* socket (esock) support.
That is what the ifdef'ing is about. Eventually, when socket is properly
official, this will be removed.

Regards,
  /BMK

________________________________
From: erlang-questions <erlang-questions-bounces@REDACTED> on behalf of Nalin Ranjan <ranjanified@REDACTED>
Sent: Tuesday, January 26, 2021 1:12 PM
To: Erlang-Questions Questions <erlang-questions@REDACTED>
Subject: Type Specification of net:getnameinfo()

Type<https://erlang.org/doc/man/net.html#getnameinfo-2> of net:getnameinfo() is specified in the source file<https://protect2.fireeye.com/v1/url?k=b7971346-e80c2a40-b79753dd-86ee86bd5107-36a745eb8cb7a80a&q=1&e=300a3de5-54c4-41b9-bbee-604bb9991333&u=https%3A%2F%2Fgithub.com%2Ferlang%2Fotp%2Fblob%2Fmaster%2Flib%2Fkernel%2Fsrc%2Fnet.erl%23L203>, and the one prevailing in the docs is as below:-

-spec getnameinfo(SockAddr, Flags) -> {ok, Info} | {error, Reason} when
SockAddr :: term(),
Flags :: name_info_flags() | undefined,
Info :: name_info(),
Reason :: term().

Currently, the type is SockAddr :: term(), and could have been SockAddr :: socket:sockaddr().

I think fixing it in the source at L221<https://protect2.fireeye.com/v1/url?k=bf7916a9-e0e22faf-bf795632-86ee86bd5107-5570f6b0d920cfb7&q=1&e=300a3de5-54c4-41b9-bbee-604bb9991333&u=https%3A%2F%2Fgithub.com%2Ferlang%2Fotp%2Fblob%2Fmaster%2Flib%2Fkernel%2Fsrc%2Fnet.erl%23L221> should fix it in the documentation as well. But please let me know if it doesn't.

However, I am myself confused about the way the type is specified, so thought I will discuss first before opening a PR.

It is not the net:getnameinfo/1 that I am confused, but about the net:getnameinfo/2. I don't understand the usage of ifndef and else while specifying this type specification. If you could please point me to a place where I can understand these 2 better. I don't want to make wild guesses here while I am working through the foundations of Erlang.

It could have been simpler had this specification been written like below, even though whatever "ifdef" is doing out there is to be taken into consideration:-

SockAddr :: socket:sockaddr() | term(),
Flags :: name_info_flags() | undefined,
Info :: name_info(),
Reason :: term()

Please let me know if there is any misconstrusion on my part.

Thanks and Regards
Nalin Ranjan



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210126/79ef6ed7/attachment.htm>


More information about the erlang-questions mailing list