Description
As of now, there is still no way to access the runtime network poller with custom socket types. As a follow up to #15021, I'd like to try implementing a new package in x/net
that contains a Socket
type which can later be plumbed into package net
, enabling access to the runtime network poller.
The basis of this proposal lies in a comment by @mikioh here: #15021 (comment)
Need to have a replacement for the syscall package
- No use of types in the syscall package is mandatory because the syscall package is locked down and will be deprecated
- The new package should provide a type that represents some sort of tuple known as a socket
- The new package should provide flexibility for system adaptation not only for the existing kernels
I have not found a name I'm happy with for this package, but for now, let's refer to it as x/net/socket
. The API could look something like the following:
package socket
// Custom socket types that can be registered with this package, identified
// by address family.
type Socket interface {
Family() int
Addr() Addr
ToAddr(sa Sockaddr) Addr
ToSockaddr(addr Addr) Sockaddr
}
// A syscall.Sockaddr, without importing syscall.
// Not sure if there is a way around this. Maybe importing syscall for
// syscall.Sockaddr is okay, since this isn't changing package syscall?
type Sockaddr interface{}
// Duplication of net.Addr. Can't import net directly because this package
// could be vendored into the standard library and used by net later.
type Addr interface {
Network() string // name of the network
String() string // string form of address
}
// Registers a Socket into the package.
func Register(s Socket)
// Retrieves all Sockets registered into the package. Can be used
// by net later to handle unknown address families.
func Sockets() []Socket
If this proposal is on the right track, I'd be happy to start working on the new package. In a later proposal, we can discuss the mechanism for plumbing it into package net
.
Thanks for your time! Let me know if there are any unresolved questions.
/cc @mikioh