-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
syscall: allow registration of new socket types for package net #15021
Comments
Hi, Thanks for the work you've put in to figuring out what's possible. Can you Thanks. On Tue, Mar 29, 2016 at 2:18 PM Matt Layher [email protected]
|
Hi Russ, It appears to me that the runtime network poller functionality is exposed directly using the Specifically, I'm looking at Thanks for the quick reply, and I look forward to hearing back. |
Your Example looks exactly as I think it should except for the fact that On Tue, Mar 29, 2016 at 3:08 PM Matt Layher [email protected]
|
I am in favor of moving it to package Can you suggest a viable approach to solving this problem? Perhaps the low level runtime network poller code in In summary, yes, I am in favor of creating EDIT: in addition, since |
Can you point me at the code you changed? Maybe that will help me see why On Tue, Mar 29, 2016 at 3:45 PM Matt Layher [email protected]
|
Here's a link to the prototype I made to make this work. Obviously, it would need cleanup, proper locking, and probably should be wrapped in a type. https://github.com/mdlayher/go/commit/2e7d77c17dbc830135ca35eb5617e073c8fc717b |
Hey @rsc , did you get a chance to look at the prototype I created above? I'd love to hear your thoughts on it. Thanks for your time. |
I didn't have a look at your proposal/prototype carefully, and probably have no spare time for this feature (including #10565 opened by me) during Go 1.7 development cycle, but a bit. I think that the basic requirements for this feature look like the following:
#10565 just covers R1, and perhaps your proposal too. I'd like to see a design that fulfils the above requirements, at least R1 and R2. Otherwise, the design would be the source of trouble in future, like "I cannot achieve my goal because of the lack of R2 (or both R2 and R3)." I suppose that a typical use case would be either R1+R2 or R2+R3; the former is for people who want to use the existing read/write methods in the net package with new socket types and the latter is for people who want to use new read/write methods with new socket types. Thoughts? |
@mikioh Thanks for replying. Your requirements seem sound, but I wouldn't even know where to begin covering R2 and R3 (mine only covers R1). Happy to help out if you have any sketches of a proposed API or something similar, but I don't have the knowledge of the internals of package |
FTR, no one says the syscall package will be deprecated. It's just frozen.
It should work fine for existing features and we even fixes bugs for
existing features. We just won't add new features or make significant
bugfixes (like BSD ABI broken changes.)
|
FTR, https://golang.org/s/go1.4-syscall says that:
not literally, but in effect. |
I think x/net repository is a good place for the new package implementing R2, because we can copy the package into src/vendor/golang.org/x/net/ and plumb it in the net package later. |
I will investigate options a bit here. |
Thanks, @bradfitz ! Looking forward to seeing what you come up with. Happy to help if there's anything I could do to assist you. |
(Still on my plate to look at.) |
The runtime already exposes a portable netpoll API to the net package, using I'd prefer to see a new package exposing a more Go-like (and less net/syscall-like) interface to that poller. I'd ideally like to see it done without any syscall.Sockaddr crud. At the heart of epoll & friends is a simple API letting people register FDs they care about (and how: readability vs writability) and wait on a bunch of them at once. We could have an API with uintptrs to watch/unwatch, a Go type for readable/writeable, and func callbacks when the edge triggers. Does anybody want to explore prototyping that? |
I don't understand what you mean by "Go-like (and less net/syscall-like)." Can you please elaborate on that? What's your plan to accommodate user-specified socket descriptors with net package API access? My guess is that your plan is just to provide a package like libuv for Node.js or mio for Rust. The package neither provide new IO methods such as {recv,send}mmsg nor replacements for broken APIs in frozen syscall and x/sys packages such as Sendfile for Darwin. Also the package doesn't help to inject user-specified socket descriptors with the net package via File{Conn,Listener,PacketConn} APIs because it doesn't address #10565. Is my understanding correct? |
There is already an interface for the network poller defined, it is just that it is linked directly into the net package using go:linkname on private functions in runtime/netpoll.go. Is there some reason that the methods there (ServerInit, Open, Close, Reset, Wait, WaitCanceled, SetDeadline, and Unblock) can't be just exposed as public APIs? This is exactly what I need for implementing an API over an AF_CAN socket type (https://groups.google.com/forum/#!topic/golang-nuts/l-1JD02_o0Q). Doing some digging this morning I found out that my options 2 and 3 are not possible because of this special link between the runtime and net packages. |
FYI: mikioh recently submitted a series of three CLs which appear to be designed to implement a version of the solution proposed here. https://go-review.googlesource.com/c/35995/ They are marked "DO NOT REVIEW" but I wanted to make sure they were mentioned for anyone keeping an eye on this issue. |
CL https://golang.org/cl/36799 mentions this issue. |
CL https://golang.org/cl/36800 mentions this issue. |
I'm happy to give this a try. Thanks for the example CL! |
@rsc, it looks to me like os.NewFile will never enable the poller on Linux (it always passes pollable = false to poll.FD.Init()), so there is still no way to use the network poller for foreign fds. Am I missing something? |
@jstarks I think you're right; that too would have to change. |
I'm not sure I'll be able to take this on. @mikioh, are you interested? |
Hello. Is anyone working on this? If not, I am willing to do the work, be it for 1.11 or 1.12. EDIT: In light of ea5825b, which I only now discovered, perhaps this is less relevant now. But the issue of creating a |
Please feel free to take this on! |
I have thought about this some more. If I understand things correctly, I believe the socket type registry is only worth implementing if there are also going to be hooks into Since a non-blocking
It's not difficult to imagine a similar construction for packet-oriented connections, with a straight-forward type assertion inside the library for methods like With this approach, users of the hypothetical bluetooth package would now have a usable, non-blocking On the other hand, the nice property of being able to pass the strings returned by The existence of a socket type registry in the syscall package would potentially hide some of the details from end-users (and preserve the aforementioned property), so long as the generic I hope I have not misunderstood the issues at hand. Moving forward, if the registry is still something we would like to implement, I can do the work for it. Otherwise, perhaps this issue could be closed in light of ea5825b. Thank you. |
Sorry for talking to myself here. I have thought about this some more, and I have a more concrete proposal. For 1.12, I plan to send a CL that adds the registration mechanism to package I think hooking into Dial (or other such intrusive things) can be discussed at a later time, if and when people use the new interface and provide feedback. Does that sound good? |
Change https://golang.org/cl/136595 mentions this issue: |
I believe @acln0 is investigating that option for the use cases I have! I don't have any further knowledge at this point. |
Because of the ability to call See mdlayher/netlink#119 for details on how this has been implemented in my netlink sockets package. At this point I am going to close this issue as unneeded, but I'll be sure to report back if we find any further limitations. |
Thanks for following up. |
Overview
At this time, there is no mechanism for socket types outside of the standard library to access the runtime network poller. This proposal, if accepted, would enable a resolution to issue #10565. This would enable packages outside of the standard library to take advantage of the runtime network poller, instead of implementing their own network polling mechanism.
Proposed Change
I propose adding a new API to package
net
which enables registration of arbitrary sockets for use with the runtime network poller. The design of this API is based upon a comment from @rsc found here: #11492 (comment).This is what I was able to come up with after a little bit of experimentation. Parameter list is to be determined, but this is what I was able to get working with my prototype on a Linux system. Efforts will be made to make this mechanism as generic and cross-platform friendly as possible, but it may not be implemented immediately on non-UNIX platforms. From what I can tell,
syscall.Sockaddr
does appear to be available on all platforms.Example
Using a modified version of package
net
, I was able to gain access to the runtime network poller andsimplify my raw sockets package code to something like the following:
Summary
The runtime network poller is an excellent mechanism, and enabling access to it will allow the future development of packages for raw ethernet sockets, netlink sockets, and other platform-specific socket types.
If this proposal is accepted, I'd happily seek guidance from @mikioh regarding creating the best possible API for this feature. In addition, this would enable me to contribute code from my raw ethernet socket package as a resolution to #8432.
Questions and comments appreciated, and thanks for your time.
/cc @rsc @mikioh
The text was updated successfully, but these errors were encountered: