rio

package module
v1.6.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2025 License: LGPL-3.0 Imports: 13 Imported by: 0

README

RIO (中文)

An AIO network library based on IOURING, without using CGO, and following the design pattern of the standard library.

Supported protocols: TCP, UDP, UNIX, UNIXGRAM (IP is the proxy standard library).

RIO is a library that follows the usage pattern of the standard library and can be put into use very conveniently. Therefore, it is not a toy and can replace NET at a very low cost.

NOTE

  • Linux kernel version must be >= 6.13.
  • Scenarios that only use Dial require PIN and UNPIN to pin the kernel thread of IOURING.
  • NetworkingMode=mirrored cannot be enabled in WSL2.
  • Since DIRECT FD does not support CLOEXEC, it is necessary to close all FD when the program exits (close all links when both net.Http and fasthttp implement closure).

Features

  • Based on the implementation of net.Listener, net.Conn and net.PacketConn.
  • Use BATCH to reduce the overhead of SYSTEM CALL.
  • Support TLS.
  • Support MULTISHOT_ACCEPT MULTISHOT_RECV and MULTISHOT_RECV_FROM.
  • Support SEND_ZC and SENDMSG_ZC.
  • Support NAPI.
  • Support PERSIONALITY.
  • Supports CURVE to dynamically adjust the timeout of WAIT CQE to fit different scenarios.

Performances

TCP

echo benchmark echo benchmark

HTTP

echo benchmark
Endpoint Platform IP OS SKU
Client WSL2 192.168.100.1 Ubuntu22.04 (6.13.6-microsoft-standard-WSL2) 4C 16G
Server Hyper-V 192.168.100.120 Ubuntu24.10 (6.13.12-061312-generic) 4C 0.5G

Syscall

syscall_rio_sqpoll.png

syscall_rio_single.png

syscall_net.png

Lib Proportion Desc
RIO 33% (3%) 33% is the single publisher mode, and 3% is the SQ-POLL mode.
NET 74% Reading, writing, Epoll, etc. account for a total of 74%.

Usage

go get -u github.com/brickingsoft/rio

For basic use, replace net with github.com/brickingsoft/rio.

// replace net.Listen() with rio.Listen() 
ln, lnErr := rio.Listen("tcp", ":9000")
// replace net.Dial() with rio.Dial() 
conn, dialErr := rio.Dial("tcp", "127.0.0.1:9000")
SocketOPT

Use rio.Conn to set or get socketopt.

rc := conn.(rio.Conn)
setErr := rc.SetSocketOptInt(level, name, value)
value, getErr := rc.GetSocketOptInt(level, name)
TLS

Use the built-in security approach.

// server("github.com/brickingsoft/rio/security")
ln, _ = security.Listen("tcp", ":9000", config)

// client("github.com/brickingsoft/rio/security")
conn, _ = security.Dial("tcp", "127.0.0.1:9000", config)
HTTP

For server, use http.Server.Serve() replace Listener.

rio.Preset(
    aio.WithNAPIBusyPollTimeout(time.Microsecond * 50),
)

ln, lnErr := rio.Listen("tcp", ":9000")
if lnErr != nil {
    panic(lnErr)
    return
}

srv := &http.Server{
    Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        w.Header().Set("Content-Type", "text/html; charset=utf-8")
        w.WriteHeader(http.StatusOK)
        _, _ = w.Write([]byte("hello world"))
    }),
}

done := make(chan struct{}, 1)
go func(ln net.Listener, srv *http.Server, done chan<- struct{}) {
    if srvErr := srv.Serve(ln); srvErr != nil {
        if errors.Is(srvErr, http.ErrServerClosed) {
            close(done)
            return
        }
        panic(srvErr)
        return
	}
	close(done)
}(ln, srv, done)

signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGABRT, syscall.SIGTERM)
<-signalCh

if shutdownErr := srv.Shutdown(context.Background()); shutdownErr != nil {
    panic(shutdownErr)
}
<-done

For client, reset http.DefaultTransport.

http.DefaultTransport = &http.Transport{
    Proxy: http.ProxyFromEnvironment,
    DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
        dialer := rio.Dialer{
            Timeout:   30 * time.Second,
            KeepAlive: 30 * time.Second,
        }
        return dialer.DialContext(ctx, network, addr)
    },
    ForceAttemptHTTP2:     true,
    MaxIdleConns:          100,
    IdleConnTimeout:       90 * time.Second,
    TLSHandshakeTimeout:   10 * time.Second,
    ExpectContinueTimeout: 1 * time.Second,
}

resp, getErr := http.Get("http://127.0.0.1:9000/")
Types
tcpConn, ok := conn.(*rio.TCPConn)
udpConn, ok := conn.(*rio.UDPConn)
unixConn, ok := conn.(*rio.UnixConn)
rioConn, ok := conn.(rio.Conn)
Config

rio.ListenConfig is similar to net.ListenConfig and listens by configuration.

config := rio.ListenConfig{
    Control:            nil,                    
    KeepAlive:          0,                       
    KeepAliveConfig:    net.KeepAliveConfig{},   
    MultipathTCP:       false,                   
    ReusePort:          false,                  
}
ln, lnErr := config.Listen(context.Background(), "tcp", ":9000")

rio.Dialer is similar to net.Dialer and dials by configuration.

dialer := rio.Dialer{
    Timeout:            0,                          
    Deadline:           time.Time{},                
    KeepAlive:          0,                          
    KeepAliveConfig:    net.KeepAliveConfig{},      
    LocalAddr:          nil,                        
    FallbackDelay:      0,                           
    MultipathTCP:       false,                      
    Control:            nil,                       
    ControlContext:     nil,                        
}
conn, dialErr := dialer.DialContext(context.Background(), "tcp", "127.0.0.1:9000")
PIN and UNPIN

Because IOURING has a resource handling step in its setup and shutdown process, and its lifecycle is tied to the user's maximum lifecycle.

To prevent an instance from shutting down when it shouldn't, its lifecycle can be manually controlled via PIN and UNPIN, generally for scenarios where there is only DIAL or where there is more than one LISTEN.

// Calling before presetting and launching a link
rio.Pin()
// Called after all links are closed
rio.Unpin()
SQL

For postgres example, create a Dialer and use the Connector to open database.

type RIOPQDialer struct{}

func (d *RIOPQDialer) Dial(network, address string) (net.Conn, error) {
	return rio.Dial(network, address)
}

func (d *RIOPQDialer) DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) {
	return rio.DialTimeout(network, address, timeout)
}
connector, connectorErr := pq.NewConnector("{dsn}")
if connectorErr != nil {
    panic(connectorErr)
}
connector.Dialer(&RIOPQDialer{})
db := sql.OpenDB(connector)
CQE Wait Timeout Curve

Predefined aio.NCurve aio.SCurve and aio.LCurve.

Name Desc Scenes
NCurve Nil For non-single publishers only
SCurve Short For short links under single publisher
LCurve Long For long links under multiple publishers
Preset

Customize IOURING with presets.

rio.Peset(
    // Set the size of the IOURING, default is 16384, maximum is 32768.
    aio.WithEntries(liburing.DefaultEntries),
    // Set the Flags of the IOURING.
    // Optimized for single threading by default, how you need to turn on SQPOLL can be set.
    aio.WithFlags(liburing.IORING_SETUP_SINGLE_ISSUER),
    // Whether to enable SEND ZERO COPY.
    // Not turned on by default. Note: Some pressure testing tools cannot detect the return value.
    aio.WithSendZCEnabled(false),
    // Whether to disable multishot mode.
    // Not disabled by default.
    // Multishots can significantly reduce SQE casts, but will require additional resources such as registering and deregistering BufferAndRing.
    // Disable multishot mode is typically used in conjunction with enabling SQPOLL to significantly reduce the overhead of SYSCALL.
    aio.WithMultishotDisabled(false),
    // Set BufferAndRing config.
    // Effective in non-prohibited multishot mode.
    // A BufferAndRing serves only one Fd.
    // The parameter size is the size of the buffer, which is recommended to be a page size.
    // The parameter count is the number of buffer nodes in the ring.
    // The parameter idle timeout is the amount of time to idle before logging out when it is no longer in use.
    aio.WithBufferAndRingConfig(4096, 32, 5*time.Second),
    // Set the CQE wait timeout curve.
    aio.WithWaitCQETimeoutCurve(aio.SCurve),
    // Set the NAPI.
    // The minimum unit of timeout time is microsecond, which is not turned on by default.
    aio.WithNAPIBusyPollTimeout(50*time.Microsecond),
)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDialer = Dialer{
		Timeout:         15 * time.Second,
		Deadline:        time.Time{},
		KeepAlive:       0,
		KeepAliveConfig: net.KeepAliveConfig{Enable: true},
		LocalAddr:       nil,
		FallbackDelay:   0,
		MultipathTCP:    false,
		Control:         nil,
		ControlContext:  nil,
	}
)

Functions

func Dial

func Dial(network string, address string) (net.Conn, error)

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

func DialContext(ctx context.Context, network string, address string) (net.Conn, error)

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

func DialTimeout(network string, address string, timeout time.Duration) (net.Conn, error)

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

func Listen(network string, addr string) (ln net.Listener, err error)

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()

Pin iouring ctx, use for dial only or multi listen.

func Preset added in v1.6.0

func Preset(options ...aio.Option)

Preset aio options

func Unpin

func Unpin()

Unpin iouring ctx

Types

type Conn added in v1.6.0

type Conn interface {
	net.Conn
	// SetSocketOptInt set socket option, the func is limited to SOL_SOCKET level.
	SetSocketOptInt(level int, optName int, optValue int) (err error)
	// GetSocketOptInt get socket option, the func is limited to SOL_SOCKET level.
	GetSocketOptInt(level int, optName int) (optValue int, err error)
}

Conn is a generic stream-oriented network connection.

Multiple goroutines may invoke methods on a Conn simultaneously.

type Dialer

type Dialer struct {
	// Timeout is the maximum amount of time a dial will wait for
	// a connect to complete. If Deadline is also set, it may fail
	// earlier.
	//
	// The default is no timeout.
	//
	// When using TCP and dialing a host name with multiple IP
	// addresses, the timeout may be divided between them.
	//
	// With or without a timeout, the operating system may impose
	// its own earlier timeout. For instance, TCP timeouts are
	// often around 3 minutes.
	Timeout time.Duration
	// Deadline is the absolute point in time after which dials
	// will fail. If Timeout is set, it may fail earlier.
	// Zero means no deadline, or dependent on the operating system
	// as with the Timeout option.
	Deadline time.Time
	// KeepAlive specifies the interval between keep-alive
	// probes for an active network connection.
	//
	// KeepAlive is ignored if KeepAliveConfig.Enable is true.
	//
	// If zero, keep-alive probes are sent with a default value
	// (currently 15 seconds), 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 probes 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
	// LocalAddr is the local address to use when dialing an
	// address. The address must be of a compatible type for the
	// network being dialed.
	// If nil, a local address is automatically chosen.
	LocalAddr net.Addr
	// FallbackDelay specifies the length of time to wait before
	// spawning a RFC 6555 Fast Fallback connection. That is, this
	// is the amount of time to wait for IPv6 to succeed before
	// assuming that IPv6 is misconfigured and falling back to
	// IPv4.
	//
	// If zero, a default delay of 300ms is used.
	// A negative value disables Fast Fallback support.
	FallbackDelay time.Duration
	// If MultipathTCP is set to a value allowing Multipath TCP (MPTCP) to be
	// used, any call to Dial with "tcp(4|6)" as network will use MPTCP if
	// supported by the operating system.
	MultipathTCP bool
	// If Control is not nil, it is called after creating the network
	// connection but before actually dialing.
	//
	// Network and address parameters passed to Control function are not
	// necessarily the ones passed to Dial. Calling Dial 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 is ignored if ControlContext is not nil.
	Control func(network, address string, c syscall.RawConn) error
	// If ControlContext is not nil, it is called after creating the network
	// connection but before actually dialing.
	//
	// Network and address parameters passed to ControlContext function are not
	// necessarily the ones passed to Dial. Calling Dial with TCP networks
	// will cause the ControlContext 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.
	//
	// If ControlContext is not nil, Control is ignored.
	ControlContext func(ctx context.Context, network, address string, c syscall.RawConn) error
}

func (*Dialer) Dial

func (d *Dialer) Dial(network string, address string) (c net.Conn, err error)

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

func (d *Dialer) DialContext(ctx context.Context, network, address string) (c net.Conn, err error)

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) SetMultipathTCP

func (d *Dialer) SetMultipathTCP(use bool)

SetMultipathTCP set multi-path tcp.

type IPConn

type IPConn struct {
	*net.IPConn
}

IPConn is the implementation of the net.Conn and net.PacketConn interfaces for IP network connections.

func DialIP

func DialIP(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 ListenIP

func ListenIP(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.

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
	// ReusePort is set SO_REUSEPORT
	ReusePort 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) SetMultipathTCP

func (lc *ListenConfig) SetMultipathTCP(use bool)

SetMultipathTCP set multi-path tcp.

type Listener added in v1.6.0

type Listener interface {
	net.Listener
	// SetSocketOptInt set socket option, the func is limited to SOL_SOCKET level.
	SetSocketOptInt(level int, optName int, optValue int) (err error)
	// GetSocketOptInt get socket option, the func is limited to SOL_SOCKET level.
	GetSocketOptInt(level int, optName int) (optValue int, err error)
}

A Listener is a generic network listener for stream-oriented protocols.

Multiple goroutines may invoke methods on a Listener simultaneously.

type PacketConn added in v1.6.0

type PacketConn interface {
	net.PacketConn
	// SetSocketOptInt set socket option, the func is limited to SOL_SOCKET level.
	SetSocketOptInt(level int, optName int, optValue int) (err error)
	// GetSocketOptInt get socket option, the func is limited to SOL_SOCKET level.
	GetSocketOptInt(level int, optName int) (optValue int, err error)
}

PacketConn is a generic packet-oriented network connection.

Multiple goroutines may invoke methods on a PacketConn simultaneously.

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

func DialTCP(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 (*TCPConn) Close

func (c *TCPConn) Close() error

Close implements the net.Conn Close method.

func (*TCPConn) CloseRead

func (c *TCPConn) CloseRead() error

CloseRead shuts down the reading side of the TCP connection. Most callers should just use Close.

func (*TCPConn) CloseWrite

func (c *TCPConn) CloseWrite() error

CloseWrite shuts down the writing side of the TCP connection. Most callers should just use Close.

func (*TCPConn) Fd added in v1.6.9

func (c *TCPConn) Fd() (*aio.NetFd, error)

Fd implements the rio.Conn Fd method.

func (*TCPConn) File

func (c *TCPConn) 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 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) GetSocketOptInt added in v1.6.0

func (c *TCPConn) GetSocketOptInt(level int, optName int) (optValue int, err error)

GetSocketOptInt implements the rio.Conn GetSocketOptInt method.

func (*TCPConn) LocalAddr

func (c *TCPConn) LocalAddr() net.Addr

LocalAddr implements the net.Conn LocalAddr method.

func (*TCPConn) MultipathTCP

func (c *TCPConn) MultipathTCP() (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 (*TCPConn) Read

func (c *TCPConn) Read(b []byte) (n int, err error)

Read implements the net.Conn Read method.

func (*TCPConn) ReadBuffer

func (c *TCPConn) ReadBuffer() (int, error)

ReadBuffer get SO_RCVBUF.

func (*TCPConn) ReadFrom

func (c *TCPConn) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements the io.ReaderFrom ReadFrom method.

func (*TCPConn) RemoteAddr

func (c *TCPConn) RemoteAddr() net.Addr

RemoteAddr implements the net.Conn RemoteAddr method.

func (*TCPConn) SetDeadline

func (c *TCPConn) SetDeadline(t time.Time) error

SetDeadline implements the net.Conn SetDeadline method.

func (*TCPConn) SetKeepAlive

func (c *TCPConn) SetKeepAlive(keepalive bool) error

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

func (c *TCPConn) SetKeepAlivePeriod(period time.Duration) 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 (*TCPConn) SetLinger

func (c *TCPConn) SetLinger(sec int) 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 (*TCPConn) SetNoDelay

func (c *TCPConn) SetNoDelay(noDelay bool) 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 (*TCPConn) SetReadBuffer

func (c *TCPConn) SetReadBuffer(bytes int) error

SetReadBuffer set SO_RCVBUF.

func (*TCPConn) SetReadDeadline

func (c *TCPConn) SetReadDeadline(t time.Time) error

SetReadDeadline implements the net.Conn SetReadDeadline method.

func (*TCPConn) SetSocketOptInt added in v1.6.0

func (c *TCPConn) SetSocketOptInt(level int, optName int, optValue int) (err error)

SetSocketOptInt implements the rio.Conn SetSocketOptInt method.

func (*TCPConn) SetWriteBuffer

func (c *TCPConn) SetWriteBuffer(bytes int) error

SetWriteBuffer set SO_SNDBUF.

func (*TCPConn) SetWriteDeadline

func (c *TCPConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the net.Conn SetWriteDeadline method.

func (*TCPConn) SyscallConn

func (c *TCPConn) SyscallConn() (syscall.RawConn, error)

SyscallConn returns a raw network connection. This implements the syscall.Conn interface.

func (*TCPConn) Write

func (c *TCPConn) Write(b []byte) (n int, err error)

Write implements the net.Conn Write method.

func (*TCPConn) WriteBuffer

func (c *TCPConn) WriteBuffer() (int, error)

WriteBuffer get SO_SNDBUF.

func (*TCPConn) WriteTo

func (c *TCPConn) WriteTo(w io.Writer) (int64, error)

WriteTo implements the io.WriterTo WriteTo 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() (c *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 *net.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) GetSocketOptInt added in v1.6.0

func (ln *TCPListener) GetSocketOptInt(level int, optName int) (optValue int, err error)

GetSocketOptInt implements the rio.Listener GetSocketOptInt method.

func (*TCPListener) SetDeadline

func (ln *TCPListener) SetDeadline(t time.Time) error

SetDeadline sets the deadline associated with the listener. set zero time value disables the deadline.

func (*TCPListener) SetSocketOptInt added in v1.6.0

func (ln *TCPListener) SetSocketOptInt(level int, optName int, optValue int) (err error)

SetSocketOptInt implements the rio.Listener SetSocketOptInt method.

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

func DialUDP(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 ListenMulticastUDP

func ListenMulticastUDP(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 ListenUDP

func ListenUDP(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 (*UDPConn) Close

func (c *UDPConn) Close() error

Close implements the net.Conn Close method.

func (*UDPConn) Fd added in v1.6.9

func (c *UDPConn) Fd() (*aio.NetFd, error)

Fd implements the rio.Conn Fd method.

func (*UDPConn) File

func (c *UDPConn) 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 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) GetSocketOptInt added in v1.6.0

func (c *UDPConn) GetSocketOptInt(level int, optName int) (optValue int, err error)

GetSocketOptInt implements the rio.PacketConn GetSocketOptInt method.

func (*UDPConn) LocalAddr

func (c *UDPConn) LocalAddr() net.Addr

LocalAddr implements the net.Conn LocalAddr method.

func (*UDPConn) Read

func (c *UDPConn) Read(b []byte) (n int, err error)

Read implements the net.Conn Read method.

func (*UDPConn) ReadBuffer

func (c *UDPConn) ReadBuffer() (int, error)

ReadBuffer get SO_RCVBUF.

func (*UDPConn) ReadFrom

func (c *UDPConn) ReadFrom(b []byte) (n int, addr net.Addr, err error)

ReadFrom implements the net.PacketConn ReadFrom method.

func (*UDPConn) ReadFromUDP

func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error)

ReadFromUDP acts like UDPConn.ReadFrom but returns a net.UDPAddr.

func (*UDPConn) ReadFromUDPAddrPort

func (c *UDPConn) ReadFromUDPAddrPort(b []byte) (n int, addr netip.AddrPort, err error)

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

func (c *UDPConn) ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *net.UDPAddr, err error)

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) RemoteAddr

func (c *UDPConn) RemoteAddr() net.Addr

RemoteAddr implements the net.Conn RemoteAddr method.

func (*UDPConn) SetDeadline

func (c *UDPConn) SetDeadline(t time.Time) error

SetDeadline implements the net.Conn SetDeadline method.

func (*UDPConn) SetReadBuffer

func (c *UDPConn) SetReadBuffer(bytes int) error

SetReadBuffer set SO_RCVBUF.

func (*UDPConn) SetReadDeadline

func (c *UDPConn) SetReadDeadline(t time.Time) error

SetReadDeadline implements the net.Conn SetReadDeadline method.

func (*UDPConn) SetSocketOptInt added in v1.6.0

func (c *UDPConn) SetSocketOptInt(level int, optName int, optValue int) (err error)

SetSocketOptInt implements the rio.PacketConn SetSocketOptInt method.

func (*UDPConn) SetWriteBuffer

func (c *UDPConn) SetWriteBuffer(bytes int) error

SetWriteBuffer set SO_SNDBUF.

func (*UDPConn) SetWriteDeadline

func (c *UDPConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the net.Conn SetWriteDeadline method.

func (*UDPConn) SyscallConn

func (c *UDPConn) SyscallConn() (syscall.RawConn, error)

SyscallConn returns a raw network connection. This implements the syscall.Conn interface.

func (*UDPConn) Write

func (c *UDPConn) Write(b []byte) (n int, err error)

Write implements the net.Conn Write method.

func (*UDPConn) WriteBuffer

func (c *UDPConn) WriteBuffer() (int, error)

WriteBuffer get SO_SNDBUF.

func (*UDPConn) WriteMsgUDP

func (c *UDPConn) WriteMsgUDP(b, oob []byte, addr *net.UDPAddr) (n, oobn int, err error)

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

func (c *UDPConn) WriteMsgUDPAddrPort(b, oob []byte, addr netip.AddrPort) (n, oobn int, err error)

WriteMsgUDPAddrPort is like UDPConn.WriteMsgUDP but takes a netip.AddrPort instead of a net.UDPAddr.

func (*UDPConn) WriteTo

func (c *UDPConn) WriteTo(b []byte, addr net.Addr) (n int, err error)

WriteTo implements the net.PacketConn WriteTo method.

func (*UDPConn) WriteToUDP

func (c *UDPConn) WriteToUDP(b []byte, addr *net.UDPAddr) (n int, err error)

WriteToUDP acts like UDPConn.WriteTo but takes a [UDPAddr].

func (*UDPConn) WriteToUDPAddrPort

func (c *UDPConn) WriteToUDPAddrPort(b []byte, addr netip.AddrPort) (n int, err error)

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

func DialUnix(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 ListenUnixgram

func ListenUnixgram(network string, addr *net.UnixAddr) (*UnixConn, error)

ListenUnixgram acts like ListenPacket for Unix networks.

The network must be "unixgram".

func (*UnixConn) Close

func (c *UnixConn) Close() error

Close implements the net.Conn Close method.

func (*UnixConn) Fd added in v1.6.9

func (c *UnixConn) Fd() (*aio.NetFd, error)

Fd implements the rio.Conn Fd method.

func (*UnixConn) File

func (c *UnixConn) 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 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) GetSocketOptInt added in v1.6.0

func (c *UnixConn) GetSocketOptInt(level int, optName int) (optValue int, err error)

GetSocketOptInt implements the rio.PacketConn GetSocketOptInt method.

func (*UnixConn) LocalAddr

func (c *UnixConn) LocalAddr() net.Addr

LocalAddr implements the net.Conn LocalAddr method.

func (*UnixConn) Read

func (c *UnixConn) Read(b []byte) (n int, err error)

Read implements the net.Conn Read method.

func (*UnixConn) ReadBuffer

func (c *UnixConn) ReadBuffer() (int, error)

ReadBuffer get SO_RCVBUF.

func (*UnixConn) ReadFrom

func (c *UnixConn) ReadFrom(b []byte) (int, net.Addr, error)

ReadFrom implements the net.PacketConn ReadFrom method.

func (*UnixConn) ReadFromUnix

func (c *UnixConn) ReadFromUnix(b []byte) (n int, addr *net.UnixAddr, err error)

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) RemoteAddr

func (c *UnixConn) RemoteAddr() net.Addr

RemoteAddr implements the net.Conn RemoteAddr method.

func (*UnixConn) SetDeadline

func (c *UnixConn) SetDeadline(t time.Time) error

SetDeadline implements the net.Conn SetDeadline method.

func (*UnixConn) SetReadBuffer

func (c *UnixConn) SetReadBuffer(bytes int) error

SetReadBuffer set SO_RCVBUF.

func (*UnixConn) SetReadDeadline

func (c *UnixConn) SetReadDeadline(t time.Time) error

SetReadDeadline implements the net.Conn SetReadDeadline method.

func (*UnixConn) SetSocketOptInt added in v1.6.0

func (c *UnixConn) SetSocketOptInt(level int, optName int, optValue int) (err error)

SetSocketOptInt implements the rio.PacketConn SetSocketOptInt method.

func (*UnixConn) SetWriteBuffer

func (c *UnixConn) SetWriteBuffer(bytes int) error

SetWriteBuffer set SO_SNDBUF.

func (*UnixConn) SetWriteDeadline

func (c *UnixConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the net.Conn SetWriteDeadline method.

func (*UnixConn) SyscallConn

func (c *UnixConn) SyscallConn() (syscall.RawConn, error)

SyscallConn returns a raw network connection. This implements the syscall.Conn interface.

func (*UnixConn) Write

func (c *UnixConn) Write(b []byte) (n int, err error)

Write implements the net.Conn Write method.

func (*UnixConn) WriteBuffer

func (c *UnixConn) WriteBuffer() (int, error)

WriteBuffer get SO_SNDBUF.

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

func (c *UnixConn) WriteTo(b []byte, addr net.Addr) (int, error)

WriteTo implements the net.PacketConn WriteTo method.

func (*UnixConn) WriteToUnix

func (c *UnixConn) WriteToUnix(b []byte, addr *net.UnixAddr) (int, error)

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 *net.UnixAddr. 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) GetSocketOptInt added in v1.6.0

func (ln *UnixListener) GetSocketOptInt(level int, optName int) (optValue int, err error)

GetSocketOptInt implements the rio.Listener GetSocketOptInt method.

func (*UnixListener) SetDeadline

func (ln *UnixListener) SetDeadline(t time.Time) error

SetDeadline sets the deadline associated with the listener. set zero time value disables the deadline.

func (*UnixListener) SetSocketOptInt added in v1.6.0

func (ln *UnixListener) SetSocketOptInt(level int, optName int, optValue int) (err error)

SetSocketOptInt implements the rio.Listener SetSocketOptInt method.

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.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL