-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: net: add ability to read OOB data without discarding a byte #32465
Comments
BTW, users could implement this today by calling |
You can use https://golang.org/pkg/net/#UnixConn.SyscallConn to perform a raw read on the file descriptor with whichever syscall you like, AND you'll still have runtime network poller support. Have you tried this option? |
Oh that's pretty nice. I hadn't seen that one yet - I'll try it out. Thanks! |
These details are pretty faded in my memory right now. Can someone explain why the 1 byte is disappearing? As far as I can see, the poller is given the read argument p unmodified, so if you ask to read 0 bytes, the kernel gets asked for 0 bytes. Is the kernel discarding the 1 byte? I don't see where Go is. |
@rsc As far I know, historically OOB data wasn't sent alone, and one would "flush it out" by sending a dummy byte. I think syscall.Recvmsg explicitly accommodates this old cruft: go/src/syscall/syscall_linux.go Lines 635 to 639 in 0b6e3bf
|
|
This looks like an implementation detail of
The linux |
Pick one or the other, you're self-contradicting. You're also asking for behavior that is against a "must" in the relevant man page ("must [...] receive at least one byte of nonancillary data in the same sendmsg(2) or recvmsg(2) call"). Now, it might be possible to let go of this legacy kludge, but not with this api. Changing Recvmsg behavior here would break existing callers that expect it to eat the dummy byte silently. (Has anyone tested writing/reading OOB data without a dummy byte, with raw syscalls? Linux, macOS, BSDs? If it doesn't work, this whole discussion is moot.) |
To read ancillary data without interrupting the data stream, users can pass the |
I'm believe the correct option at this point is to use the SyscallConn method to perform the appropriate system call with the appropriate flags. I'm not sure it's worth adding stdlib API for this. |
🤷♂Eh there isn't always a correct option in situations like this, but I can understand a preference by lib maintainers to reduce API bloat even at the expense of extra functionality in the net/unix lib (especially when there are lower-level alternatives). Thanks for the help all |
@APTy, did you try using SyscallConn? Did it work for you? |
There have been no updates since #32465 (comment). Based on that and @mdlayher's suggestion above, this seems like a likely decline. Leaving open for a week for final comments. |
Marked this last week as likely decline w/ call for last comments (#32465 (comment)). |
Problem
Currently,
(*UnixConn) ReadMsgUnix()
reads a message from a unix socket, and, if that socket is a stream, it will always read at least one byte from the stream.From UnixConn.ReadMsgUnix:
For applications that use
ReadMsgUnix
to receive ancillary, out-of-bound data and don't want to disrupt the data sent in-bound, this isn't a useful API.Proposed Solution
The underlying syscall,
recvmsg(2)
allows setting the flags param toMSG_PEEK
, which accomplishes this task. Unfortunately, flags are not part of theReadMsgUnix
API. To solve these, I see two options:Notes
Since the list of flags is fairly short, option (2) could be acceptable.
The text was updated successfully, but these errors were encountered: