-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
Proposal Details
I would like to use Dial like so:
net.Dial("fd", "3")
or ListenPacket like so:
net.ListenPacket("fdgram", "3")
to create a FilePacketConn from a file descriptor number. I would also like to use Listen like so:
net.Listen("fd", "0")
to create a FileListener from a file descriptor number. This is useful because many go programs read a network and address from some form of configuration, and then pass these values to net.Dial or net.Listen to connect or bind to the given address. It is desirable for these programs to be able to inherit file descriptors from a parent process for these connections and listeners, without making any changes made to their implementation, for at least two use cases:
- programs can be run in a containerized environment with networking completely disabled but still use
netfor I/O - socket managers can terminate and respawn child servers that inherit listeners, without clients seeing an ECONNREFUSED
both of these use cases can already be implemented with NewFile, FileListener, and FilePacketConn, but adding support for them directly to Dial and Listen abstracts their implementation down to the level of configuration, which most programs using net implement already. For consistency, separate funcs with typed parameters similar to the other Dial* and Listen* funcs, can also be added:
func DialFd(network string, lfd, rfd uintptr) (FilePacketConn, error)func ListenFd(network string, lfd uintptr) (FileListener, error)func ListenFdgram(network string, lfd uintptr) (FilePacketConn, error)
all of these funcs can be implemented as simple compositions of NewFile with FileListener or FilePacketConn. I can add all of these features to net if there is support for them.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status