Type Specification of net:getnameinfo()

Nalin Ranjan ranjanified@REDACTED
Tue Jan 26 17:16:26 CET 2021


Thanks a lot Micael.

I will explore the "ifdef" attribute in that case, for me its a perception
as of yet .

1. Does it mean "net" module itself will be gone in future, once "socket"
is official?

2. In this particular case of type specification, the only difference is in
one of the parameters of the function. I was also wondering if we could
have used a union instead to write the same type spec, it would have been
simpler?
For example,
Instead of writing a type spec like this

-ifdef(SOME_PRAGMA_CONDITION)
          SomeVar :: xxx_type().
-else
         SomeVar :: yyy_type().

We could specify the same type spec as:
        SomeVar :: xxx_type() | yyy_type().

Any reason we preferred the former over the latter?


नमस्ते।
नलिन रंजन

On Tue, Jan 26, 2021, 8:25 PM Micael Karlberg <micael.karlberg@REDACTED>
wrote:

> 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/82f5612b/attachment.htm>


More information about the erlang-questions mailing list