core: Wrap listeners with type that can pipe #5040
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Once a server has a listener, the only way for it to act on connections is to call
Accept()
. Unfortunately, the implementations ofAccept()
are opaque and hard-coded; that is, a server looping on a TCP listener can only accept real TCP connections. It's not really possible (AFAIK) to give that listener a virtual "connection" in user space, we have to open a real TCP socket through the kernel and proxy all the bytes.This change allows servers to accept connections whether they be real or virtual. It exports a
Pipe()
method that allows other code to give a server anet.Conn
. This means the server can still use real TCP connections, but also allows us to add our own connections if we have something we want it to do or act on.For example, the layer4 module could hand off a connection to the HTTP app without having to proxy. Very efficient!
This is an early-stages experiment and still WIP. Haven't even tested it yet.
(Currently, this functionality does not apply to PacketConn or quic.EarlyListener types.)