type TCPAddr … // AddrPort returns the [TCPAddr] a as a [netip.AddrPort]. // // If a.Port does not fit in a uint16, it's silently truncated. // // If a is nil, a zero value is returned. func (a *TCPAddr) AddrPort() netip.AddrPort { … } // Network returns the address's network name, "tcp". func (a *TCPAddr) Network() string { … } func (a *TCPAddr) String() string { … } func (a *TCPAddr) isWildcard() bool { … } func (a *TCPAddr) opAddr() Addr { … } // ResolveTCPAddr returns an address of TCP end point. // // The network must be a TCP network name. // // If the host in the address parameter is not a literal IP address or // the port is not a literal port number, ResolveTCPAddr resolves the // address to an address of TCP end point. // Otherwise, it parses the address as a pair of literal IP address // and port number. // The address parameter can use a host name, but this is not // recommended, because it will return at most one of the host name's // IP addresses. // // See func [Dial] for a description of the network and address // parameters. func ResolveTCPAddr(network, address string) (*TCPAddr, error) { … } // TCPAddrFromAddrPort returns addr as a [TCPAddr]. If addr.IsValid() is false, // then the returned TCPAddr will contain a nil IP field, indicating an // address family-agnostic unspecified address. func TCPAddrFromAddrPort(addr netip.AddrPort) *TCPAddr { … } type TCPConn … type KeepAliveConfig … // SyscallConn returns a raw network connection. // This implements the [syscall.Conn] interface. func (c *TCPConn) SyscallConn() (syscall.RawConn, error) { … } // ReadFrom implements the [io.ReaderFrom] ReadFrom method. func (c *TCPConn) ReadFrom(r io.Reader) (int64, error) { … } // WriteTo implements the io.WriterTo WriteTo method. func (c *TCPConn) WriteTo(w io.Writer) (int64, error) { … } // CloseRead shuts down the reading side of the TCP connection. // Most callers should just use Close. func (c *TCPConn) CloseRead() error { … } // CloseWrite shuts down the writing side of the TCP connection. // Most callers should just use Close. func (c *TCPConn) CloseWrite() error { … } // SetLinger sets the behavior of Close on a connection which still // has data waiting to be sent or to be acknowledged. // // If sec < 0 (the default), the operating system finishes sending the // data in the background. // // If sec == 0, the operating system discards any unsent or // unacknowledged data. // // If sec > 0, the data is sent in the background as with sec < 0. // On some operating systems including Linux, this may cause Close to block // until all data has been sent or discarded. // On some operating systems after sec seconds have elapsed any remaining // unsent data may be discarded. func (c *TCPConn) SetLinger(sec int) error { … } // SetKeepAlive sets whether the operating system should send // keep-alive messages on the connection. func (c *TCPConn) SetKeepAlive(keepalive bool) error { … } // SetKeepAlivePeriod sets the duration the connection needs to // remain idle before TCP starts sending keepalive probes. // // Note that calling this method on Windows prior to Windows 10 version 1709 // will reset the KeepAliveInterval to the default system value, which is normally 1 second. func (c *TCPConn) SetKeepAlivePeriod(d time.Duration) error { … } // SetNoDelay controls whether the operating system should delay // packet transmission in hopes of sending fewer packets (Nagle's // algorithm). The default is true (no delay), meaning that data is // sent as soon as possible after a Write. func (c *TCPConn) SetNoDelay(noDelay bool) error { … } // MultipathTCP reports whether the ongoing connection is using MPTCP. // // If Multipath TCP is not supported by the host, by the other peer or // intentionally / accidentally filtered out by a device in between, a // fallback to TCP will be done. This method does its best to check if // MPTCP is still being used or not. // // On Linux, more conditions are verified on kernels >= v5.16, improving // the results. func (c *TCPConn) MultipathTCP() (bool, error) { … } func newTCPConn(fd *netFD, keepAliveIdle time.Duration, keepAliveCfg KeepAliveConfig, preKeepAliveHook func(*netFD), keepAliveHook func(KeepAliveConfig)) *TCPConn { … } // DialTCP acts like [Dial] for TCP networks. // // The network must be a TCP network name; see func Dial for details. // // If laddr is nil, a local address is automatically chosen. // If the IP field of raddr is nil or an unspecified IP address, the // local system is assumed. func DialTCP(network string, laddr, raddr *TCPAddr) (*TCPConn, error) { … } type TCPListener … // SyscallConn returns a raw network connection. // This implements the [syscall.Conn] interface. // // The returned RawConn only supports calling Control. Read and // Write return an error. func (l *TCPListener) SyscallConn() (syscall.RawConn, error) { … } // AcceptTCP accepts the next incoming call and returns the new // connection. func (l *TCPListener) AcceptTCP() (*TCPConn, error) { … } // Accept implements the Accept method in the [Listener] interface; it // waits for the next call and returns a generic [Conn]. func (l *TCPListener) Accept() (Conn, error) { … } // Close stops listening on the TCP address. // Already Accepted connections are not closed. func (l *TCPListener) Close() error { … } // Addr returns the listener's network address, a [*TCPAddr]. // The Addr returned is shared by all invocations of Addr, so // do not modify it. func (l *TCPListener) Addr() Addr { … } // SetDeadline sets the deadline associated with the listener. // A zero time value disables the deadline. func (l *TCPListener) SetDeadline(t time.Time) error { … } // File returns a copy of the underlying [os.File]. // It is the caller's responsibility to close f when finished. // Closing l does not affect f, and closing f does not affect l. // // The returned os.File's file descriptor is different from the // connection's. Attempting to change properties of the original // using this duplicate may or may not have the desired effect. func (l *TCPListener) File() (f *os.File, err error) { … } // ListenTCP acts like [Listen] for TCP networks. // // The network must be a TCP network name; see func Dial for details. // // If the IP field of laddr is nil or an unspecified IP address, // ListenTCP listens on all available unicast and anycast IP addresses // of the local system. // If the Port field of laddr is 0, a port number is automatically // chosen. func ListenTCP(network string, laddr *TCPAddr) (*TCPListener, error) { … } // roundDurationUp rounds d to the next multiple of to. func roundDurationUp(d time.Duration, to time.Duration) time.Duration { … }