Documentation
¶
Index ¶
- Constants
- Variables
- func Dial(network string, address string) (net.Conn, error)
- func DialContext(ctx context.Context, network string, address string) (net.Conn, error)
- func DialContextTimeout(ctx context.Context, network string, address string, timeout time.Duration) (net.Conn, error)
- func DialTimeout(network string, address string, timeout time.Duration) (net.Conn, error)
- func Listen(network string, addr string) (ln net.Listener, err error)
- func ListenPacket(network string, addr string) (c net.PacketConn, err error)
- func Pin() error
- func Presets(options ...aio.Option)
- func Unpin() error
- func UseProcessPriority(level process.PriorityLevel)
- type Dialer
- func (d *Dialer) Dial(network string, address string) (c net.Conn, err error)
- func (d *Dialer) DialContext(ctx context.Context, network, address string) (c net.Conn, err error)
- func (d *Dialer) DialIP(_ context.Context, network string, laddr, raddr *net.IPAddr) (*IPConn, error)
- func (d *Dialer) DialTCP(ctx context.Context, network string, laddr, raddr *net.TCPAddr) (*TCPConn, error)
- func (d *Dialer) DialUDP(ctx context.Context, network string, laddr, raddr *net.UDPAddr) (*UDPConn, error)
- func (d *Dialer) DialUnix(ctx context.Context, network string, laddr, raddr *net.UnixAddr) (*UnixConn, error)
- func (d *Dialer) SetAutoFixedFdInstall(auto bool)
- func (d *Dialer) SetFastOpen(use bool)
- func (d *Dialer) SetMultipathTCP(use bool)
- func (d *Dialer) SetQuickAck(use bool)
- func (d *Dialer) SetSendZC(use bool)
- type FixedFd
- type FixedReaderWriter
- type IPConn
- type ListenConfig
- func (lc *ListenConfig) Listen(ctx context.Context, network string, address string) (ln net.Listener, err error)
- func (lc *ListenConfig) ListenIP(_ context.Context, network string, addr *net.IPAddr) (*IPConn, error)
- func (lc *ListenConfig) ListenMulticastUDP(ctx context.Context, network string, ifi *net.Interface, addr *net.UDPAddr) (*UDPConn, error)
- func (lc *ListenConfig) ListenPacket(ctx context.Context, network, address string) (c net.PacketConn, err error)
- func (lc *ListenConfig) ListenTCP(ctx context.Context, network string, addr *net.TCPAddr) (*TCPListener, error)
- func (lc *ListenConfig) ListenUDP(ctx context.Context, network string, addr *net.UDPAddr) (*UDPConn, error)
- func (lc *ListenConfig) ListenUnix(ctx context.Context, network string, addr *net.UnixAddr) (*UnixListener, error)
- func (lc *ListenConfig) ListenUnixgram(ctx context.Context, network string, addr *net.UnixAddr) (*UnixConn, error)
- func (lc *ListenConfig) SetAutoFixedFdInstall(auto bool)
- func (lc *ListenConfig) SetFastOpen(use bool)
- func (lc *ListenConfig) SetMultipathTCP(use bool)
- func (lc *ListenConfig) SetMultishotAccept(multi bool)
- func (lc *ListenConfig) SetQuickAck(use bool)
- func (lc *ListenConfig) SetReusePort(use bool)
- func (lc *ListenConfig) SetSendZC(use bool)
- type TCPConn
- func (c *TCPConn) AcquireRegisteredBuffer() *aio.FixedBuffer
- func (c *TCPConn) Close() error
- func (c *TCPConn) CloseRead() error
- func (c *TCPConn) CloseWrite() error
- func (c *TCPConn) Context() context.Context
- func (c *TCPConn) File() (f *os.File, err error)
- func (c *TCPConn) FixedFdInstalled() bool
- func (c *TCPConn) InstallFixedFd() (err error)
- func (c *TCPConn) LocalAddr() net.Addr
- func (c *TCPConn) MultipathTCP() (bool, error)
- func (c *TCPConn) Read(b []byte) (n int, err error)
- func (c *TCPConn) ReadBuffer() (int, error)
- func (c *TCPConn) ReadFixed(buf *aio.FixedBuffer) (n int, err error)
- func (c *TCPConn) ReadFrom(r io.Reader) (int64, error)
- func (c *TCPConn) ReleaseRegisteredBuffer(buf *aio.FixedBuffer)
- func (c *TCPConn) RemoteAddr() net.Addr
- func (c *TCPConn) SetDeadline(t time.Time) error
- func (c *TCPConn) SetKeepAlive(keepalive bool) error
- func (c *TCPConn) SetKeepAliveConfig(config net.KeepAliveConfig) error
- func (c *TCPConn) SetKeepAlivePeriod(period time.Duration) error
- func (c *TCPConn) SetLinger(sec int) error
- func (c *TCPConn) SetNoDelay(noDelay bool) error
- func (c *TCPConn) SetReadBuffer(bytes int) error
- func (c *TCPConn) SetReadDeadline(t time.Time) error
- func (c *TCPConn) SetReadFromFilePolicy(policy int32)
- func (c *TCPConn) SetWriteBuffer(bytes int) error
- func (c *TCPConn) SetWriteDeadline(t time.Time) error
- func (c *TCPConn) SyscallConn() (syscall.RawConn, error)
- func (c *TCPConn) UseSendZC(use bool) bool
- func (c *TCPConn) Write(b []byte) (n int, err error)
- func (c *TCPConn) WriteBuffer() (int, error)
- func (c *TCPConn) WriteFixed(buf *aio.FixedBuffer) (n int, err error)
- func (c *TCPConn) WriteTo(w io.Writer) (int64, error)
- type TCPListener
- func (ln *TCPListener) Accept() (net.Conn, error)
- func (ln *TCPListener) AcceptTCP() (tc *TCPConn, err error)
- func (ln *TCPListener) Addr() net.Addr
- func (ln *TCPListener) Close() error
- func (ln *TCPListener) File() (f *os.File, err error)
- func (ln *TCPListener) FixedFdInstalled() bool
- func (ln *TCPListener) InstallFixedFd() error
- func (ln *TCPListener) SetDeadline(t time.Time) error
- func (ln *TCPListener) SyscallConn() (syscall.RawConn, error)
- type UDPConn
- func (c *UDPConn) AcquireRegisteredBuffer() *aio.FixedBuffer
- func (c *UDPConn) Close() error
- func (c *UDPConn) Context() context.Context
- func (c *UDPConn) File() (f *os.File, err error)
- func (c *UDPConn) FixedFdInstalled() bool
- func (c *UDPConn) InstallFixedFd() (err error)
- func (c *UDPConn) LocalAddr() net.Addr
- func (c *UDPConn) Read(b []byte) (n int, err error)
- func (c *UDPConn) ReadBuffer() (int, error)
- func (c *UDPConn) ReadFixed(buf *aio.FixedBuffer) (n int, err error)
- func (c *UDPConn) ReadFrom(b []byte) (n int, addr net.Addr, err error)
- func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error)
- func (c *UDPConn) ReadFromUDPAddrPort(b []byte) (n int, addr netip.AddrPort, err error)
- func (c *UDPConn) ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *net.UDPAddr, err error)
- func (c *UDPConn) ReadMsgUDPAddrPort(b, oob []byte) (n, oobn, flags int, addr netip.AddrPort, err error)
- func (c *UDPConn) ReleaseRegisteredBuffer(buf *aio.FixedBuffer)
- func (c *UDPConn) RemoteAddr() net.Addr
- func (c *UDPConn) SetDeadline(t time.Time) error
- func (c *UDPConn) SetReadBuffer(bytes int) error
- func (c *UDPConn) SetReadDeadline(t time.Time) error
- func (c *UDPConn) SetWriteBuffer(bytes int) error
- func (c *UDPConn) SetWriteDeadline(t time.Time) error
- func (c *UDPConn) SyscallConn() (syscall.RawConn, error)
- func (c *UDPConn) UseSendMSGZC(use bool) bool
- func (c *UDPConn) UseSendZC(use bool) bool
- func (c *UDPConn) Write(b []byte) (n int, err error)
- func (c *UDPConn) WriteBuffer() (int, error)
- func (c *UDPConn) WriteFixed(buf *aio.FixedBuffer) (n int, err error)
- func (c *UDPConn) WriteMsgUDP(b, oob []byte, addr *net.UDPAddr) (n, oobn int, err error)
- func (c *UDPConn) WriteMsgUDPAddrPort(b, oob []byte, addr netip.AddrPort) (n, oobn int, err error)
- func (c *UDPConn) WriteTo(b []byte, addr net.Addr) (n int, err error)
- func (c *UDPConn) WriteToUDP(b []byte, addr *net.UDPAddr) (n int, err error)
- func (c *UDPConn) WriteToUDPAddrPort(b []byte, addr netip.AddrPort) (n int, err error)
- type UnixConn
- func (c *UnixConn) AcquireRegisteredBuffer() *aio.FixedBuffer
- func (c *UnixConn) Close() error
- func (c *UnixConn) Context() context.Context
- func (c *UnixConn) File() (f *os.File, err error)
- func (c *UnixConn) FixedFdInstalled() bool
- func (c *UnixConn) InstallFixedFd() (err error)
- func (c *UnixConn) LocalAddr() net.Addr
- func (c *UnixConn) Read(b []byte) (n int, err error)
- func (c *UnixConn) ReadBuffer() (int, error)
- func (c *UnixConn) ReadFixed(buf *aio.FixedBuffer) (n int, err error)
- func (c *UnixConn) ReadFrom(b []byte) (int, net.Addr, error)
- func (c *UnixConn) ReadFromUnix(b []byte) (n int, addr *net.UnixAddr, err error)
- func (c *UnixConn) ReadMsgUnix(b []byte, oob []byte) (n, oobn, flags int, addr *net.UnixAddr, err error)
- func (c *UnixConn) ReleaseRegisteredBuffer(buf *aio.FixedBuffer)
- func (c *UnixConn) RemoteAddr() net.Addr
- func (c *UnixConn) SetDeadline(t time.Time) error
- func (c *UnixConn) SetReadBuffer(bytes int) error
- func (c *UnixConn) SetReadDeadline(t time.Time) error
- func (c *UnixConn) SetWriteBuffer(bytes int) error
- func (c *UnixConn) SetWriteDeadline(t time.Time) error
- func (c *UnixConn) SyscallConn() (syscall.RawConn, error)
- func (c *UnixConn) UseSendMSGZC(use bool) bool
- func (c *UnixConn) UseSendZC(use bool) bool
- func (c *UnixConn) Write(b []byte) (n int, err error)
- func (c *UnixConn) WriteBuffer() (int, error)
- func (c *UnixConn) WriteFixed(buf *aio.FixedBuffer) (n int, err error)
- func (c *UnixConn) WriteMsgUnix(b []byte, oob []byte, addr *net.UnixAddr) (n int, oobn int, err error)
- func (c *UnixConn) WriteTo(b []byte, addr net.Addr) (int, error)
- func (c *UnixConn) WriteToUnix(b []byte, addr *net.UnixAddr) (int, error)
- type UnixListener
- func (ln *UnixListener) Accept() (net.Conn, error)
- func (ln *UnixListener) AcceptUnix() (c *UnixConn, err error)
- func (ln *UnixListener) Addr() net.Addr
- func (ln *UnixListener) Close() error
- func (ln *UnixListener) File() (f *os.File, err error)
- func (ln *UnixListener) FixedFdInstalled() bool
- func (ln *UnixListener) InstallFixedFd() error
- func (ln *UnixListener) SetDeadline(t time.Time) error
- func (ln *UnixListener) SetUnlinkOnClose(unlink bool)
- func (ln *UnixListener) SyscallConn() (syscall.RawConn, error)
Constants ¶
const ( ReadFromFileUseMMapPolicy = int32(iota) ReadFromFileUseMixPolicy )
Variables ¶
var ( DefaultDialer = Dialer{ Timeout: 15 * time.Second, Deadline: time.Time{}, LocalAddr: nil, KeepAlive: 0, KeepAliveConfig: net.KeepAliveConfig{Enable: true}, MultipathTCP: false, FastOpen: false, QuickAck: false, SendZC: false, AutoFixedFdInstall: false, Control: nil, ControlContext: nil, } )
Functions ¶
func Dial ¶
Dial connects to the address on the named network.
Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), "ip", "ip4" (IPv4-only), "ip6" (IPv6-only), "unix", "unixgram" and "unixpacket".
For TCP and UDP networks, the address has the form "host:port". The host must be a literal IP address, or a host name that can be resolved to IP addresses. The port must be a literal port number or a service name. If the host is a literal IPv6 address it must be enclosed in square brackets, as in "[2001:db8::1]:80" or "[fe80::1%zone]:80". The zone specifies the scope of the literal IPv6 address as defined in RFC 4007. The functions [JoinHostPort] and [SplitHostPort] manipulate a pair of host and port in this form. When using TCP, and the host resolves to multiple IP addresses, Dial will try each IP address in order until one succeeds.
Examples:
Dial("tcp", "golang.org:http") Dial("tcp", "192.0.2.1:http") Dial("tcp", "198.51.100.1:80") Dial("udp", "[2001:db8::1]:domain") Dial("udp", "[fe80::1%lo0]:53") Dial("tcp", ":80")
For IP networks, the network must be "ip", "ip4" or "ip6" followed by a colon and a literal protocol number or a protocol name, and the address has the form "host". The host must be a literal IP address or a literal IPv6 address with zone. It depends on each operating system how the operating system behaves with a non-well known protocol number such as "0" or "255".
Examples:
Dial("ip4:1", "192.0.2.1") Dial("ip6:ipv6-icmp", "2001:db8::1") Dial("ip6:58", "fe80::1%lo0")
For TCP, UDP and IP networks, if the host is empty or a literal unspecified IP address, as in ":80", "0.0.0.0:80" or "[::]:80" for TCP and UDP, "", "0.0.0.0" or "::" for IP, the local system is assumed.
For Unix networks, the address must be a file system path.
func DialContext ¶
DialContext same as Dial but takes a context.
func DialContextTimeout ¶ added in v1.5.6
func DialContextTimeout(ctx context.Context, network string, address string, timeout time.Duration) (net.Conn, error)
DialContextTimeout acts like DialTimeout but takes a context.
func DialTimeout ¶
DialTimeout acts like Dial but takes a timeout.
The timeout includes name resolution, if required. When using TCP, and the host in the address parameter resolves to multiple IP addresses, the timeout is spread over each consecutive dial, such that each is given an appropriate fraction of the time to connect.
See func Dial for a description of the network and address parameters.
func Listen ¶
Listen announces on the local network address.
The network must be "tcp", "tcp4", "tcp6", "unix" or "unixpacket".
For TCP networks, if the host in the address parameter is empty or a literal unspecified IP address, Listen listens on all available unicast and anycast IP addresses of the local system. To only use IPv4, use network "tcp4". The address can use a host name, but this is not recommended, because it will create a listener for at most one of the host's IP addresses. If the port in the address parameter is empty or "0", as in "127.0.0.1:" or "[::1]:0", a port number is automatically chosen. The [Addr] method of [Listener] can be used to discover the chosen port.
See func Dial for a description of the network and address parameters.
Listen uses context.Background internally; to specify the context, use ListenConfig.Listen.
func ListenPacket ¶
func ListenPacket(network string, addr string) (c net.PacketConn, err error)
ListenPacket announces on the local network address.
The network must be "udp", "udp4", "udp6", "unixgram", or an IP transport. The IP transports are "ip", "ip4", or "ip6" followed by a colon and a literal protocol number or a protocol name, as in "ip:1" or "ip:icmp".
For UDP and IP networks, if the host in the address parameter is empty or a literal unspecified IP address, ListenPacket listens on all available IP addresses of the local system except multicast IP addresses. To only use IPv4, use network "udp4" or "ip4:proto". The address can use a host name, but this is not recommended, because it will create a listener for at most one of the host's IP addresses. If the port in the address parameter is empty or "0", as in "127.0.0.1:" or "[::1]:0", a port number is automatically chosen. The LocalAddr method of [PacketConn] can be used to discover the chosen port.
See func Dial for a description of the network and address parameters.
ListenPacket uses context.Background internally; to specify the context, use ListenConfig.ListenPacket.
func Pin ¶
func Pin() error
Pin usually used during program startup. such as only use Dial case, Pin before Dial and Unpin when program exit.
func Presets ¶ added in v1.5.6
Presets preset aio options, must be called before Pin, Dial and Listen.
func UseProcessPriority ¶
func UseProcessPriority(level process.PriorityLevel)
UseProcessPriority set process priority
Types ¶
type Dialer ¶
type Dialer struct { Timeout time.Duration Deadline time.Time KeepAlive time.Duration KeepAliveConfig net.KeepAliveConfig LocalAddr net.Addr MultipathTCP bool FastOpen bool QuickAck bool SendZC bool AutoFixedFdInstall bool Control func(network, address string, c syscall.RawConn) error ControlContext func(ctx context.Context, network, address string, c syscall.RawConn) error }
func (*Dialer) Dial ¶
Dial connects to the address on the named network.
See func Dial for a description of the network and address parameters.
Dial uses context.Background internally; to specify the context, use Dialer.DialContext.
func (*Dialer) DialContext ¶
DialContext connects to the address on the named network using the provided context.
The provided Context must be non-nil. If the context expires before the connection is complete, an error is returned. Once successfully connected, any expiration of the context will not affect the connection.
When using TCP, and the host in the address parameter resolves to multiple network addresses, any dial timeout (from d.Timeout or ctx) is spread over each consecutive dial, such that each is given an appropriate fraction of the time to connect. For example, if a host has 4 IP addresses and the timeout is 1 minute, the connect to each single address will be given 15 seconds to complete before trying the next one.
See func Dial for a description of the network and address parameters.
func (*Dialer) DialIP ¶
func (d *Dialer) DialIP(_ context.Context, network string, laddr, raddr *net.IPAddr) (*IPConn, error)
DialIP acts like Dial for IP networks.
The network must be an IP 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 (*Dialer) DialTCP ¶
func (d *Dialer) DialTCP(ctx context.Context, network string, laddr, raddr *net.TCPAddr) (*TCPConn, error)
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 (*Dialer) DialUDP ¶
func (d *Dialer) DialUDP(ctx context.Context, network string, laddr, raddr *net.UDPAddr) (*UDPConn, error)
DialUDP acts like Dial for UDP networks.
The network must be a UDP 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 (*Dialer) DialUnix ¶
func (d *Dialer) DialUnix(ctx context.Context, network string, laddr, raddr *net.UnixAddr) (*UnixConn, error)
DialUnix acts like Dial for Unix networks.
The network must be a Unix network name; see func Dial for details.
If laddr is non-nil, it is used as the local address for the connection.
func (*Dialer) SetAutoFixedFdInstall ¶ added in v1.5.6
SetAutoFixedFdInstall set auto install fixed fd.
auto install fixed fd when connected. available after [RIO_IOURING_REG_FIXED_FILES] set.
func (*Dialer) SetMultipathTCP ¶
SetMultipathTCP set multi-path tcp.
type FixedFd ¶ added in v1.5.6
type FixedFd interface { // InstallFixedFd // install fixed fd into iouring. InstallFixedFd() (err error) // FixedFdInstalled // check installed. FixedFdInstalled() bool }
FixedFd it is used to install fd into iouring.
func ConvertToFixedFd ¶ added in v1.5.6
ConvertToFixedFd convert net.Conn, rio.TCPListener or rio.UnixListener to FixedFd.
type FixedReaderWriter ¶ added in v1.3.0
type FixedReaderWriter interface { // AcquireRegisteredBuffer // acquire a buffer. // Note! must release buffer after used. AcquireRegisteredBuffer() *aio.FixedBuffer // ReleaseRegisteredBuffer // release a buffer. ReleaseRegisteredBuffer(buf *aio.FixedBuffer) // ReadFixed // read via registered fixed buffer. ReadFixed(buf *aio.FixedBuffer) (n int, err error) // WriteFixed // write via registered fixed buffer. WriteFixed(buf *aio.FixedBuffer) (n int, err error) }
FixedReaderWriter use fixed buffer to read and write, which is registered in iouring.
func ConvertToFixedReaderWriter ¶ added in v1.5.6
func ConvertToFixedReaderWriter(c net.Conn) (fixed FixedReaderWriter, ok bool)
ConvertToFixedReaderWriter convert net.Conn to FixedReaderWriter.
type IPConn ¶
IPConn is the implementation of the net.Conn and net.PacketConn interfaces for IP network connections.
func DialIP ¶
DialIP acts like Dial for IP networks.
The network must be an IP 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 ListenIP ¶
ListenIP acts like ListenPacket for IP networks.
The network must be an IP network name; see func Dial for details.
If the IP field of laddr is nil or an unspecified IP address, ListenIP listens on all available IP addresses of the local system except multicast IP addresses.
type ListenConfig ¶
type ListenConfig struct { // If Control is not nil, it is called after creating the network // connection but before binding it to the operating system. // // Network and address parameters passed to Control function are not // necessarily the ones passed to Listen. Calling Listen with TCP networks // will cause the Control function to be called with "tcp4" or "tcp6", // UDP networks become "udp4" or "udp6", IP networks become "ip4" or "ip6", // and other known networks are passed as-is. Control func(network, address string, c syscall.RawConn) error // KeepAlive specifies the keep-alive period for network // connections accepted by this listener. // // KeepAlive is ignored if KeepAliveConfig.Enable is true. // // If zero, keep-alive are enabled if supported by the protocol // and operating system. Network protocols or operating systems // that do not support keep-alive ignore this field. // If negative, keep-alive are disabled. KeepAlive time.Duration // KeepAliveConfig specifies the keep-alive probe configuration // for an active network connection, when supported by the // protocol and operating system. // // If KeepAliveConfig.Enable is true, keep-alive probes are enabled. // If KeepAliveConfig.Enable is false and KeepAlive is negative, // keep-alive probes are disabled. KeepAliveConfig net.KeepAliveConfig // MultipathTCP is set to a value allowing Multipath TCP (MPTCP) to be // used, any call to Listen with "tcp(4|6)" as network will use MPTCP if // supported by the operating system. MultipathTCP bool // FastOpen is set TCP_FASTOPEN FastOpen bool // QuickAck is set TCP_QUICKACK QuickAck bool // ReusePort is set SO_REUSEPORT ReusePort bool // SendZC is set IOURING.OP_SENDZC SendZC bool // MultishotAccept is set use IOURING.OP_MULTISHOT_ACCEPT MultishotAccept bool // AutoFixedFdInstall is set install conn fd into iouring after accepted. AutoFixedFdInstall bool }
ListenConfig contains options for listening to an address.
func (*ListenConfig) Listen ¶
func (lc *ListenConfig) Listen(ctx context.Context, network string, address string) (ln net.Listener, err error)
Listen announces on the local network address.
See func Listen for a description of the network and address parameters.
The ctx argument is used while resolving the address on which to listen; it does not affect the returned Listener.
func (*ListenConfig) ListenIP ¶
func (lc *ListenConfig) ListenIP(_ context.Context, network string, addr *net.IPAddr) (*IPConn, error)
ListenIP acts like ListenPacket for IP networks.
The network must be an IP network name; see func Dial for details.
If the IP field of laddr is nil or an unspecified IP address, ListenIP listens on all available IP addresses of the local system except multicast IP addresses.
func (*ListenConfig) ListenMulticastUDP ¶
func (lc *ListenConfig) ListenMulticastUDP(ctx context.Context, network string, ifi *net.Interface, addr *net.UDPAddr) (*UDPConn, error)
ListenMulticastUDP acts like ListenPacket for UDP networks but takes a group address on a specific network interface.
The network must be a UDP network name; see func Dial for details.
ListenMulticastUDP listens on all available IP addresses of the local system including the group, multicast IP address. If ifi is nil, ListenMulticastUDP uses the system-assigned multicast interface, although this is not recommended because the assignment depends on platforms and sometimes it might require routing configuration. If the Port field of gaddr is 0, a port number is automatically chosen.
ListenMulticastUDP is just for convenience of simple, small applications. There are golang.org/x/net/ipv4 and golang.org/x/net/ipv6 packages for general purpose uses.
Note that ListenMulticastUDP will set the IP_MULTICAST_LOOP socket option to 0 under IPPROTO_IP, to disable loopback of multicast packets.
func (*ListenConfig) ListenPacket ¶
func (lc *ListenConfig) ListenPacket(ctx context.Context, network, address string) (c net.PacketConn, err error)
ListenPacket announces on the local network address.
See func ListenPacket for a description of the network and address parameters.
The ctx argument is used while resolving the address on which to listen; it does not affect the returned Listener.
func (*ListenConfig) ListenTCP ¶
func (lc *ListenConfig) ListenTCP(ctx context.Context, network string, addr *net.TCPAddr) (*TCPListener, 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 (*ListenConfig) ListenUDP ¶
func (lc *ListenConfig) ListenUDP(ctx context.Context, network string, addr *net.UDPAddr) (*UDPConn, error)
ListenUDP acts like ListenPacket for UDP networks.
The network must be a UDP network name; see func Dial for details.
If the IP field of laddr is nil or an unspecified IP address, ListenUDP listens on all available IP addresses of the local system except multicast IP addresses. If the Port field of laddr is 0, a port number is automatically chosen.
func (*ListenConfig) ListenUnix ¶
func (lc *ListenConfig) ListenUnix(ctx context.Context, network string, addr *net.UnixAddr) (*UnixListener, error)
ListenUnix acts like Listen for Unix networks.
The network must be "unix" or "unixpacket".
func (*ListenConfig) ListenUnixgram ¶
func (lc *ListenConfig) ListenUnixgram(ctx context.Context, network string, addr *net.UnixAddr) (*UnixConn, error)
ListenUnixgram acts like ListenPacket for Unix networks.
The network must be "unixgram".
func (*ListenConfig) SetAutoFixedFdInstall ¶ added in v1.5.6
func (lc *ListenConfig) SetAutoFixedFdInstall(auto bool)
func (*ListenConfig) SetFastOpen ¶
func (lc *ListenConfig) SetFastOpen(use bool)
func (*ListenConfig) SetMultipathTCP ¶
func (lc *ListenConfig) SetMultipathTCP(use bool)
func (*ListenConfig) SetMultishotAccept ¶ added in v1.5.6
func (lc *ListenConfig) SetMultishotAccept(multi bool)
func (*ListenConfig) SetQuickAck ¶
func (lc *ListenConfig) SetQuickAck(use bool)
func (*ListenConfig) SetReusePort ¶
func (lc *ListenConfig) SetReusePort(use bool)
func (*ListenConfig) SetSendZC ¶
func (lc *ListenConfig) SetSendZC(use bool)
type TCPConn ¶
type TCPConn struct {
// contains filtered or unexported fields
}
TCPConn is an implementation of the net.Conn interface for TCP network connections.
func DialTCP ¶
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 (*TCPConn) AcquireRegisteredBuffer ¶ added in v1.3.0
func (c *TCPConn) AcquireRegisteredBuffer() *aio.FixedBuffer
AcquireRegisteredBuffer implements the FixedReaderWriter AcquireRegisteredBuffer method.
func (*TCPConn) CloseRead ¶
CloseRead shuts down the reading side of the TCP connection. Most callers should just use Close.
func (*TCPConn) CloseWrite ¶
CloseWrite shuts down the writing side of the TCP connection. Most callers should just use Close.
func (*TCPConn) File ¶
File returns a copy of the underlying os.File. It is the caller's responsibility to close f when finished. Closing c does not affect f, and closing f does not affect c.
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 (*TCPConn) FixedFdInstalled ¶ added in v1.5.6
func (c *TCPConn) FixedFdInstalled() bool
FixedFdInstalled implements the FixedFd FixedFdInstalled method.
func (*TCPConn) InstallFixedFd ¶ added in v1.5.6
func (c *TCPConn) InstallFixedFd() (err error)
InstallFixedFd implements the FixedFd InstallFixedFd method.
func (*TCPConn) MultipathTCP ¶
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 (*TCPConn) ReadFixed ¶ added in v1.3.0
func (c *TCPConn) ReadFixed(buf *aio.FixedBuffer) (n int, err error)
ReadFixed implements the FixedReaderWriter ReadFixed method.
func (*TCPConn) ReadFrom ¶
ReadFrom implements the io.ReaderFrom ReadFrom method.
func (*TCPConn) ReleaseRegisteredBuffer ¶ added in v1.3.0
func (c *TCPConn) ReleaseRegisteredBuffer(buf *aio.FixedBuffer)
ReleaseRegisteredBuffer implements the FixedReaderWriter ReleaseRegisteredBuffer method.
func (*TCPConn) RemoteAddr ¶
RemoteAddr implements the net.Conn RemoteAddr method.
func (*TCPConn) SetDeadline ¶
SetDeadline implements the net.Conn SetDeadline method.
func (*TCPConn) SetKeepAlive ¶
SetKeepAlive sets whether the operating system should send keep-alive messages on the connection.
func (*TCPConn) SetKeepAliveConfig ¶
func (c *TCPConn) SetKeepAliveConfig(config net.KeepAliveConfig) error
SetKeepAliveConfig configures keep-alive messages sent by the operating system.
func (*TCPConn) SetKeepAlivePeriod ¶
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 (*TCPConn) SetLinger ¶
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 (*TCPConn) SetNoDelay ¶
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 (*TCPConn) SetReadBuffer ¶
SetReadBuffer set SO_RCVBUF.
func (*TCPConn) SetReadDeadline ¶
SetReadDeadline implements the net.Conn SetReadDeadline method.
func (*TCPConn) SetReadFromFilePolicy ¶ added in v1.5.6
func (*TCPConn) SetWriteBuffer ¶
SetWriteBuffer set SO_SNDBUF.
func (*TCPConn) SetWriteDeadline ¶
SetWriteDeadline implements the net.Conn SetWriteDeadline method.
func (*TCPConn) SyscallConn ¶
SyscallConn returns a raw network connection. This implements the syscall.Conn interface.
func (*TCPConn) WriteBuffer ¶
WriteBuffer get SO_SNDBUF.
func (*TCPConn) WriteFixed ¶ added in v1.3.0
func (c *TCPConn) WriteFixed(buf *aio.FixedBuffer) (n int, err error)
WriteFixed implements the FixedReaderWriter WriteFixed method.
type TCPListener ¶
type TCPListener struct {
// contains filtered or unexported fields
}
TCPListener is a TCP network listener. Clients should typically use variables of type net.Listener instead of assuming TCP.
func ListenTCP ¶
func ListenTCP(network string, addr *net.TCPAddr) (*TCPListener, 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 (*TCPListener) Accept ¶
func (ln *TCPListener) Accept() (net.Conn, error)
Accept implements the Accept method in the net.Listener interface; it waits for the next call and returns a generic net.Conn.
func (*TCPListener) AcceptTCP ¶
func (ln *TCPListener) AcceptTCP() (tc *TCPConn, err error)
AcceptTCP accepts the next incoming call and returns the new connection.
func (*TCPListener) Addr ¶
func (ln *TCPListener) Addr() net.Addr
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 (*TCPListener) Close ¶
func (ln *TCPListener) Close() error
Close stops listening on the TCP address. Already Accepted connections are not closed.
func (*TCPListener) File ¶
func (ln *TCPListener) File() (f *os.File, err 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 (*TCPListener) FixedFdInstalled ¶ added in v1.5.6
func (ln *TCPListener) FixedFdInstalled() bool
FixedFdInstalled implements the FixedFdInstalled method in the FixedFd interface.
func (*TCPListener) InstallFixedFd ¶ added in v1.5.6
func (ln *TCPListener) InstallFixedFd() error
InstallFixedFd implements the InstallFixedFd method in the FixedFd interface.
func (*TCPListener) SetDeadline ¶
func (ln *TCPListener) SetDeadline(t time.Time) error
SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline. Only valid when not multishot accept mode.
func (*TCPListener) SyscallConn ¶
func (ln *TCPListener) SyscallConn() (syscall.RawConn, error)
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.
type UDPConn ¶
type UDPConn struct {
// contains filtered or unexported fields
}
UDPConn is the implementation of the net.Conn and net.PacketConn interfaces for UDP network connections.
func DialUDP ¶
DialUDP acts like Dial for UDP networks.
The network must be a UDP 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 ListenMulticastUDP ¶
ListenMulticastUDP acts like ListenPacket for UDP networks but takes a group address on a specific network interface.
The network must be a UDP network name; see func Dial for details.
ListenMulticastUDP listens on all available IP addresses of the local system including the group, multicast IP address. If ifi is nil, ListenMulticastUDP uses the system-assigned multicast interface, although this is not recommended because the assignment depends on platforms and sometimes it might require routing configuration. If the Port field of gaddr is 0, a port number is automatically chosen.
ListenMulticastUDP is just for convenience of simple, small applications. There are golang.org/x/net/ipv4 and golang.org/x/net/ipv6 packages for general purpose uses.
Note that ListenMulticastUDP will set the IP_MULTICAST_LOOP socket option to 0 under IPPROTO_IP, to disable loopback of multicast packets.
func ListenUDP ¶
ListenUDP acts like ListenPacket for UDP networks.
The network must be a UDP network name; see func Dial for details.
If the IP field of laddr is nil or an unspecified IP address, ListenUDP listens on all available IP addresses of the local system except multicast IP addresses. If the Port field of laddr is 0, a port number is automatically chosen.
func (*UDPConn) AcquireRegisteredBuffer ¶ added in v1.3.0
func (c *UDPConn) AcquireRegisteredBuffer() *aio.FixedBuffer
AcquireRegisteredBuffer implements the FixedReaderWriter AcquireRegisteredBuffer method.
func (*UDPConn) File ¶
File returns a copy of the underlying os.File. It is the caller's responsibility to close f when finished. Closing c does not affect f, and closing f does not affect c.
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 (*UDPConn) FixedFdInstalled ¶ added in v1.5.6
func (c *UDPConn) FixedFdInstalled() bool
FixedFdInstalled implements the FixedFd FixedFdInstalled method.
func (*UDPConn) InstallFixedFd ¶ added in v1.5.6
func (c *UDPConn) InstallFixedFd() (err error)
InstallFixedFd implements the FixedFd InstallFixedFd method.
func (*UDPConn) ReadFixed ¶ added in v1.3.0
func (c *UDPConn) ReadFixed(buf *aio.FixedBuffer) (n int, err error)
ReadFixed implements the FixedReaderWriter ReadFixed method.
func (*UDPConn) ReadFrom ¶
ReadFrom implements the net.PacketConn ReadFrom method.
func (*UDPConn) ReadFromUDP ¶
ReadFromUDP acts like UDPConn.ReadFrom but returns a net.UDPAddr.
func (*UDPConn) ReadFromUDPAddrPort ¶
ReadFromUDPAddrPort acts like ReadFrom but returns a netip.AddrPort.
If c is bound to an unspecified address, the returned netip.AddrPort's address might be an IPv4-mapped IPv6 address. Use netip.Addr.Unmap to get the address without the IPv6 prefix.
func (*UDPConn) ReadMsgUDP ¶
ReadMsgUDP reads a message from c, copying the payload into b and the associated out-of-band data into oob. It returns the number of bytes copied into b, the number of bytes copied into oob, the flags that were set on the message and the source address of the message.
The packages golang.org/x/net/ipv4 and golang.org/x/net/ipv6 can be used to manipulate IP-level socket options in oob.
func (*UDPConn) ReadMsgUDPAddrPort ¶
func (c *UDPConn) ReadMsgUDPAddrPort(b, oob []byte) (n, oobn, flags int, addr netip.AddrPort, err error)
ReadMsgUDPAddrPort is like UDPConn.ReadMsgUDP but returns an netip.AddrPort instead of a net.UDPAddr.
func (*UDPConn) ReleaseRegisteredBuffer ¶ added in v1.3.0
func (c *UDPConn) ReleaseRegisteredBuffer(buf *aio.FixedBuffer)
ReleaseRegisteredBuffer implements the FixedReaderWriter ReleaseRegisteredBuffer method.
func (*UDPConn) RemoteAddr ¶
RemoteAddr implements the net.Conn RemoteAddr method.
func (*UDPConn) SetDeadline ¶
SetDeadline implements the net.Conn SetDeadline method.
func (*UDPConn) SetReadBuffer ¶
SetReadBuffer set SO_RCVBUF.
func (*UDPConn) SetReadDeadline ¶
SetReadDeadline implements the net.Conn SetReadDeadline method.
func (*UDPConn) SetWriteBuffer ¶
SetWriteBuffer set SO_SNDBUF.
func (*UDPConn) SetWriteDeadline ¶
SetWriteDeadline implements the net.Conn SetWriteDeadline method.
func (*UDPConn) SyscallConn ¶
SyscallConn returns a raw network connection. This implements the syscall.Conn interface.
func (*UDPConn) UseSendMSGZC ¶ added in v1.5.6
UseSendMSGZC try to enable sendmsg_zc.
func (*UDPConn) WriteBuffer ¶
WriteBuffer get SO_SNDBUF.
func (*UDPConn) WriteFixed ¶ added in v1.3.0
func (c *UDPConn) WriteFixed(buf *aio.FixedBuffer) (n int, err error)
WriteFixed implements the FixedReaderWriter WriteFixed method.
func (*UDPConn) WriteMsgUDP ¶
WriteMsgUDP writes a message to addr via c if c isn't connected, or to c's remote address if c is connected (in which case addr must be nil). The payload is copied from b and the associated out-of-band data is copied from oob. It returns the number of payload and out-of-band bytes written.
The packages golang.org/x/net/ipv4 and golang.org/x/net/ipv6 can be used to manipulate IP-level socket options in oob.
func (*UDPConn) WriteMsgUDPAddrPort ¶
WriteMsgUDPAddrPort is like UDPConn.WriteMsgUDP but takes a netip.AddrPort instead of a net.UDPAddr.
func (*UDPConn) WriteTo ¶
WriteTo implements the net.PacketConn WriteTo method.
func (*UDPConn) WriteToUDP ¶
WriteToUDP acts like UDPConn.WriteTo but takes a [UDPAddr].
func (*UDPConn) WriteToUDPAddrPort ¶
WriteToUDPAddrPort acts like UDPConn.WriteTo but takes a netip.AddrPort.
type UnixConn ¶
type UnixConn struct {
// contains filtered or unexported fields
}
UnixConn is an implementation of the net.Conn interface for connections to Unix domain sockets.
func DialUnix ¶
DialUnix acts like Dial for Unix networks.
The network must be a Unix network name; see func Dial for details.
If laddr is non-nil, it is used as the local address for the connection.
func ListenUnixgram ¶
ListenUnixgram acts like ListenPacket for Unix networks.
The network must be "unixgram".
func (*UnixConn) AcquireRegisteredBuffer ¶ added in v1.3.0
func (c *UnixConn) AcquireRegisteredBuffer() *aio.FixedBuffer
AcquireRegisteredBuffer implements the FixedReaderWriter AcquireRegisteredBuffer method.
func (*UnixConn) Close ¶
func (c *UnixConn) Close() error
Close implements the net.Conn Close method.
func (*UnixConn) File ¶
File returns a copy of the underlying os.File. It is the caller's responsibility to close f when finished. Closing c does not affect f, and closing f does not affect c.
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 (*UnixConn) FixedFdInstalled ¶ added in v1.5.6
func (c *UnixConn) FixedFdInstalled() bool
FixedFdInstalled implements the FixedFd FixedFdInstalled method.
func (*UnixConn) InstallFixedFd ¶ added in v1.5.6
func (c *UnixConn) InstallFixedFd() (err error)
InstallFixedFd implements the FixedFd InstallFixedFd method.
func (*UnixConn) ReadBuffer ¶
ReadBuffer get SO_RCVBUF.
func (*UnixConn) ReadFixed ¶ added in v1.3.0
func (c *UnixConn) ReadFixed(buf *aio.FixedBuffer) (n int, err error)
ReadFixed implements the FixedReaderWriter ReadFixed method.
func (*UnixConn) ReadFrom ¶
ReadFrom implements the net.PacketConn ReadFrom method.
func (*UnixConn) ReadFromUnix ¶
ReadFromUnix acts like UnixConn.ReadFrom but returns a net.UnixAddr.
func (*UnixConn) ReadMsgUnix ¶
func (c *UnixConn) ReadMsgUnix(b []byte, oob []byte) (n, oobn, flags int, addr *net.UnixAddr, err error)
ReadMsgUnix reads a message from c, copying the payload into b and the associated out-of-band data into oob. It returns the number of bytes copied into b, the number of bytes copied into oob, the flags that were set on the message and the source address of the message.
Note that if len(b) == 0 and len(oob) > 0, this function will still read (and discard) 1 byte from the connection.
func (*UnixConn) ReleaseRegisteredBuffer ¶ added in v1.3.0
func (c *UnixConn) ReleaseRegisteredBuffer(buf *aio.FixedBuffer)
ReleaseRegisteredBuffer implements the FixedReaderWriter ReleaseRegisteredBuffer method.
func (*UnixConn) RemoteAddr ¶
RemoteAddr implements the net.Conn RemoteAddr method.
func (*UnixConn) SetDeadline ¶
SetDeadline implements the net.Conn SetDeadline method.
func (*UnixConn) SetReadBuffer ¶
SetReadBuffer set SO_RCVBUF.
func (*UnixConn) SetReadDeadline ¶
SetReadDeadline implements the net.Conn SetReadDeadline method.
func (*UnixConn) SetWriteBuffer ¶
SetWriteBuffer set SO_SNDBUF.
func (*UnixConn) SetWriteDeadline ¶
SetWriteDeadline implements the net.Conn SetWriteDeadline method.
func (*UnixConn) SyscallConn ¶
SyscallConn returns a raw network connection. This implements the syscall.Conn interface.
func (*UnixConn) UseSendMSGZC ¶ added in v1.5.6
UseSendMSGZC try to enable sendmsg_zc.
func (*UnixConn) WriteBuffer ¶
WriteBuffer get SO_SNDBUF.
func (*UnixConn) WriteFixed ¶ added in v1.3.0
func (c *UnixConn) WriteFixed(buf *aio.FixedBuffer) (n int, err error)
WriteFixed implements the FixedReaderWriter WriteFixed method.
func (*UnixConn) WriteMsgUnix ¶
func (c *UnixConn) WriteMsgUnix(b []byte, oob []byte, addr *net.UnixAddr) (n int, oobn int, err error)
WriteMsgUnix writes a message to addr via c, copying the payload from b and the associated out-of-band data from oob. It returns the number of payload and out-of-band bytes written.
Note that if len(b) == 0 and len(oob) > 0, this function will still write 1 byte to the connection.
func (*UnixConn) WriteTo ¶
WriteTo implements the net.PacketConn WriteTo method.
func (*UnixConn) WriteToUnix ¶
WriteToUnix acts like UnixConn.WriteTo but takes a net.UnixAddr.
type UnixListener ¶
type UnixListener struct {
// contains filtered or unexported fields
}
UnixListener is a Unix domain socket listener. Clients should typically use variables of type net.Listener instead of assuming Unix domain sockets.
func ListenUnix ¶
func ListenUnix(network string, addr *net.UnixAddr) (*UnixListener, error)
ListenUnix acts like Listen for Unix networks.
The network must be "unix" or "unixpacket".
func (*UnixListener) Accept ¶
func (ln *UnixListener) Accept() (net.Conn, error)
Accept implements the Accept method in the net.Listener interface. Returned connections will be of type *UnixConn.
func (*UnixListener) AcceptUnix ¶
func (ln *UnixListener) AcceptUnix() (c *UnixConn, err error)
AcceptUnix accepts the next incoming call and returns the new connection.
func (*UnixListener) Addr ¶
func (ln *UnixListener) Addr() net.Addr
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 (*UnixListener) Close ¶
func (ln *UnixListener) Close() error
Close stops listening on the Unix address. Already accepted connections are not closed.
func (*UnixListener) File ¶
func (ln *UnixListener) File() (f *os.File, err 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 (*UnixListener) FixedFdInstalled ¶ added in v1.5.6
func (ln *UnixListener) FixedFdInstalled() bool
FixedFdInstalled implements the FixedFdInstalled method in the FixedFd interface.
func (*UnixListener) InstallFixedFd ¶ added in v1.5.6
func (ln *UnixListener) InstallFixedFd() error
InstallFixedFd implements the InstallFixedFd method in the FixedFd interface.
func (*UnixListener) SetDeadline ¶
func (ln *UnixListener) SetDeadline(t time.Time) error
SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline. Only valid when not multishot accept mode.
func (*UnixListener) SetUnlinkOnClose ¶
func (ln *UnixListener) SetUnlinkOnClose(unlink bool)
SetUnlinkOnClose sets whether the underlying socket file should be removed from the file system when the listener is closed.
The default behavior is to unlink the socket file only when package net created it. That is, when the listener and the underlying socket file were created by a call to Listen or ListenUnix, then by default closing the listener will remove the socket file. but if the listener was created by a call to FileListener to use an already existing socket file, then by default closing the listener will not remove the socket file.
func (*UnixListener) SyscallConn ¶
func (ln *UnixListener) SyscallConn() (syscall.RawConn, error)
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.