-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Implement read_ahead
option (OTP-19199)
#8785
Implement read_ahead
option (OTP-19199)
#8785
Conversation
I saw a strange behaviour of the MGS_PEEK flag on Linux (Ubuntu 22.04 LTS). When using MSG_PEEK through `socket` to try to avoid concatenating the header and body binaries, instead peek the header then receive the whole packet, this happened (header 2, incoming <<0,1,65>>, but one character at the time, through `gen_tcp_echo_SUITE`'s slow echo server: * recv 0 -> select ... * recv 0 -> <<0>> We are missing one byte for the header and try to peek it * recv 1 peek -> timeout * recv 1 -> select ... New attempt to peek the header * recv 1 peek -> <<1>> We conclude the length field is 1 and we are missing 2 bytes * recv 2 -> select ... Here we don't save the state that we want 2 bytes so we start over with the <<0>> we have and, again, peek for the rest of the header. * recv 1 peek -> <<1,0>> ??? we asked for 1 byte, what is the <<0>>? Here the packet decode succeeds surprisingly since we were supposed to only have the header, so we fall back to the generic path which receives one byte at the time. * recv 1 -> <<65>> ??? where did the <<1>> go? * recv 65 -> select ... We are lost and think the length field is 65= recv N peek means `socket:recv(_, N, [peek], 0)` (timeout 0). We didn't store data from a peek, just use it to figure out the packet length for a recv without peek.
CT Test Results 2 files 70 suites 1h 6m 49s ⏱️ For more details on these failures, see this check. Results for commit 0e943f4. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
Continuation of PR #8690 that implements the
read_ahead
option ininet:setopts/2
, that is; also forinet_backend=socket
(gen_tcp_socket
), with documentation, and test cases.