Documentation
¶
Index ¶
- func AllIPAddr() string
- func BidiCopy(conn1, conn2 io.ReadWriteCloser, isClient bool) error
- func IsIPDualStack() bool
- func IsNilNetAddr(addr net.Addr) bool
- func LocalIPAddr() string
- func MaybeDecorateIPv6(addr string) string
- func NilNetAddr() net.Addr
- func ReuseAddrPort(network, address string, conn syscall.RawConn) error
- func SendReceive(ctx context.Context, conn net.Conn, req []byte) (resp []byte, err error)
- func UnusedTCPPort() (int, error)
- func UnusedUDPPort() (int, error)
- func WaitForClose(conn net.Conn)
- type ConnHandler
- type HierarchyConn
- type IPVersion
- type NetAddr
- type TransportProtocol
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllIPAddr ¶
func AllIPAddr() string
AllIPAddr returns a catch-all IP address to bind. If the machine supports IP dual stack, "::" is returned. Otherwise "0.0.0.0" is returned.
func BidiCopy ¶ added in v1.11.0
func BidiCopy(conn1, conn2 io.ReadWriteCloser, isClient bool) error
BidiCopy does bi-directional data copy.
func IsIPDualStack ¶
func IsIPDualStack() bool
IsIPDualStack returns true if an IPv6 socket is able to send and receive both IPv4 and IPv6 packets.
This function only supports Linux. It always returns false if running other operating systems.
func IsNilNetAddr ¶ added in v1.15.0
IsNilNetAddr returns true if the net.Addr is nil / empty.
func LocalIPAddr ¶ added in v1.7.0
func LocalIPAddr() string
LocalIPAddr returns the localhost IP address.
func MaybeDecorateIPv6 ¶
MaybeDecorateIPv6 adds [ and ] before and after an IPv6 address. If the input string is a IPv4 address or not a valid IP address (e.g. is a domain), the same string is returned.
func NilNetAddr ¶ added in v1.15.0
NilNetAddr returns an empty network address.
func ReuseAddrPort ¶ added in v1.4.0
ReuseAddrPort sets SO_REUSEADDR and SO_REUSEPORT options to a given connection.
func SendReceive ¶ added in v1.11.0
SendReceive sends a request to the connection and returns the response. The maxinum size of response is 4096 bytes.
func UnusedTCPPort ¶ added in v1.13.0
UnusedTCPPort returns an unused TCP port.
func UnusedUDPPort ¶ added in v1.13.0
UnusedUDPPort returns an unused UDP port.
func WaitForClose ¶ added in v1.9.1
WaitForClose blocks the go routine. It returns when the peer closes the connection. In the meanwhile, everything send by the peer is discarded.
Types ¶
type ConnHandler ¶ added in v1.15.0
type ConnHandler interface { // Take grabs the ownership of the network connection. // The function returns when the handler returns the ownership. Take(net.Conn) (closed bool, err error) }
ConnHandler defines a generic handler that can take the ownership of a network connection.
type HierarchyConn ¶ added in v1.9.1
HierarchyConn closes sub-connections when this connection is closed.
func WrapHierarchyConn ¶ added in v1.9.1
func WrapHierarchyConn(conn net.Conn) HierarchyConn
WrapHierarchyConn wraps an existing connection with HierarchyConn.
type IPVersion ¶ added in v1.4.0
type IPVersion int
func GetIPVersion ¶ added in v1.4.0
GetIPVersion returns the IP version of the given network address.
type TransportProtocol ¶ added in v1.13.0
type TransportProtocol int
const ( UnknownTransport TransportProtocol = iota UDPTransport TCPTransport )