Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERL-1082: Return value of socket:bind() different than docs #4299

Closed
OTP-Maintainer opened this issue Oct 28, 2019 · 8 comments
Closed

ERL-1082: Return value of socket:bind() different than docs #4299

OTP-Maintainer opened this issue Oct 28, 2019 · 8 comments
Assignees
Labels
bug Issue is reported as a bug priority:medium team:PS Assigned to OTP team PS

Comments

@OTP-Maintainer
Copy link

Original reporter: benbro
Affected version: OTP-22.0.4
Component: inet
Migrated from: https://bugs.erlang.org/browse/ERL-1082


socket:bind/2 return value is {ok, Port} while the docs says just ok
http://erlang.org/doc/man/socket.html#bind-2
@OTP-Maintainer
Copy link
Author

benbro said:

socket:getopt/3 [1]  Level = integer() in the docs but in the usage page [2] it's atom (otp, socket...)

[1] http://erlang.org/doc/man/socket.html#getopt-3
[2] http://erlang.org/doc/apps/erts/socket_usage.html#socket_options

@OTP-Maintainer
Copy link
Author

bmk said:

Hi,

You are correct about bind. The code is correct.

As for getopt. I left out this case, when Level = integer (and Key is {NativeOpt, ValueSize}),
from the user guide, as it can be "anything". getopt with level = otp | ... is described in 
the previous clauses (in the ref man) and they are what is represented in the user guide table(s).
And in any case, a table for Level = integer() would only have one row, and there is really no
info to present (as with the other options).



@OTP-Maintainer
Copy link
Author

benbro said:

What's the difference between 'otp' and 'socket' levels?
What's the equivalent of setting recbuf n gen_udp? rcvbuf on Level=otp or Level=socket?
gen_udp:open(0, [binary, {buffer, 16384}, {recbuf, 16384}]),

I also don't 'buffer' but maybe that will be part of the gen_ wrapper around socket.

@OTP-Maintainer
Copy link
Author

bmk said:

The 'otp' in sockopt_level is for "our own" options. All the other levels,
such as 'socket' (SOL_SOCKET), 'ip' (SOL_IP / IPPROTO_IP), ... are the 
normal socket option levels.

The 'recvbuf' with level = socket is the size of the OS level receive buffer.
The 'recvbuf' with level = otp is the size of the buffer "we" read into when 
we read data (with recv/recvfrom/recvmsg).

Wrapping socket(tcp) in gen_tcp is being worked on at the moment.

@OTP-Maintainer
Copy link
Author

benbro said:

Thank you for the explanation. To me the distinction between 'otp' and 'socket' wasn't clear from the docs.
I also don't understand what will be the effect of a smaller or larger otp recvbuf in a UDP socket.
Is the otp recvbuf always equal or larger than the socket recvbuf?
I'll ask on the mailing list.

@OTP-Maintainer
Copy link
Author

benbro said:

There is also a typo. *to* instead of *too*. I've fixed it at one place but the same typo appears several times.

??if the buffer size is *to* small, the message will be truncated??

@OTP-Maintainer
Copy link
Author

bmk said:

The size(s) of the OS buffers is not something we can control.
The default value for otp:recvbuf is (currently) 8k.

The buffer defined by otp:recvbuf needs to be large enough to hold
the messages you expect to receive (otherwise you will need to
process the received messages).

Its up to the user to adjust the buffer size(s).

 

@OTP-Maintainer
Copy link
Author

bmk said:

A fix (for bind doc) has been merged into main (and master)

and will be included in the next maintenance release.

@OTP-Maintainer OTP-Maintainer added bug Issue is reported as a bug team:PS Assigned to OTP team PS priority:medium labels Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug priority:medium team:PS Assigned to OTP team PS
Projects
None yet
Development

No branches or pull requests

2 participants