package sockimport ()// TCPSock is a pseudo-file representing a TCP socket.typeTCPSockinterface {sys.FileAccept() (TCPConn, sys.Errno)}// TCPConn is a pseudo-file representing a TCP connection.typeTCPConninterface {sys.File// Recvfrom only supports the flag sysfs.MSG_PEEK // TODO: document this like sys.File with known sys.ErrnoRecvfrom(p []byte, flags int) (n int, errno sys.Errno)// TODO: document this like sys.File with known sys.ErrnoShutdown(how int) sys.Errno}// ConfigKey is a context.Context Value key. Its associated value should be a Config.typeConfigKeystruct{}// Config is an internal struct meant to implement// the interface in experimental/sock/Config.typeConfigstruct {// TCPAddresses is a slice of the configured host:port pairs. TCPAddresses []TCPAddress}// TCPAddress is a host:port pair to pre-open.typeTCPAddressstruct {// Host is the host name for this listener. Host string// Port is the port number for this listener. Port int}// WithTCPListener implements the method of the same name in experimental/sock/Config.//// However, to avoid cyclic dependencies, this is returning the *Config in this scope.// The interface is implemented in experimental/sock/Config via delegation.func ( *Config) ( string, int) *Config { := .clone() .TCPAddresses = append(.TCPAddresses, TCPAddress{, })return &}// Makes a deep copy of this sockConfig.func ( *Config) () Config { := * .TCPAddresses = make([]TCPAddress, 0, len(.TCPAddresses)) .TCPAddresses = append(.TCPAddresses, .TCPAddresses...)return}// BuildTCPListeners build listeners from the current configuration.func ( *Config) () ( []*net.TCPListener, error) {for , := range .TCPAddresses {varnet.Listener , = net.Listen("tcp", .String())if != nil {break }if , := .(*net.TCPListener); { = append(, ) } }if != nil {// An error occurred, cleanup.for , := range { _ = .Close() // Ignore errors, we are already cleaning. } = nil }return}func ( TCPAddress) () string {returnfmt.Sprintf("%s:%d", .Host, .Port)}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.