Documentation
¶
Overview ¶
Package socket contains platform-specific descriptor and socket operations used by UIO's native transports.
Index ¶
- func Accept(fd int) (int, syscall.Sockaddr, error)
- func Dup(fd int) (nfd int, err error)
- func DupNetConn(conn net.Conn) (int, error)
- func Recv(fd int, p []byte) (int, error)
- func RecvUDP(fd int, packet []byte, receive *UDPReceive) (int, error)
- func RecvUDPBatch(fd int, packets [][]byte, receives []UDPReceive) (int, error)
- func Send(fd int, p []byte) (int, error)
- func SendUDPBatch(fd int, packets [][]byte, remote syscall.Sockaddr) (int, error)
- func SetIPv6Only(fd, ipv6only int) error
- func SetKeepAlive(fd int, keepalive bool) error
- func SetKeepAlivePeriod(fd int, secs int) error
- func SetLinger(fd, secs int) error
- func SetNoDelay(fd int, nodelay bool) error
- func SetNonblock(fd int, nonblocking bool) error
- func SetRecvBuffer(fd, size int) error
- func SetReuseAddr(fd, reuseAddr int) error
- func SetSendBuffer(fd, size int) error
- func SockaddrToAddr(sa syscall.Sockaddr, udpAddr bool) net.Addr
- func SockaddrToAddrPort(sa syscall.Sockaddr) netip.AddrPort
- func SocketFamily(fd int) (uint8, error)
- func Writev(fd int, buffers [][]byte) (int, error)
- type AcceptFailure
- type UDPAddress
- type UDPReceive
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Accept ¶ added in v1.1.0
Accept creates a non-blocking descriptor that cannot leak across exec.
func DupNetConn ¶
DupNetConn duplicates conn's descriptor so UIO can assume ownership without changing the lifetime of the caller's net.Conn during handoff.
func RecvUDP ¶ added in v1.1.0
func RecvUDP(fd int, packet []byte, receive *UDPReceive) (int, error)
RecvUDP receives one datagram without allocating a Sockaddr interface.
func RecvUDPBatch ¶ added in v1.8.0
func RecvUDPBatch(fd int, packets [][]byte, receives []UDPReceive) (int, error)
RecvUDPBatch receives up to min(len(packets), len(receives), udpBatchBound) datagrams with recvmmsg. It reports how many arrived; each receive's Len is the datagram's original length, which may exceed its buffer when the datagram was truncated.
func SendUDPBatch ¶ added in v1.8.0
SendUDPBatch sends each packet as its own datagram to remote — nil for a connected socket — with sendmmsg, one syscall per batch of udpBatchBound. It reports the bytes of the datagrams the socket accepted; a batch the queue refused part-way reports what left before the refusal, and the datagrams after it are not attempted. Empty packets carry no datagram and are skipped.
func SetIPv6Only ¶
SetIPv6Only restricts a IPv6 socket to only process IPv6 requests or both IPv4 and IPv6 requests.
func SetKeepAlive ¶
SetKeepAlive sets whether the operating system should send keep-alive messages on the connection.
func SetKeepAlivePeriod ¶
SetKeepAlivePeriod sets period between keep-alives.
func 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 after sec seconds have elapsed any remaining unsent data may be discarded.
func 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 SetNonblock ¶
SetNonblock set this socket to use non-blocking mode or block mode.
func SetRecvBuffer ¶
SetRecvBuffer sets the size of the operating system's receive buffer associated with the connection.
func SetReuseAddr ¶
SetReuseAddr enables SO_REUSEADDR option on socket.
func SetSendBuffer ¶
SetSendBuffer sets the size of the operating system's transmit buffer associated with the connection.
func SockaddrToAddrPort ¶ added in v1.6.0
SockaddrToAddr returns a go/net friendly address SockaddrToAddrPort converts a sockaddr to the value form, with no allocation; an unsupported or empty address returns the zero value.
func SocketFamily ¶ added in v1.8.0
SocketFamily reports whether fd is an IPv4 (4) or IPv6 (6) socket.
Types ¶
type AcceptFailure ¶ added in v1.8.0
type AcceptFailure int
AcceptFailure is what a listener does about an accept that failed.
const ( // AcceptRetry: the failure belonged to one pending connection, which is // gone; the next accept may succeed at once. AcceptRetry AcceptFailure = iota // AcceptBackoff: the process or the system ran out of something the next // connection needs as well, such as descriptors or buffer memory, so // accepting resumes after a pause. AcceptBackoff // AcceptFatal: the listening descriptor itself is unusable. AcceptFatal )
func ClassifyAcceptError ¶ added in v1.8.0
func ClassifyAcceptError(err error) AcceptFailure
ClassifyAcceptError sorts an error Accept returned. Errors it does not know back off: a listener stays up until it is closed.
type UDPAddress ¶ added in v1.1.0
UDPAddress is a comparable source address suitable for use as a map key.
func UDPAddressFor ¶ added in v1.8.0
func UDPAddressFor(family uint8, addr netip.AddrPort) (UDPAddress, error)
UDPAddressFor returns the key a datagram from addr arrives with on a socket of family (4 or 6): on an IPv6 socket an IPv4 peer is reported in its IPv4-mapped form, and on an IPv4 socket only IPv4 peers exist.
func (UDPAddress) NetAddr ¶ added in v1.1.0
func (addr UDPAddress) NetAddr() *net.UDPAddr
NetAddr allocates the user-visible address used only for a new peer.
func (UDPAddress) Sockaddr ¶ added in v1.1.0
func (addr UDPAddress) Sockaddr() syscall.Sockaddr
Sockaddr allocates the persistent send address used only for a new peer.
type UDPReceive ¶ added in v1.1.0
type UDPReceive struct {
Addr UDPAddress
// Len is the datagram's original length, which exceeds its buffer when
// the datagram was truncated.
Len int
// contains filtered or unexported fields
}
UDPReceive holds reusable source-address storage for RecvUDP.