sox

package module
v0.0.0-...-36d5e2c Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: MIT Imports: 19 Imported by: 0

README

sox(WIP)

Go Version Linux Kernel License

Pure Go asynchronous network I/O library using io_uring

Overview

Sox provides asynchronous socket I/O and event notification for Go applications on Linux, using io_uring for efficient network operations and event handling.

Basic Concepts

  • Low-copy I/O implementation on sockets
  • Reduced kernel-userspace context switches
  • Lock-free programming friendly

Use Cases

  • Real-time communication systems
  • High-performance network servers
  • Networking utilities

Requirements

  • Linux only (kernel 6.12+)
  • Go 1.25+
  • Recommended: Debian 13 (Trixie) or later

For WSL2 development setup, see: WSL2-Linux-Kernel

Status

⚠️ Work in Progress

Next Steps

  • Completion event handling
  • Connection lifecycle management
  • Public API stabilization
  • Built-in Middlewares

License

©2022 Hayabusa Cloud Co., Ltd.
#5F Eclat BLDG, 3-6-2 Shibuya, Shibuya City, Tokyo 150-0002, Japan
Released under the MIT license

Documentation

Index

Constants

View Source
const (

	// BoundedPoolPicoCapacity is the recommended capacity for PicoBufferBoundedPool
	BoundedPoolPicoCapacity
	// BoundedPoolNanoCapacity is the recommended capacity for NanoBufferBoundedPool
	BoundedPoolNanoCapacity
	// BoundedPoolMicroCapacity is the recommended capacity for MicroBufferBoundedPool
	BoundedPoolMicroCapacity
	// BoundedPoolSmallCapacity is the recommended capacity for SmallBufferBoundedPool
	BoundedPoolSmallCapacity
	// BoundedPoolMediumCapacity is the recommended capacity for MediumBufferBoundedPool
	BoundedPoolMediumCapacity
	// BoundedPoolLargeCapacity is the recommended capacity for LargeBufferBoundedPool
	BoundedPoolLargeCapacity
	// BoundedPoolHugeCapacity is the recommended capacity for HugeBufferBoundedPool
	BoundedPoolHugeCapacity
	// BoundedPoolGiantCapacity is the recommended capacity for GiantBufferBoundedPool
	BoundedPoolGiantCapacity
)
View Source
const (

	// BufferSizePico represents the size of a pico buffer
	BufferSizePico

	// BufferSizeNano represents the size of a nano buffer.
	BufferSizeNano

	// BufferSizeMicro represents the size of a micro buffer.
	BufferSizeMicro

	// BufferSizeSmall represents the size of a small buffer.
	BufferSizeSmall

	// BufferSizeMedium represents the size of a medium buffer.
	BufferSizeMedium

	// BufferSizeLarge represents the size of a large buffer.
	BufferSizeLarge

	// BufferSizeHuge represents the size of a huge buffer.
	BufferSizeHuge

	// BufferSizeGiant represents the size of a giant buffer.
	BufferSizeGiant
)
View Source
const (
	// OpcodeTextMessage denotes a text message
	OpcodeTextMessage = 1 << 4
	// OpcodeBinaryMessage denotes a binary message
	OpcodeBinaryMessage = 2 << 4
	// OpcodeBuiltinCommand denotes a builtin-command message with 4-bits command code
	OpcodeBuiltinCommand = 4 << 4
	// OpcodeExtBuiltinCommand denotes a builtin-command message with 1-byte command code
	OpcodeExtBuiltinCommand = 5 << 4
	// OpcodeClose denotes a connection close
	OpcodeClose = 8 << 4
	// OpcodePing denotes a ping
	OpcodePing = 9 << 4
	// OpcodePong denotes a pong
	OpcodePong = 10 << 4
)
View Source
const (
	SCTP_RTOINFO   = 0
	SCTP_ASSOCINFO = 1
	SCTP_INITMSG   = 2
	SCTP_NODELAY   = 3

	SCTP_SOCKOPT_BINDX_ADD = 100
	SCTP_SOCKOPT_BINDX_REM = 101
	SCTP_SOCKOPT_CONNECTX  = 110
	SCTP_SOCKOPT_CONNECTX3 = 111
)
View Source
const (

	// SockShutdownRead is a constant that represents the action of shutting down
	// the reading side of a socket. It is used in conjunction with the unix.SHUT_RD
	// constant to specify the shutdown action.
	SockShutdownRead = unix.SHUT_RD

	// SockShutdownWrite represents a constant that is used to shutdown the write
	// function of a socket. It is typically used with the SockShutdown function
	// in the unix package.
	SockShutdownWrite = unix.SHUT_WR

	// SockShutdownReadWrite is a constant that represents the value `unix.SHUT_RDWR`.
	// It can be used to specify shutting down both the reading and writing operations
	// of a socket.
	SockShutdownReadWrite = unix.SHUT_RDWR
)
View Source
const (
	// SpinWaitLevelBlocking results in less CPU consumption but may cause a little delay
	// It is suggested to be used for io events polling etc.
	SpinWaitLevelBlocking = iota
	// SpinWaitLevelPending take balances of CPU consumption and delay
	// It is often to be used for producer-consumer ops on concurrent data structures
	SpinWaitLevelPending
	// SpinWaitLevelPreempting results in higher CPU consumption and lower delay,
	// which makes it suitable for time-sensitive operations on concurrent data structures.
	SpinWaitLevelPreempting
)
View Source
const (
	DefaultTimerID = 0
	DefaultTimerHZ = 60
)
View Source
const (
	IORING_SETUP_IOPOLL             = 1 << 0
	IORING_SETUP_SQPOLL             = 1 << 1
	IORING_SETUP_SQ_AFF             = 1 << 2
	IORING_SETUP_CQSIZE             = 1 << 3
	IORING_SETUP_CLAMP              = 1 << 4
	IORING_SETUP_ATTACH_WQ          = 1 << 5
	IORING_SETUP_R_DISABLED         = 1 << 6
	IORING_SETUP_SUBMIT_ALL         = 1 << 7
	IORING_SETUP_COOP_TASKRUN       = 1 << 8
	IORING_SETUP_TASKRUN_FLAG       = 1 << 9
	IORING_SETUP_SQE128             = 1 << 10
	IORING_SETUP_CQE32              = 1 << 11
	IORING_SETUP_SINGLE_ISSUER      = 1 << 12
	IORING_SETUP_DEFER_TASKRUN      = 1 << 13
	IORING_SETUP_NO_MMAP            = 1 << 14
	IORING_SETUP_REGISTERED_FD_ONLY = 1 << 15
	IORING_SETUP_NO_SQARRAY         = 1 << 16
	IORING_SETUP_HYBRID_IOPOLL      = 1 << 17
)
View Source
const (
	IORING_FEAT_SINGLE_MMAP = 1 << iota
	IORING_FEAT_NODROP
	IORING_FEAT_SUBMIT_STABLE
	IORING_FEAT_RW_CUR_POS
	IORING_FEAT_CUR_PERSONALITY
	IORING_FEAT_FAST_POLL
	IORING_FEAT_POLL_32BITS
	IORING_FEAT_SQPOLL_NONFIXED
	IORING_FEAT_EXT_ARG
	IORING_FEAT_NATIVE_WORKERS
	IORING_FEAT_RSRC_TAGS
	IORING_FEAT_CQE_SKIP
	IORING_FEAT_LINKED_FILE
	IORING_FEAT_REG_REG_RING
)
View Source
const (
	IORING_ENTER_GETEVENTS       = 1 << 0
	IORING_ENTER_SQ_WAKEUP       = 1 << 1
	IORING_ENTER_SQ_WAIT         = 1 << 2
	IORING_ENTER_EXT_ARG         = 1 << 3
	IORING_ENTER_REGISTERED_RING = 1 << 4
)
View Source
const (
	IORING_OFF_SQ_RING    int64 = 0
	IORING_OFF_CQ_RING    int64 = 0x8000000
	IORING_OFF_SQES       int64 = 0x10000000
	IORING_OFF_PBUF_RING        = 0x80000000
	IORING_OFF_PBUF_SHIFT       = 16
	IORING_OFF_MMAP_MASK        = 0xf8000000
)
View Source
const (
	IORING_SQ_NEED_WAKEUP = 1 << iota
	IORING_SQ_CQ_OVERFLOW
	IORING_SQ_TASKRUN
)
View Source
const (
	IOSQE_FIXED_FILE = 1 << iota
	IOSQE_IO_DRAIN
	IOSQE_IO_LINK
	IOSQE_IO_HARDLINK
	IOSQE_ASYNC
	IOSQE_BUFFER_SELECT
	IOSQE_CQE_SKIP_SUCCESS
)
View Source
const (
	IORING_POLL_ADD_MULTI = 1 << iota
	IORING_POLL_UPDATE_EVENTS
	IORING_POLL_UPDATE_USER_DATA
	IORING_POLL_ADD_LEVEL
)
View Source
const (
	IORING_ASYNC_CANCEL_ALL = 1 << iota
	IORING_ASYNC_CANCEL_FD
	IORING_ASYNC_CANCEL_ANY
	IORING_ASYNC_CANCEL_FD_FIXED
	IORING_ASYNC_CANCEL_USERDATA
	IORING_ASYNC_CANCEL_OP
)
View Source
const (
	IORING_CQE_F_BUFFER = 1 << iota
	IORING_CQE_F_MORE
	IORING_CQE_F_SOCK_NONEMPTY
	IORING_CQE_F_NOTIF
)
View Source
const (
	IORING_REGISTER_BUFFERS uintptr = iota
	IORING_UNREGISTER_BUFFERS
	IORING_REGISTER_FILES
	IORING_UNREGISTER_FILES
	IORING_REGISTER_EVENTFD
	IORING_UNREGISTER_EVENTFD
	IORING_REGISTER_FILES_UPDATE
	IORING_REGISTER_EVENTFD_ASYNC
	IORING_REGISTER_PROBE
	IORING_REGISTER_PERSONALITY
	IORING_UNREGISTER_PERSONALITY
	IORING_REGISTER_RESTRICTIONS
	IORING_REGISTER_ENABLE_RINGS
	IORING_REGISTER_FILES2
	IORING_REGISTER_FILES_UPDATE2
	IORING_REGISTER_BUFFERS2
	IORING_REGISTER_BUFFERS_UPDATE
	IORING_REGISTER_IOWQ_AFF
	IORING_UNREGISTER_IOWQ_AFF
	IORING_REGISTER_IOWQ_MAX_WORKERS
	IORING_REGISTER_RING_FDS
	IORING_UNREGISTER_RING_FDS
	IORING_REGISTER_PBUF_RING
	IORING_UNREGISTER_PBUF_RING
	IORING_REGISTER_SYNC_CANCEL
	IORING_REGISTER_FILE_ALLOC_RANGE
	IORING_REGISTER_PBUF_STATUS
	IORING_REGISTER_NAPI
	IORING_UNREGISTER_NAPI
)
View Source
const (
	UringEntriesPico
	UringEntriesNano
	UringEntriesMicro
	UringEntriesSmall
	UringEntriesMedium
	UringEntriesLarge
	UringEntriesHuge
)
View Source
const (
	IORING_OP_NOP uint8 = iota
	IORING_OP_READV
	IORING_OP_WRITEV
	IORING_OP_FSYNC
	IORING_OP_READ_FIXED
	IORING_OP_WRITE_FIXED
	IORING_OP_POLL_ADD
	IORING_OP_POLL_REMOVE
	IORING_OP_SYNC_FILE_RANGE
	IORING_OP_SENDMSG
	IORING_OP_RECVMSG
	IORING_OP_TIMEOUT
	IORING_OP_TIMEOUT_REMOVE
	IORING_OP_ACCEPT
	IORING_OP_ASYNC_CANCEL
	IORING_OP_LINK_TIMEOUT
	IORING_OP_CONNECT
	IORING_OP_FALLOCATE
	IORING_OP_OPENAT
	IORING_OP_CLOSE
	IORING_OP_FILES_UPDATE
	IORING_OP_STATX
	IORING_OP_READ
	IORING_OP_WRITE
	IORING_OP_FADVISE
	IORING_OP_MADVISE
	IORING_OP_SEND
	IORING_OP_RECV
	IORING_OP_OPENAT2
	IORING_OP_EPOLL_CTL
	IORING_OP_SPLICE
	IORING_OP_PROVIDE_BUFFERS
	IORING_OP_REMOVE_BUFFERS
	IORING_OP_TEE
	IORING_OP_SHUTDOWN
	IORING_OP_RENAMEAT
	IORING_OP_UNLINKAT
	IORING_OP_MKDIRAT
	IORING_OP_SYMLINKAT
	IORING_OP_LINKAT
	IORING_OP_MSG_RING
	IORING_OP_FSETXATTR
	IORING_OP_SETXATTR
	IORING_OP_FGETXATTR
	IORING_OP_GETXATTR
	IORING_OP_SOCKET
	IORING_OP_URING_CMD
	IORING_OP_SEND_ZC
	IORING_OP_SENDMSG_ZC
	IORING_OP_READ_MULTISHOT
	IORING_OP_WAITID
	IORING_OP_FUTEX_WAIT
	IORING_OP_FUTEX_WAKE
	IORING_OP_FUTEX_WAITV
	IORING_OP_FIXED_FD_INSTALL
	IORING_OP_FTRUNCATE
	IORING_OP_BIND
	IORING_OP_LISTEN
)
View Source
const (
	IORING_TIMEOUT_ABS = 1 << iota
	IORING_TIMEOUT_UPDATE
	IORING_TIMEOUT_BOOTTIME
	IORING_TIMEOUT_REALTIME
	IORING_LINK_TIMEOUT_UPDATE
	IORING_TIMEOUT_ETIME_SUCCESS
	IORING_TIMEOUT_MULTISHOT
	IORING_TIMEOUT_CLOCK_MASK  = IORING_TIMEOUT_BOOTTIME | IORING_TIMEOUT_REALTIME
	IORING_TIMEOUT_UPDATE_MASK = IORING_TIMEOUT_UPDATE | IORING_LINK_TIMEOUT_UPDATE
)
View Source
const (
	IORING_ACCEPT_MULTISHOT  = 1 << 0
	IORING_ACCEPT_DONTWAIT   = 1 << 1
	IORING_ACCEPT_POLL_FIRST = 1 << 2
)
View Source
const (
	IORING_RECVSEND_POLL_FIRST = 1 << iota
	IORING_RECV_MULTISHOT
	IORING_RECVSEND_FIXED_BUF
	IORING_SEND_ZC_REPORT_USAGE
	IORING_RECVSEND_BUNDLE
)
View Source
const (
	IORING_CQE_BUFFER_SHIFT = 16
)
View Source
const (
	IO_URING_OP_SUPPORTED = 1 << 0
)
View Source
const (
	SOL_SCTP = 132
)

Variables

View Source
var (
	// IPV4zero is an IPv4 address representing the zero value (0.0.0.0).
	IPV4zero = net.IPv4zero

	// IPV6unspecified is an IPv6 address representing the unspecified value (::).
	IPV6unspecified = net.IPv6unspecified

	// IPv4LoopBack is an IPv4 address representing the loopback address (127.0.0.1).
	IPv4LoopBack = net.IPv4(127, 0, 0, 1)

	// IPv6LoopBack is an IPv6 address representing the loopback address (::).
	IPv6LoopBack = net.IPv6loopback
)
View Source
var (
	// TCPAddrFromAddrPort refers to the net.TCPAddrFromAddrPort function
	// It returns addr as a [TCPAddr]. If addr.IsValid() is false,
	// then the returned TCPAddr will contain a nil IP field, indicating an
	// address-family-agnostic unspecified address.
	TCPAddrFromAddrPort = net.TCPAddrFromAddrPort

	// UDPAddrFromAddrPort refers to the net.UDPAddrFromAddrPort function
	// It returns addr as a UDPAddr. If addr.IsValid() is false,
	// then the returned UDPAddr will contain a nil IP field, indicating an
	// address-family-agnostic unspecified address.
	UDPAddrFromAddrPort = net.UDPAddrFromAddrPort
)
View Source
var (
	// ResolveIPAddr refers to the net.ResolveIPAddr function
	// It returns an address of the IP end point.
	ResolveIPAddr = net.ResolveIPAddr

	// ResolveTCPAddr refers to the net.ResolveTCPAddr function.
	// It returns a TCPAddr struct that contains IP and port information.
	ResolveTCPAddr = net.ResolveTCPAddr

	// ResolveUDPAddr refers to the net.ResolveUDPAddr function.
	// It takes a network type and a string representation of the address and returns a
	// UDPAddr struct that contains the IP and port information.
	ResolveUDPAddr = net.ResolveUDPAddr
)
View Source
var (
	// ErrMsgInvalidArguments will be returned when got invalid parameter
	ErrMsgInvalidArguments = errors.New("message invalid argument")
	// ErrMsgInvalidRead will be returned when read operation invalid
	ErrMsgInvalidRead = errors.New("message invalid read result")
	// ErrMsgInvalidWrite will be returned when write operation invalid
	ErrMsgInvalidWrite = errors.New("message invalid write result")
	// ErrMsgTooLong will be returned when try to read or write a message which is too long
	ErrMsgTooLong = errors.New("message too long")
	// ErrMsgClosed will be returned when try to read or write on a closed reader or writer
	ErrMsgClosed = errors.New("message closed")
)
View Source
var (

	// ErrInterruptedSyscall represents an error indicating an interrupted system call.
	ErrInterruptedSyscall = errors.New("interrupted system call")

	// ErrTemporarilyUnavailable represents an error indicating that a resource is temporarily unavailable.
	// In many cases, when ErrTemporarilyUnavailable is returned, the caller would block.
	ErrTemporarilyUnavailable = errors.New("resource temporarily unavailable")

	// ErrInProgress represents an error indicating that an operation is in progress.
	ErrInProgress = errors.New("in progress")

	// ErrFaultParams represents an error indicating fault parameters.
	ErrFaultParams = errors.New("fault parameters")

	// ErrInvalidParam is an error indicating that a parameter passed to a function is invalid.
	ErrInvalidParam = errors.New("invalid param")

	// ErrProcessFileLimit represents an error indicating that the process has reached its open file descriptor limit.
	ErrProcessFileLimit = errors.New("process open fd limit")

	// ErrSystemFileLimit represents an error indicating that the system has reached its open file descriptor limit.
	ErrSystemFileLimit = errors.New("system open fd limit")

	// ErrNoDevice represents an error indicating that there is no device available.
	ErrNoDevice = errors.New("no device")

	// ErrNoAvailableMemory represents an error indicating that there is no available kernel memory.
	ErrNoAvailableMemory = errors.New("no available kernel memory")

	// ErrNoPermission represents an error indicating that the operation is not permitted.
	ErrNoPermission = errors.New("operation not permitted")

	// ErrCanceled represents an error indicating that an operation was canceled.
	ErrCanceled = errors.New("operation canceled")
)
View Source
var (
	// DefaultResolver is a variable that holds the default resolver implementation
	// for performing network resolution in the Go standard library.
	DefaultResolver = net.DefaultResolver
)
View Source
var MessageOptionsNetworkOrder = func(options *MessageOptions) {
	options.ReadByteOrder = binary.BigEndian
	options.WriteByteOrder = binary.BigEndian
}

MessageOptionsNetworkOrder sets byte order to big endian

View Source
var MessageOptionsNonblock = func(options *MessageOptions) {
	options.Nonblock = true
}

MessageOptionsNonblock sets message nonblock

View Source
var MessageOptionsRawSocket = func(options *MessageOptions) {
	options.ReadByteOrder = binary.BigEndian
	options.WriteByteOrder = binary.BigEndian
	options.ReadProto = UnderlyingProtocolRaw
	options.WriteProto = UnderlyingProtocolRaw
}

MessageOptionsRawSocket sets feature options for raw sockets

View Source
var MessageOptionsSCTPSocket = func(options *MessageOptions) {
	options.ReadByteOrder = binary.BigEndian
	options.WriteByteOrder = binary.BigEndian
	options.ReadProto = UnderlyingProtocolSeqPacket
	options.WriteProto = UnderlyingProtocolSeqPacket
}

MessageOptionsSCTPSocket sets feature options for SCTP sockets

View Source
var MessageOptionsTCPSocket = func(options *MessageOptions) {
	options.ReadByteOrder = binary.BigEndian
	options.WriteByteOrder = binary.BigEndian
	options.ReadProto = UnderlyingProtocolStream
	options.WriteProto = UnderlyingProtocolStream
}

MessageOptionsTCPSocket sets feature options for TCP sockets

View Source
var (
	// NetworkByteOrder represents the network byte order, which is big-endian.
	NetworkByteOrder = binary.BigEndian
)
View Source
var PageSize = uintptr(os.Getpagesize())
View Source
var (
	// ResolveUnixAddr is a function that resolves a Unix network address.
	ResolveUnixAddr = net.ResolveUnixAddr
)

Functions

func AlignedMem

func AlignedMem(size int) []byte

AlignedMem returns a byte slice with the specified size and starting address aligned to the memory page size.

func AlignedMemBlock

func AlignedMemBlock() []byte

AlignedMemBlock returns one aligned block

func AlignedMemBlocks

func AlignedMemBlocks(n int) (blocks [][]byte)

AlignedMemBlocks returns n bytes slices that have length with memory page size and address starts from multiple of memory page size

func ContextUserdata

func ContextUserdata[T any](ctx context.Context) (ret T)

func ContextWithUserdata

func ContextWithUserdata[T any](parent context.Context, userdata T) context.Context

func GetFd

func GetFd(x any) int

GetFd gets the file descriptor of a given object. It checks if the object implements the PollFd interface, and if so, returns the result of calling the Fd method on it. If the object implements the file interface, it retrieves the file using the File method and returns its file descriptor. If none of these conditions are met, it returns -1.

func IP4AddressToBytes

func IP4AddressToBytes(ip net.IP) [4]byte

IP4AddressToBytes converts an IPv4 address to a byte array. If the given IP address is not an IPv4 address, it returns an empty byte array. The byte array contains the four octets of the IPv4 address in network byte order.

func IP6AddressToBytes

func IP6AddressToBytes(ip net.IP) [16]byte

IP6AddressToBytes converts the given net.IPv6 address to a fixed-size byte array. The resulting byte array contains the individual bytes of the IPv6 address in the same order as the original address. Each byte of the byte array corresponds to a byte of the IPv6 address. For example, the first byte of the byte array corresponds to the first byte of the IPv6 address, and so on. The byte array has a length of 16 bytes.

Note: This function assumes that the given net.IPv6 address is a valid IPv6 address.

func ListenAndServe

func ListenAndServe(network string, address string, handler AcceptedHandler) error

ListenAndServe listens on the given network and address, and then calls Serve method with the given handler to handle incoming connect requests

func MemoryBarrier

func MemoryBarrier()

MemoryBarrier provides a memory barrier operation to ensure ordering of memory accesses.

func NewMessagePipe

func NewMessagePipe(opts ...func(options *MessageOptions)) (reader io.Reader, writer io.Writer)

NewMessagePipe creates and returns a synchronous in-memory message pipe

func NewMessageReadWriter

func NewMessageReadWriter(reader io.Reader, writer io.Writer, opts ...func(options *MessageOptions)) io.ReadWriter

NewMessageReadWriter creates and returns a new io.ReadWriter to read and write messages

func NewMessageReader

func NewMessageReader(reader io.Reader, opts ...func(options *MessageOptions)) io.Reader

NewMessageReader creates and returns a new io.Reader to read messages

func NewMessageWriter

func NewMessageWriter(writer io.Writer, opts ...func(options *MessageOptions)) io.Writer

NewMessageWriter creates and returns a new io.Writer to write messages

func NewRingQueue

func NewRingQueue[ItemType any](
	opts ...func(options *RingQueueOptions)) (
	consumer ItemConsumer[ItemType],
	producer ItemProducer[ItemType],
	err error)

NewRingQueue creates a ring queue with given options and returns the consumer and the producer of it

func Serve

func Serve(listener Listener, handler AcceptedHandler) error

Serve accepts and handles incoming connections on the listener l with the given handler Serve method works like this:

evLoop, _ = New()
evLoop.AddAccepted(listener, handler)
return evLoop.Serve()

func Yield

func Yield(ticks ...int)

Yield pauses the current goroutine, allowing other goroutines to run, or optionally sleeps for a specific duration.

Types

type AcceptedHandler

type AcceptedHandler interface {
	ServeAccepted(conn Conn, listener Listener)
}

AcceptedHandler handles the listener accepted new connections event

type Addr

type Addr = net.Addr

Addr is an alias for the net.Addr type. It represents a network address.

type AddrError

type AddrError = net.AddrError

AddrError is an error type that represents an address-related error.

type BoundedPool

type BoundedPool[T BoundedPoolItem] struct {
	// contains filtered or unexported fields
}

func NewBoundedPool

func NewBoundedPool[ItemType BoundedPoolItem](capacity int) *BoundedPool[ItemType]

NewBoundedPool creates a new instance of BoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 (inclusive).

func (*BoundedPool[T]) Cap

func (pool *BoundedPool[T]) Cap() int

Cap returns the capacity of the BoundedPool

func (*BoundedPool[T]) Fill

func (pool *BoundedPool[T]) Fill(newFunc func() T)

Fill initializes and fills the BoundedPool with a newFunc function, which is used to create new items. Fill Put capacity items with new BoundedPoolItem created by newFunc for each item in the pool.

Example:

pool := NewBoundedPool[ItemType](capacity)
pool.Fill(newFunc)

Parameters:

newFunc - a function that returns an instance of an item to be added to the pool.

func (*BoundedPool[T]) Get

func (pool *BoundedPool[T]) Get() (indirect int, err error)

Get retrieves an item from the pool and returns its indirect index. If an item is available, its indirect index and a nil error are returned.

func (*BoundedPool[T]) Put

func (pool *BoundedPool[T]) Put(indirect int) error

Put puts the indirect index of an item back into the BoundedPool. It tries to put the given indirect index into the pool and returns nil error if successful. If the BoundedPool is currently full, it would block until the item can be put into the pool or return an ErrTemporarilyUnavailable error if the pool is nonblocking.

func (*BoundedPool[T]) SetNonblock

func (pool *BoundedPool[T]) SetNonblock(nonblocking bool)

SetNonblock enables or disables the non-blocking mode of the pool. When nonblocking is set to true, Get() and Put() calls will not block and return immediately. When nonblocking is set to false, Get() calls will block until an item is available, and Put() calls will block until the pool is no longer full.

Example:

pool := NewBoundedPool[ItemType](capacity)
pool.SetNonblock(true)

Parameters:

nonblocking - determines whether the pool operates in non-blocking mode (true) or blocking mode (false).

func (*BoundedPool[T]) SetValue

func (pool *BoundedPool[T]) SetValue(indirect int, value T)

SetValue sets the value of the item at the specified indirect index in the BoundedPool. The given indirect index must not be marked as empty and must be within the valid range.

func (*BoundedPool[T]) Value

func (pool *BoundedPool[T]) Value(indirect int) T

Value returns the item at the specified indirect index. The given indirect index must not be marked as empty and must be within the valid range.

type BoundedPoolItem

type BoundedPoolItem interface{}

BoundedPoolItem is an interface that represents an item that can be used in a bounded pool. Implementing this interface allows an object to be stored and retrieved from a BoundedPool.

type BufferType

BufferType is an interface that represents different types of buffers, including PicoBuffer, NanoBuffer, MicroBuffer, SmallBuffer, MediumBuffer, LargeBuffer, HugeBuffer, and GiantBuffer. Each buffer type is a byte array with a specific size.

type Buffers

type Buffers = net.Buffers

Buffers is an alias of net.Buffers

func NewBuffers

func NewBuffers(n int, size int) Buffers

NewBuffers creates and initializes a new Buffers with a given n and size

type ClosedHandler

type ClosedHandler interface {
	ServeDisconnected(lfd int, rfd int)
}

ClosedHandler handles connection closed event

type Conn

type Conn = net.Conn

Conn is an alias for net.Conn type. It represents a generic network connection. It has methods for accessing the local and remote addresses, setting deadlines, and shutting down the connection.

Conn is used in various examples and functions in the codebase. Some of the usage examples include: - NewTCPConn: creates a new TCP connection - NewUDPConn: creates a new UDP connection - NewSCTPConn: creates a new SCTP connection - NewUnixConn: creates a new Unix connection

func Dial

func Dial(network string, address string) (conn Conn, err error)

func NewSCTPConn

func NewSCTPConn(localAddr Addr, remoteSock *SCTPSocket) (Conn, error)

func NewTCPConn

func NewTCPConn(localAddr Addr, remoteSock *TCPSocket) (Conn, error)

func NewUDPConn

func NewUDPConn(localAddr Addr, remoteSock *UDPSocket) (Conn, error)

func NewUnixConn

func NewUnixConn(localAddr Addr, remoteSock *UnixSocket) (Conn, error)

type ConnectedHandler

type ConnectedHandler interface {
	ServeConnected(conn Conn)
}

ConnectedHandler handles the client connected to remote server event

type DispatchHandler

type DispatchHandler interface {
	ServeDispatch(ctx context.Context, reader PollReader) MessageHandler
}

DispatchHandler chooses the MessageHandler which will be used to handle the incoming message

type Empty

type Empty = struct{}

type FixedStackOptions

type FixedStackOptions struct {
	// Capacity specifies the capacity of Stack. The default Capacity is 32K
	Capacity uint32
	// Concurrent specifies whether the Stack works in Concurrent mode or not
	// Concurrent should be set as true,
	//   if there are multiple goroutines doing Push or multiple goroutines doing Pop
	Concurrent bool
	// Nonblocking specifies whether the Push or Pop operations will NOT block
	// even if it is temporarily unavailable or not
	Nonblocking bool
}

FixedStackOptions holds optional parameters for Stack implementations

type GiantBuffer

type GiantBuffer [BufferSizeGiant]byte

GiantBuffer represents a byte array with size of BufferSizeGiant

func NewGiantBuffer

func NewGiantBuffer() GiantBuffer

NewGiantBuffer returns a new instance of GiantBuffer.

func (GiantBuffer) Reset

func (b GiantBuffer) Reset()

type GiantBufferBoundedPool

type GiantBufferBoundedPool = BoundedPool[GiantBuffer]

GiantBufferBoundedPool is a type alias of BoundedPool[GiantBuffer].

func NewGiantBufferPool

func NewGiantBufferPool(capacity int) *GiantBufferBoundedPool

NewGiantBufferPool creates a new instance of GiantBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.

type GiantBufferPool

type GiantBufferPool = IndirectPool[GiantBuffer]

GiantBufferPool represents a generic object pool that uses indirect indices to Put and Get items of type GiantBuffer

type HugeBuffer

type HugeBuffer [BufferSizeHuge]byte

HugeBuffer represents a byte array with size of BufferSizeHuge

func NewHugeBuffer

func NewHugeBuffer() HugeBuffer

NewHugeBuffer returns a new instance of HugeBuffer.

func (HugeBuffer) Reset

func (b HugeBuffer) Reset()

type HugeBufferBoundedPool

type HugeBufferBoundedPool = BoundedPool[HugeBuffer]

HugeBufferBoundedPool is a type alias of BoundedPool[HugeBuffer].

func NewHugeBufferPool

func NewHugeBufferPool(capacity int) *HugeBufferBoundedPool

NewHugeBufferPool creates a new instance of HugeBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.

type HugeBufferPool

type HugeBufferPool = IndirectPool[HugeBuffer]

HugeBufferPool represents a generic object pool that uses indirect indices to Put and Get items of type HugeBuffer.

type IP

type IP = net.IP

IP represents an IP address. It is a type alias for the net.IP type.

type IPAddr

type IPAddr = net.IPAddr

IPAddr represents a network address of type IP. It is a type alias for the net.IPAddr type.

func IPAddrFromSCTPAddr

func IPAddrFromSCTPAddr(addr *SCTPAddr) *IPAddr

IPAddrFromSCTPAddr returns a new IPAddr based on the given SCTPAddr.

func IPAddrFromTCPAddr

func IPAddrFromTCPAddr(addr *TCPAddr) *IPAddr

IPAddrFromTCPAddr returns a new IPAddr based on the given TCPAddr.

func IPAddrFromUDPAddr

func IPAddrFromUDPAddr(addr *UDPAddr) *IPAddr

IPAddrFromUDPAddr returns a new IPAddr based on the given UDPAddr. It sets the IP and Zone fields of the IPAddr with the values from the UDPAddr.

type IndirectPool

type IndirectPool[T any] interface {
	Pool[int]
	// Value returns the value with the given indirect index
	Value(indirect int) T
	// SetValue sets the value with the given indirect index
	SetValue(indirect int, item T)
}

IndirectPool is a generic object pool that Put and Get the int type indices of items instead of direct values. It extends the Pool[int] interface and adds Value and SetValue methods for working with indirect indices.

type Interface

type Interface interface {
	// AddListen adds listen event on the given listener with the given event handler
	AddListen(listener Listener, handler AcceptedHandler)
	// AddIO adds io event with the given event handlers
	AddIO(dispatch DispatchHandler, message MessageHandler, written WrittenHandler, closed ClosedHandler)
	// AddTimer adds timer event with the given event handler
	AddTimer(ticked TickedHandler)
	// Serve starts serving
	Serve() error
	// Poll waits for events. The d parameter specifies the duration that Poll will block
	// d == 0 means Poll method will return immediately even if there is no events came
	// d < 0 means Poll method will block forever or until there are any events
	Poll(d time.Duration) error
}

Interface is the interface of sox events notification library

func New

func New(options ...func(option *Options)) (evLoop Interface, err error)

New creates and returns a new event loop with given options

type InvalidAddrError

type InvalidAddrError = net.InvalidAddrError

InvalidAddrError is an error type that represents an invalid network address.

type ItemConsumer

type ItemConsumer[ItemType any] interface {
	// Consume consumes items
	Consume() (item ItemType, err error)
}

ItemConsumer is the interface that Consume items

type ItemProducer

type ItemProducer[ItemType any] interface {
	// Produce produces items
	Produce(item ItemType) error
	// Close closed the ItemProducer
	Close() error
}

ItemProducer is the interface that Produce items and can be Close

type LargeBuffer

type LargeBuffer [BufferSizeLarge]byte

LargeBuffer represents a byte array with size of BufferSizeLarge

func NewLargeBuffer

func NewLargeBuffer() LargeBuffer

NewLargeBuffer returns a new instance of LargeBuffer.

func (LargeBuffer) Reset

func (b LargeBuffer) Reset()

type LargeBufferBoundedPool

type LargeBufferBoundedPool = BoundedPool[LargeBuffer]

LargeBufferBoundedPool is a type alias of BoundedPool[LargeBuffer].

func NewLargeBufferPool

func NewLargeBufferPool(capacity int) *LargeBufferBoundedPool

NewLargeBufferPool creates a new instance of LargeBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.

type LargeBufferPool

type LargeBufferPool = IndirectPool[LargeBuffer]

LargeBufferPool represents a generic object pool that uses indirect indices to Put and Get items of type LargeBuffer.

type Listener

type Listener = net.Listener

Listener represents a generic network listener. It is an alias for the net.Listener type.

func Listen

func Listen(network string, address string) (listener Listener, err error)

func ListenSCTP

func ListenSCTP(network string, laddr *SCTPAddr) (listener Listener, err error)

func ListenTCP

func ListenTCP(network string, laddr *TCPAddr) (listener Listener, err error)

type ListenerSocket

type ListenerSocket interface {
	Socket
	// Accept accepts incoming connections and returns a new socket for the accepted connection.
	Accept() (Socket, error)
}

ListenerSocket is an interface that represents a network socket capable of accepting incoming connections. It extends the Socket interface and adds the Accept method which returns a new socket for the accepted connection.

type MediumBuffer

type MediumBuffer [BufferSizeMedium]byte

MediumBuffer represents a byte array with size of BufferSizeMedium

func NewMediumBuffer

func NewMediumBuffer() MediumBuffer

NewMediumBuffer returns a new instance of MediumBuffer.

func (MediumBuffer) Reset

func (b MediumBuffer) Reset()

type MediumBufferBoundedPool

type MediumBufferBoundedPool = BoundedPool[MediumBuffer]

MediumBufferBoundedPool is a type alias of BoundedPool[MediumBuffer].

func NewMediumBufferPool

func NewMediumBufferPool(capacity int) *MediumBufferBoundedPool

NewMediumBufferPool creates a new instance of MediumBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.

type MediumBufferPool

type MediumBufferPool = IndirectPool[MediumBuffer]

MediumBufferPool represents a generic object pool that uses indirect indices to Put and Get items of type MediumBuffer.

type MessageHandler

type MessageHandler interface {
	ServeMessage(ctx context.Context, reply PollWriter, request PollReader)
}

MessageHandler is the most often used handle. It handles the incoming request messages

type MessageOptions

type MessageOptions struct {
	// ReadByteOrder sets which byte order will be used when reading data
	ReadByteOrder binary.ByteOrder
	// WriteByteOrder sets which byte order will be used when writing data
	WriteByteOrder binary.ByteOrder
	// ReadProto sets which protocol type will be used when reading data
	ReadProto UnderlyingProtocol
	// WriteProto sets which protocol type will be used when writing data
	WriteProto UnderlyingProtocol
	// ReadLimit is the maximum message payload data size
	// A ReadLimit of zero indicates that there is no limit
	ReadLimit int
	// Nonblock if the nonblock flag is true, Message will not block on I/O
	Nonblock bool
}

MessageOptions represents message feature options

type MicroBuffer

type MicroBuffer [BufferSizeMicro]byte

MicroBuffer represents a byte array with size of BufferSizeMicro

func NewMicroBuffer

func NewMicroBuffer() MicroBuffer

NewMicroBuffer returns a new instance of MicroBuffer.

func (MicroBuffer) Reset

func (b MicroBuffer) Reset()

type MicroBufferBoundedPool

type MicroBufferBoundedPool = BoundedPool[MicroBuffer]

MicroBufferBoundedPool is a type alias of BoundedPool[MicroBuffer].

func NewMicroBufferPool

func NewMicroBufferPool(capacity int) *MicroBufferBoundedPool

NewMicroBufferPool creates a new instance of MicroBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.

type MicroBufferPool

type MicroBufferPool = IndirectPool[MicroBuffer]

MicroBufferPool represents a generic object pool that uses indirect indices to Put and Get items of type MicroBuffer.

type NanoBuffer

type NanoBuffer [BufferSizeNano]byte

NanoBuffer represents a byte array with size of BufferSizeNano

func NewNanoBuffer

func NewNanoBuffer() NanoBuffer

NewNanoBuffer returns a new instance of NanoBuffer.

func (NanoBuffer) Reset

func (b NanoBuffer) Reset()

type NanoBufferBoundedPool

type NanoBufferBoundedPool = BoundedPool[NanoBuffer]

NanoBufferBoundedPool is a type alias of BoundedPool[NanoBuffer].

func NewNanoBufferPool

func NewNanoBufferPool(capacity int) *NanoBufferBoundedPool

NewNanoBufferPool creates a new instance of NanoBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.

type NanoBufferPool

type NanoBufferPool = IndirectPool[NanoBuffer]

NanoBufferPool represents a generic object pool that uses indirect indices to Put and Get items of type NanoBuffer. It implements the IndirectPool interface.

type NetworkType

type NetworkType int

NetworkType is a custom type used to represent network types in the code.

const (
	// NetworkUnix represents a constant value used to indicate the Unix network type.
	NetworkUnix NetworkType = 1
	// NetworkIPv4 represents a constant value used to indicate the IPv4 network type.
	NetworkIPv4 NetworkType = 2
	// NetworkIPv6 represents a constant value used to indicate the IPv6 network type.
	NetworkIPv6 NetworkType = 10
)

type OpError

type OpError = net.OpError

OpError is an error that represents an operation error along with the operation name, network protocol, source address, target address, and the underlying error. It is an alias for net.OpError.

type OpcodePacketReader

type OpcodePacketReader interface {
	PacketReader

	// ReadOpcodeCommand reads an opcode command from the packet.
	// It returns the opcode and cmd integers, and any error that occurred.
	ReadOpcodeCommand() (opcode int, cmd int, err error)
}

OpcodePacketReader is an interface that extends the PacketReader interface, adding a method ReadOpcodeCommand, which reads an opcode command from the packet.

type OpcodePacketWriter

type OpcodePacketWriter interface {
	PacketWriter

	// WriteOpcodeCommand writes an opcode command to the PacketWriter.
	// The opcode specifies the type of command, and the cmd parameter
	// provides additional information about the command.
	// The returned error indicates any error that occurred during writing.
	//
	// Parameters:
	// - opcode: The opcode of the command to be written.
	// - cmd: Additional information about the command.
	//
	// Returns:
	// - error: An error if any occurred during writing.
	WriteOpcodeCommand(opcode int, cmd int) error
}

OpcodePacketWriter is an interface that extends the PacketWriter interface, adding a method for writing opcode commands.

type Options

type Options struct {
	// UserPoll sets if it's need to call Interface.Poll to wait events manually
	// set UserPoll to true might improve performance of some IO operations
	UserPoll bool
	// Parallel sets the number of goroutines that do handle the events. Default value is 0
	// Parallel <= 0 means the events will be handled at the same goroutine as the polling goroutine
	// Parallel == 1 means the events will be handled in series at one another worker goroutine
	// Parallel >= 2 means the events will be handled in parallel at Parallel worker goroutines
	// It is possible to specify which worker will be used to handle the event
	// by implement your customized DispatchHandler
	Parallel int
}

Options represents

type PacketReader

type PacketReader interface {
	io.Reader
	io.WriterTo
	io.ByteReader
	io.RuneReader
	ReadBool() (bool, error)
	ReadInt8() (int8, error)
	ReadUint8() (uint8, error)
	ReadInt16() (int16, error)
	ReadUint16() (uint16, error)
	ReadInt32() (int32, error)
	ReadUint32() (uint32, error)
	ReadInt64() (int64, error)
	ReadUint64() (uint64, error)
	ReadFloat32() (float32, error)
	ReadFloat64() (float64, error)
	ReadComplex64() (complex64, error)
	ReadComplex128() (complex128, error)
	ReadObject(object io.Writer) error
	ReadBytes(delim byte) (line []byte, err error)
	ReadString(delim byte) (line string, err error)
	ReadFixedBytes(n int) ([]byte, error)
	ReadFixedString(n int) (string, error)
	Writer() PacketWriter
}

PacketReader is the interface that wraps common used methods that reads numerics, byte slices, strings etc.

func NewPacketReader

func NewPacketReader(buffer *bytes.Buffer, order binary.ByteOrder) PacketReader

NewPacketReader creates and returns a new PacketReader with the given buffer and byte order

type PacketWriter

type PacketWriter interface {
	io.Writer
	io.ReaderFrom
	io.ByteWriter
	WriteRune(r rune) (n int, err error)
	WriteBool(val bool) PacketWriter
	WriteInt8(val int8) PacketWriter
	WriteUint8(val uint8) PacketWriter
	WriteInt16(val int16) PacketWriter
	WriteUint16(val uint16) PacketWriter
	WriteInt32(val int32) PacketWriter
	WriteUint32(val uint32) PacketWriter
	WriteInt64(val int64) PacketWriter
	WriteUint64(val uint64) PacketWriter
	WriteFloat32(val float32) PacketWriter
	WriteFloat64(val float64) PacketWriter
	WriteComplex64(val complex64) PacketWriter
	WriteComplex128(val complex128) PacketWriter
	WriteObject(object io.Reader) error
	WriteString(s string) (n int, err error)
	Reset()
	Reader() PacketReader
}

PacketWriter is the interface that wraps common used methods that writes or puts numerics, byte slices, strings etc.

func NewPacketWriter

func NewPacketWriter(buffer *bytes.Buffer, order binary.ByteOrder) PacketWriter

NewPacketWriter creates and returns a new PacketWriter with the given buffer and byte order

type ParamSpinWait

type ParamSpinWait struct {
	Level int8
	// contains filtered or unexported fields
}

ParamSpinWait is a type that represents a parameterized version of SpinWait. It is used for lightweight synchronization in low-level scenarios with lower cost. The zero value of ParamSpinWait is already initialized and ready to use.

func NewParamSpinWait

func NewParamSpinWait() ParamSpinWait

NewParamSpinWait returns a new instance of ParamSpinWait with default values.

func NewSpinWaitWithLevel

func NewSpinWaitWithLevel(level int8) ParamSpinWait

NewSpinWaitWithLevel returns a new instance of ParamSpinWait with the specified level. The level determines the preemptive behavior of the spin wait, where higher levels result in less delay but more CPU consumption.

func (*ParamSpinWait) Closed

func (sw *ParamSpinWait) Closed() bool

Closed returns true if the limit is greater than 0 and the current count is equal or greater than the limit.

func (*ParamSpinWait) Once

func (sw *ParamSpinWait) Once()

Once performs a single spin operation based on the provided preemptive level.

func (*ParamSpinWait) OnceWithLevel

func (sw *ParamSpinWait) OnceWithLevel(level int)

OnceWithLevel performs a single spin with the given preemptive level.

func (*ParamSpinWait) Reset

func (sw *ParamSpinWait) Reset()

Reset resets the internal counters of the ParamSpinWait instance to their initial values.

func (*ParamSpinWait) SetLevel

func (sw *ParamSpinWait) SetLevel(level int) *ParamSpinWait

SetLevel sets the preemptive Level of the ParamSpinWait to the specified value. Higher preemptive level result in less delay, but more CPU consumption.

func (*ParamSpinWait) SetLimit

func (sw *ParamSpinWait) SetLimit(limit int) *ParamSpinWait

SetLimit sets the limit for the number of times the spin waite can spin before yielding.

func (*ParamSpinWait) WillYield

func (sw *ParamSpinWait) WillYield() bool

WillYield returns true if the spin wait should yield the processor,

func (*ParamSpinWait) WillYieldWithLevel

func (sw *ParamSpinWait) WillYieldWithLevel(level int8) bool

WillYieldWithLevel returns true if the spin wait should yield the processor based on the provided preemptive level.

type PicoBuffer

type PicoBuffer [BufferSizePico]byte

PicoBuffer represents a byte array with size of BufferSizePico

func NewPicoBuffer

func NewPicoBuffer() PicoBuffer

NewPicoBuffer returns a new PicoBuffer.

func (PicoBuffer) Reset

func (b PicoBuffer) Reset()

type PicoBufferBoundedPool

type PicoBufferBoundedPool = BoundedPool[PicoBuffer]

PicoBufferBoundedPool is a type alias of BoundedPool[PicoBuffer].

func NewPicoBufferPool

func NewPicoBufferPool(capacity int) *PicoBufferBoundedPool

NewPicoBufferPool creates a new instance of PicoBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.

type PicoBufferPool

type PicoBufferPool = IndirectPool[PicoBuffer]

PicoBufferPool represents a generic object pool that uses indirect indices to Put and Get items of type PicoBuffer.

type PollCloser

type PollCloser interface {
	PollFd
	io.Closer
}

PollCloser is the interface that groups Fd and the basic Close method

type PollFd

type PollFd interface {
	// Fd returns the file descriptor
	Fd() int
}

PollFd is the interface that warps Fd

type PollReadCloser

type PollReadCloser interface {
	PollReader
	io.Closer
}

PollReadCloser is the interface that groups the methods in interface PollReader and PollCloser

type PollReadWriteCloser

type PollReadWriteCloser interface {
	PollReader
	PollWriter
	io.Closer
}

PollReadWriteCloser is the interface that groups the methods in interface PollReader, PollWriter and PollCloser

type PollReadWriter

type PollReadWriter interface {
	PollReader
	PollWriter
}

PollReadWriter is the interface that groups the methods in interface PollReader and PollWriter

type PollReader

type PollReader interface {
	PollFd
	io.Reader
}

PollReader is the interface that groups Fd and the basic Read method

type PollSignalfd

type PollSignalfd interface {
	PollFd
	// ReadSiginfo reads and returns the came signal info
	ReadSiginfo() (sig unix.Signal, code int, err error)
}

PollSignalfd is the interface that groups Fd and ReadSiginfo method

func NewSignalFile

func NewSignalFile() (signalFile PollSignalfd, err error)

NewSignalFile creates and returns a new signal fd

type PollUintReadCloser

type PollUintReadCloser interface {
	PollUintReader
	io.Closer
}

PollUintReadCloser is the interface that groups the methods in interface PollUintReader and PollUintCloser

type PollUintReadWriteCloser

type PollUintReadWriteCloser interface {
	PollUintReader
	PollUintWriter
	io.Closer
}

PollUintReadWriteCloser is the interface that groups the methods in interface PollUintReader, PollUintWriter and PollCloser

func NewEventfd

func NewEventfd() (PollUintReadWriteCloser, error)

NewEventfd creates and returns a new nonblocking eventfd as a PollUintReadWriteCloser

type PollUintReadWriter

type PollUintReadWriter interface {
	PollUintReader
	PollUintWriter
}

PollUintReadWriter is the interface that groups the methods in interface PollUintReader and PollUintWriter

type PollUintReader

type PollUintReader interface {
	PollReader
	ReadUint() (val uint, err error)
}

PollUintReader is the interface that groups ReadUint() and the methods in interface PollReader

type PollUintWriteCloser

type PollUintWriteCloser interface {
	PollUintWriter
	io.Closer
}

PollUintWriteCloser is the interface that groups the methods in interface PollUintWriter and PollCloser

type PollUintWriter

type PollUintWriter interface {
	PollWriter
	WriteUint(val uint) error
}

PollUintWriter is the interface that groups WriteUint() and the methods in interface PollWriter

type PollWriteCloser

type PollWriteCloser interface {
	PollWriter
	io.Closer
}

PollWriteCloser is the interface that groups the methods in interface PollWriter and PollCloser

type PollWriter

type PollWriter interface {
	PollFd
	io.Writer
}

PollWriter is the interface that groups Fd and the basic Write method

type Pool

type Pool[T any] interface {
	// Put adds item to the pool
	// If the Pool is a nonblocking bounded pool, ErrTemporarilyUnavailable
	// will be returned when the Pool is full.
	// If the Pool is a bounded pool but not nonblocking,
	// Put would block until the Pool is no longer full
	// Note that if the Pool is not nonblocking, the return error can be ignored
	Put(item T) error
	// Get selects an arbitrary item from the Pool,
	// removes it from the Pool, and returns it to the caller.
	// If the Pool is empty and has been set to nonblocking,
	// ErrTemporarilyUnavailable will be returned.
	// If the Pool is empty and has been not set to nonblocking,
	// Get would block until any item put back to the Pool
	// Note that if the Pool is not nonblocking, the return error can be ignored
	Get() (item T, err error)
}

Pool is a generic object pool

type RawConn

type RawConn struct {
	*RawSocket
	// contains filtered or unexported fields
}

func DialRaw4

func DialRaw4(laddr *IPAddr, raddr *IPAddr, protocol int) (*RawConn, error)

func DialRaw6

func DialRaw6(laddr *IPAddr, raddr *IPAddr, protocol int) (*RawConn, error)

func ListenRaw4

func ListenRaw4(laddr *IPAddr, protocol int) (*RawConn, error)

func ListenRaw6

func ListenRaw6(laddr *IPAddr, protocol int) (*RawConn, error)

func (RawConn) Accept

func (so RawConn) Accept() (Socket, error)

func (RawConn) Close

func (so RawConn) Close() error

func (RawConn) Connect

func (so RawConn) Connect(addr Addr) error

func (RawConn) Fd

func (so RawConn) Fd() int

func (*RawConn) LocalAddr

func (conn *RawConn) LocalAddr() Addr

func (RawConn) NetworkType

func (so RawConn) NetworkType() NetworkType

func (*RawConn) Read

func (conn *RawConn) Read(p []byte) (n int, err error)

func (RawConn) Readv

func (so RawConn) Readv(iovs [][]byte) (n int, err error)

func (RawConn) Recvmsg

func (so RawConn) Recvmsg(buffers [][]byte, oob []byte) (n, oobn int, recvflags int, from Sockaddr, err error)

func (*RawConn) RemoteAddr

func (conn *RawConn) RemoteAddr() Addr

func (RawConn) Sendmsg

func (so RawConn) Sendmsg(buffers [][]byte, oob []byte, to Addr) (n int, err error)

func (*RawConn) SetDeadline

func (conn *RawConn) SetDeadline(t time.Time) error

func (*RawConn) SetReadDeadline

func (conn *RawConn) SetReadDeadline(t time.Time) error

func (*RawConn) SetWriteDeadline

func (conn *RawConn) SetWriteDeadline(t time.Time) error

func (*RawConn) Write

func (conn *RawConn) Write(p []byte) (n int, err error)

func (RawConn) Writev

func (so RawConn) Writev(iovs [][]byte) (n int, err error)

type RawSocket

type RawSocket struct {
	// contains filtered or unexported fields
}

func (RawSocket) Accept

func (so RawSocket) Accept() (Socket, error)

func (RawSocket) Close

func (so RawSocket) Close() error

func (RawSocket) Connect

func (so RawSocket) Connect(addr Addr) error

func (RawSocket) Fd

func (so RawSocket) Fd() int

func (RawSocket) NetworkType

func (so RawSocket) NetworkType() NetworkType

func (*RawSocket) Protocol

func (so *RawSocket) Protocol() UnderlyingProtocol

func (RawSocket) Read

func (so RawSocket) Read(b []byte) (n int, err error)

func (RawSocket) Readv

func (so RawSocket) Readv(iovs [][]byte) (n int, err error)

func (*RawSocket) RecvFrom

func (so *RawSocket) RecvFrom(b []byte) (n int, addr Addr, err error)

func (RawSocket) Recvmsg

func (so RawSocket) Recvmsg(buffers [][]byte, oob []byte) (n, oobn int, recvflags int, from Sockaddr, err error)

func (*RawSocket) SendTo

func (so *RawSocket) SendTo(b []byte, raddr Addr) (n int, err error)

func (RawSocket) Sendmsg

func (so RawSocket) Sendmsg(buffers [][]byte, oob []byte, to Addr) (n int, err error)

func (RawSocket) Write

func (so RawSocket) Write(b []byte) (n int, err error)

func (RawSocket) Writev

func (so RawSocket) Writev(iovs [][]byte) (n int, err error)

type RegisterBuffer

type RegisterBuffer [registerBufferSize]byte

RegisterBuffer represents a fixed-size buffer used for registering with the I/O ring.

type RegisterBufferPool

type RegisterBufferPool = BoundedPool[RegisterBuffer]

RegisterBufferPool represents a pool of fixed-size buffers used for registering with the I/O ring.

func NewRegisterBufferPool

func NewRegisterBufferPool(capacity int) *RegisterBufferPool

NewRegisterBufferPool creates a new instance of RegisterBufferPool with the specified capacity.

type RingQueueOptions

type RingQueueOptions struct {
	// Capacity specifies the capacity of queue. The default Capacity is 32K
	Capacity int
	// ConcurrentProduce specifies whether the ItemProducer works concurrently or not
	// It should be set as true, if there are multiple goroutines doing Produce operations
	ConcurrentProduce bool
	// ConcurrentConsume specifies whether the ItemConsumer works concurrently or not
	// It should be set as true, if there are multiple goroutines doing Consumer operations
	ConcurrentConsume bool
	// Nonblocking specifies whether the Produce or Consume operations will NOT block
	// even if it is temporarily unavailable or not
	Nonblocking bool
}

RingQueueOptions holds optional parameters for RingQueue implementations

type SCTPAddr

type SCTPAddr struct {
	IP   net.IP
	Port int
	Zone string
}

SCTPAddr represents the address of a SCTP endpoint. It contains the IP address, port number, and IPv6 zone.

func ResolveSCTPAddr

func ResolveSCTPAddr(network, address string) (*SCTPAddr, error)

ResolveSCTPAddr resolves the SCTP network address of the given network and address string. It returns a new SCTPAddr based on the resolved address and network. Possible network values are "sctp", "sctp4", and "sctp6".

func SCTPAddrFromAddrPort

func SCTPAddrFromAddrPort(addr netip.AddrPort) *SCTPAddr

SCTPAddrFromAddrPort returns a new SCTPAddr based on the given netip.AddrPort.

func (*SCTPAddr) Network

func (a *SCTPAddr) Network() string

Network returns the network name "sctp"

func (*SCTPAddr) String

func (a *SCTPAddr) String() string

String returns the string representation of the SCTPAddr. It returns "<nil>" if the SCTPAddr is nil. Otherwise, it combines the IP address, IPv6 zone (if present), and port number using the net.JoinHostPort function and returns the resulting string.

type SCTPConn

type SCTPConn struct {
	*SCTPSocket
	// contains filtered or unexported fields
}

func DialSCTP4

func DialSCTP4(laddr *SCTPAddr, raddr *SCTPAddr) (*SCTPConn, error)

func DialSCTP6

func DialSCTP6(laddr *SCTPAddr, raddr *SCTPAddr) (*SCTPConn, error)

func (SCTPConn) Accept

func (so SCTPConn) Accept() (Socket, error)

func (SCTPConn) Close

func (so SCTPConn) Close() error

func (SCTPConn) Connect

func (so SCTPConn) Connect(addr Addr) error

func (SCTPConn) Fd

func (so SCTPConn) Fd() int

func (*SCTPConn) LocalAddr

func (conn *SCTPConn) LocalAddr() Addr

func (SCTPConn) NetworkType

func (so SCTPConn) NetworkType() NetworkType

func (SCTPConn) Read

func (so SCTPConn) Read(b []byte) (n int, err error)

func (SCTPConn) Readv

func (so SCTPConn) Readv(iovs [][]byte) (n int, err error)

func (SCTPConn) Recvmsg

func (so SCTPConn) Recvmsg(buffers [][]byte, oob []byte) (n, oobn int, recvflags int, from Sockaddr, err error)

func (*SCTPConn) RemoteAddr

func (conn *SCTPConn) RemoteAddr() Addr

func (SCTPConn) Sendmsg

func (so SCTPConn) Sendmsg(buffers [][]byte, oob []byte, to Addr) (n int, err error)

func (*SCTPConn) SetDeadline

func (conn *SCTPConn) SetDeadline(t time.Time) error

func (*SCTPConn) SetReadDeadline

func (conn *SCTPConn) SetReadDeadline(t time.Time) error

func (*SCTPConn) SetWriteDeadline

func (conn *SCTPConn) SetWriteDeadline(t time.Time) error

func (SCTPConn) Write

func (so SCTPConn) Write(b []byte) (n int, err error)

func (SCTPConn) Writev

func (so SCTPConn) Writev(iovs [][]byte) (n int, err error)

type SCTPListener

type SCTPListener struct {
	*SCTPSocket
	// contains filtered or unexported fields
}

func ListenSCTP4

func ListenSCTP4(laddr *SCTPAddr) (*SCTPListener, error)

func ListenSCTP6

func ListenSCTP6(laddr *SCTPAddr) (*SCTPListener, error)

func (*SCTPListener) Accept

func (l *SCTPListener) Accept() (Conn, error)

func (*SCTPListener) Addr

func (l *SCTPListener) Addr() Addr

func (*SCTPListener) Close

func (l *SCTPListener) Close() error

func (SCTPListener) Connect

func (so SCTPListener) Connect(addr Addr) error

func (SCTPListener) Fd

func (so SCTPListener) Fd() int

func (SCTPListener) NetworkType

func (so SCTPListener) NetworkType() NetworkType

func (SCTPListener) Read

func (so SCTPListener) Read(b []byte) (n int, err error)

func (SCTPListener) Readv

func (so SCTPListener) Readv(iovs [][]byte) (n int, err error)

func (SCTPListener) Recvmsg

func (so SCTPListener) Recvmsg(buffers [][]byte, oob []byte) (n, oobn int, recvflags int, from Sockaddr, err error)

func (SCTPListener) Sendmsg

func (so SCTPListener) Sendmsg(buffers [][]byte, oob []byte, to Addr) (n int, err error)

func (SCTPListener) Write

func (so SCTPListener) Write(b []byte) (n int, err error)

func (SCTPListener) Writev

func (so SCTPListener) Writev(iovs [][]byte) (n int, err error)

type SCTPSocket

type SCTPSocket struct {
	// contains filtered or unexported fields
}

func (SCTPSocket) Accept

func (so SCTPSocket) Accept() (Socket, error)

func (*SCTPSocket) Bind

func (so *SCTPSocket) Bind(addr ...*SCTPAddr) error

Bind binds addresses to the SCTP socket

func (SCTPSocket) Close

func (so SCTPSocket) Close() error

func (SCTPSocket) Connect

func (so SCTPSocket) Connect(addr Addr) error

func (SCTPSocket) Fd

func (so SCTPSocket) Fd() int

func (SCTPSocket) NetworkType

func (so SCTPSocket) NetworkType() NetworkType

func (*SCTPSocket) Protocol

func (so *SCTPSocket) Protocol() UnderlyingProtocol

func (SCTPSocket) Read

func (so SCTPSocket) Read(b []byte) (n int, err error)

func (SCTPSocket) Readv

func (so SCTPSocket) Readv(iovs [][]byte) (n int, err error)

func (SCTPSocket) Recvmsg

func (so SCTPSocket) Recvmsg(buffers [][]byte, oob []byte) (n, oobn int, recvflags int, from Sockaddr, err error)

func (SCTPSocket) Sendmsg

func (so SCTPSocket) Sendmsg(buffers [][]byte, oob []byte, to Addr) (n int, err error)

func (*SCTPSocket) Shutdown

func (so *SCTPSocket) Shutdown(how int) error

func (SCTPSocket) Write

func (so SCTPSocket) Write(b []byte) (n int, err error)

func (SCTPSocket) Writev

func (so SCTPSocket) Writev(iovs [][]byte) (n int, err error)

type SmallBuffer

type SmallBuffer [BufferSizeSmall]byte

SmallBuffer represents a byte array with size of BufferSizeSmall

func NewSmallBuffer

func NewSmallBuffer() SmallBuffer

NewSmallBuffer returns a new instance of SmallBuffer.

func (SmallBuffer) Reset

func (b SmallBuffer) Reset()

type SmallBufferBoundedPool

type SmallBufferBoundedPool = BoundedPool[SmallBuffer]

SmallBufferBoundedPool is a type alias of BoundedPool[SmallBuffer].

func NewSmallBufferPool

func NewSmallBufferPool(capacity int) *SmallBufferBoundedPool

NewSmallBufferPool creates a new instance of SmallBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.

type SmallBufferPool

type SmallBufferPool = IndirectPool[SmallBuffer]

SmallBufferPool represents a generic object pool that uses indirect indices to Put and Get items of type SmallBuffer.

type Sockaddr

type Sockaddr = unix.Sockaddr

Sockaddr is an alias for the unix.Sockaddr type.

func AddrToSockaddr

func AddrToSockaddr(addr Addr) Sockaddr

AddrToSockaddr takes a network address and returns the Sockaddr type socket address.

func NetworkAddressToSockaddr

func NetworkAddressToSockaddr(network, address string) (Sockaddr, error)

NetworkAddressToSockaddr returns the corresponding Sockaddr type socket address. It resolves the network address and creates a Sockaddr based on the network type.

type SockaddrInet4

type SockaddrInet4 = unix.SockaddrInet4

SockaddrInet4 is an alias for the unix.SockaddrInet4 type.

type SockaddrInet6

type SockaddrInet6 = unix.SockaddrInet6

SockaddrInet6 is an alias for the unix.SockaddrInet6 type.

type SockaddrUnix

type SockaddrUnix = unix.SockaddrUnix

SockaddrUnix is an alias for the unix.SockaddrUnix type.

type Socket

type Socket interface {
	// Fd returns the file descriptor associated with the socket.
	Fd() int

	// NetworkType returns the network type associated with the socket.
	NetworkType() NetworkType

	// Protocol returns the underlying protocol of the Socket.
	// It indicates the transmission protocol features.
	Protocol() UnderlyingProtocol

	// Reader is an interface that represents an object that can read data.
	io.Reader

	// Writer is an interface that represents a data writer.
	io.Writer

	// Closer is an interface implemented by objects that can be closed.
	io.Closer
}

Socket is a generic network socket

func SocketPair

func SocketPair(network string) (so [2]Socket, err error)

type SpinWait

type SpinWait struct {
	// contains filtered or unexported fields
}

SpinWait is a lightweight synchronization type that you can use in low-level scenarios with lower cost. The zero value for SpinWait is ready to use.

func (*SpinWait) Once

func (s *SpinWait) Once()

Once performs a single spin

func (*SpinWait) Reset

func (s *SpinWait) Reset()

Reset resets the counter in SpinWait

func (*SpinWait) WillYield

func (s *SpinWait) WillYield() bool

WillYield returns true if calling SpinOnce() will result in occurring a thread sleeping instead of a simply procyield()

type Spinlock

type Spinlock struct {
	// contains filtered or unexported fields
}

Spinlock is a synchronization type that provides a simple spinlock mechanism. The zero value for Spinlock is ready to use.

func (*Spinlock) Lock

func (sl *Spinlock) Lock()

Lock attempts to acquire the spinlock. If it fails, it will spin wait until it succeeds.

func (*Spinlock) SpinOnce

func (sl *Spinlock) SpinOnce()

SpinOnce performs a single spin using the SpinWait synchronization type.

func (*Spinlock) TryLock

func (sl *Spinlock) TryLock() bool

TryLock attempts to acquire the Spinlock and returns true if successful, otherwise it returns false.

func (*Spinlock) Unlock

func (sl *Spinlock) Unlock()

Unlock releases the spinlock.

type Stack

type Stack[ItemType any] interface {
	// Push inserts an element at the of the Stack
	// It returns io.ErrClosesPipe if the Stack is closed.
	// If the Stack is full and the Nonblocking option is set as true,
	// an ErrTemporarilyUnavailable will be returned.
	// If the Stack is full and the Nonblocking option is set as false,
	// the Push operation blocks until the Stack became not full
	Push(item ItemType) error
	// Pop removes and returns the element at the top of the Stack
	// When the Stack is empty,
	//   It returns the zero-value and io.EOF if the Stack is already closed.
	//   It returns the zero-value and ErrTemporarilyUnavailable if the Stack is set as Nonblocking.
	//   If the stack is not set as Nonblocking, it blocks until any element has been Pushed.
	Pop() (item ItemType, err error)
	// Close closes the Stack. The return value is always nil.
	Close() error
}

Stack is the interface that wraps Push and Pop operations on a Stack

func NewFixedStack

func NewFixedStack[ItemType any](opts ...func(options *FixedStackOptions)) (Stack[ItemType], error)

NewFixedStack creates and returns a fixed capacity Stack with the given options

type TCPAddr

type TCPAddr = net.TCPAddr

TCPAddr represents the address of a TCP endpoint. It is a type alias for the net.TCPAddr type.

type TCPConn

type TCPConn struct {
	*TCPSocket
	// contains filtered or unexported fields
}

func DialTCP4

func DialTCP4(laddr *TCPAddr, raddr *TCPAddr) (*TCPConn, error)

func DialTCP6

func DialTCP6(laddr *TCPAddr, raddr *TCPAddr) (*TCPConn, error)

func (TCPConn) Accept

func (so TCPConn) Accept() (Socket, error)

func (TCPConn) Close

func (so TCPConn) Close() error

func (TCPConn) Connect

func (so TCPConn) Connect(addr Addr) error

func (TCPConn) Fd

func (so TCPConn) Fd() int

func (*TCPConn) LocalAddr

func (conn *TCPConn) LocalAddr() Addr

func (TCPConn) NetworkType

func (so TCPConn) NetworkType() NetworkType

func (TCPConn) Read

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

func (TCPConn) Readv

func (so TCPConn) Readv(iovs [][]byte) (n int, err error)

func (TCPConn) Recvmsg

func (so TCPConn) Recvmsg(buffers [][]byte, oob []byte) (n, oobn int, recvflags int, from Sockaddr, err error)

func (*TCPConn) RemoteAddr

func (conn *TCPConn) RemoteAddr() Addr

func (TCPConn) Sendmsg

func (so TCPConn) Sendmsg(buffers [][]byte, oob []byte, to Addr) (n int, err error)

func (*TCPConn) SetDeadline

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

func (*TCPConn) SetReadDeadline

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

func (*TCPConn) SetWriteDeadline

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

func (TCPConn) Write

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

func (TCPConn) Writev

func (so TCPConn) Writev(iovs [][]byte) (n int, err error)

type TCPListener

type TCPListener struct {
	*TCPSocket
	// contains filtered or unexported fields
}

func ListenTCP4

func ListenTCP4(laddr *TCPAddr) (*TCPListener, error)

func ListenTCP6

func ListenTCP6(laddr *TCPAddr) (*TCPListener, error)

func (*TCPListener) Accept

func (l *TCPListener) Accept() (Conn, error)

func (*TCPListener) Addr

func (l *TCPListener) Addr() Addr

func (TCPListener) Close

func (so TCPListener) Close() error

func (TCPListener) Connect

func (so TCPListener) Connect(addr Addr) error

func (TCPListener) Fd

func (so TCPListener) Fd() int

func (TCPListener) NetworkType

func (so TCPListener) NetworkType() NetworkType

func (TCPListener) Read

func (so TCPListener) Read(b []byte) (n int, err error)

func (TCPListener) Readv

func (so TCPListener) Readv(iovs [][]byte) (n int, err error)

func (TCPListener) Recvmsg

func (so TCPListener) Recvmsg(buffers [][]byte, oob []byte) (n, oobn int, recvflags int, from Sockaddr, err error)

func (TCPListener) Sendmsg

func (so TCPListener) Sendmsg(buffers [][]byte, oob []byte, to Addr) (n int, err error)

func (TCPListener) Write

func (so TCPListener) Write(b []byte) (n int, err error)

func (TCPListener) Writev

func (so TCPListener) Writev(iovs [][]byte) (n int, err error)

type TCPSocket

type TCPSocket struct {
	// contains filtered or unexported fields
}

func (TCPSocket) Accept

func (so TCPSocket) Accept() (Socket, error)

func (TCPSocket) Close

func (so TCPSocket) Close() error

func (TCPSocket) Connect

func (so TCPSocket) Connect(addr Addr) error

func (TCPSocket) Fd

func (so TCPSocket) Fd() int

func (TCPSocket) NetworkType

func (so TCPSocket) NetworkType() NetworkType

func (*TCPSocket) Protocol

func (so *TCPSocket) Protocol() UnderlyingProtocol

func (TCPSocket) Read

func (so TCPSocket) Read(b []byte) (n int, err error)

func (TCPSocket) Readv

func (so TCPSocket) Readv(iovs [][]byte) (n int, err error)

func (TCPSocket) Recvmsg

func (so TCPSocket) Recvmsg(buffers [][]byte, oob []byte) (n, oobn int, recvflags int, from Sockaddr, err error)

func (TCPSocket) Sendmsg

func (so TCPSocket) Sendmsg(buffers [][]byte, oob []byte, to Addr) (n int, err error)

func (*TCPSocket) Shutdown

func (so *TCPSocket) Shutdown(how int) error

func (TCPSocket) Write

func (so TCPSocket) Write(b []byte) (n int, err error)

func (TCPSocket) Writev

func (so TCPSocket) Writev(iovs [][]byte) (n int, err error)

type TickedHandler

type TickedHandler interface {
	ServeMessage(at time.Time)
}

TickedHandler handles timer events

type Timer

type Timer interface {
	Now() time.Time
	PollReadCloser
}

type UDPAddr

type UDPAddr = net.UDPAddr

UDPAddr represents the address of a UDP endpoint. It is a type alias for the net.UDPAddr type.

type UDPConn

type UDPConn struct {
	*UDPSocket
	// contains filtered or unexported fields
}

func DialUDP4

func DialUDP4(laddr *UDPAddr, raddr *UDPAddr) (*UDPConn, error)

func DialUDP6

func DialUDP6(laddr *UDPAddr, raddr *UDPAddr) (*UDPConn, error)

func ListenUDP

func ListenUDP(network string, laddr *UDPAddr) (conn *UDPConn, err error)

func ListenUDP4

func ListenUDP4(laddr *UDPAddr) (*UDPConn, error)

func ListenUDP6

func ListenUDP6(laddr *UDPAddr) (*UDPConn, error)

func (UDPConn) Accept

func (so UDPConn) Accept() (Socket, error)

func (UDPConn) Close

func (so UDPConn) Close() error

func (UDPConn) Connect

func (so UDPConn) Connect(addr Addr) error

func (UDPConn) Fd

func (so UDPConn) Fd() int

func (*UDPConn) LocalAddr

func (conn *UDPConn) LocalAddr() Addr

func (UDPConn) NetworkType

func (so UDPConn) NetworkType() NetworkType

func (*UDPConn) Read

func (conn *UDPConn) Read(p []byte) (n int, err error)

func (UDPConn) Readv

func (so UDPConn) Readv(iovs [][]byte) (n int, err error)

func (UDPConn) Recvmsg

func (so UDPConn) Recvmsg(buffers [][]byte, oob []byte) (n, oobn int, recvflags int, from Sockaddr, err error)

func (*UDPConn) RemoteAddr

func (conn *UDPConn) RemoteAddr() Addr

func (UDPConn) Sendmsg

func (so UDPConn) Sendmsg(buffers [][]byte, oob []byte, to Addr) (n int, err error)

func (*UDPConn) SetDeadline

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

func (*UDPConn) SetReadDeadline

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

func (*UDPConn) SetWriteDeadline

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

func (*UDPConn) Write

func (conn *UDPConn) Write(p []byte) (n int, err error)

func (UDPConn) Writev

func (so UDPConn) Writev(iovs [][]byte) (n int, err error)

type UDPSocket

type UDPSocket struct {
	// contains filtered or unexported fields
}

func (UDPSocket) Accept

func (so UDPSocket) Accept() (Socket, error)

func (UDPSocket) Close

func (so UDPSocket) Close() error

func (UDPSocket) Connect

func (so UDPSocket) Connect(addr Addr) error

func (*UDPSocket) Dial4

func (so *UDPSocket) Dial4(raddr *UDPAddr) (conn *UDPConn, err error)

func (*UDPSocket) Dial6

func (so *UDPSocket) Dial6(raddr *UDPAddr) (conn *UDPConn, err error)

func (UDPSocket) Fd

func (so UDPSocket) Fd() int

func (UDPSocket) NetworkType

func (so UDPSocket) NetworkType() NetworkType

func (*UDPSocket) Protocol

func (so *UDPSocket) Protocol() UnderlyingProtocol

func (UDPSocket) Read

func (so UDPSocket) Read(b []byte) (n int, err error)

func (UDPSocket) Readv

func (so UDPSocket) Readv(iovs [][]byte) (n int, err error)

func (*UDPSocket) RecvFrom

func (so *UDPSocket) RecvFrom(b []byte) (n int, addr Addr, err error)

func (UDPSocket) Recvmsg

func (so UDPSocket) Recvmsg(buffers [][]byte, oob []byte) (n, oobn int, recvflags int, from Sockaddr, err error)

func (*UDPSocket) SendTo

func (so *UDPSocket) SendTo(b []byte, raddr Addr) (n int, err error)

func (UDPSocket) Sendmsg

func (so UDPSocket) Sendmsg(buffers [][]byte, oob []byte, to Addr) (n int, err error)

func (UDPSocket) Write

func (so UDPSocket) Write(b []byte) (n int, err error)

func (UDPSocket) Writev

func (so UDPSocket) Writev(iovs [][]byte) (n int, err error)

type UnderlyingProtocol

type UnderlyingProtocol int

UnderlyingProtocol represents transmission protocol features

const (
	// UnderlyingProtocolStream means the underlying protocol works like a stream
	UnderlyingProtocolStream UnderlyingProtocol = 1
	// UnderlyingProtocolDgram means the underlying protocol works like datagram
	UnderlyingProtocolDgram UnderlyingProtocol = 2
	// UnderlyingProtocolRaw means the underlying protocol works rawly
	UnderlyingProtocolRaw UnderlyingProtocol = 3
	// UnderlyingProtocolSeqPacket means the underlying protocol works like a sequenced packet
	UnderlyingProtocolSeqPacket UnderlyingProtocol = 5
)

func (UnderlyingProtocol) PreserveBoundary

func (t UnderlyingProtocol) PreserveBoundary() bool

PreserveBoundary returns true if the underlying protocol preserves message boundaries

type UnixAddr

type UnixAddr = net.UnixAddr

UnixAddr represents a Unix domain socket address. It is an alias for the net.UnixAddr type.

type UnixConn

type UnixConn struct {
	*UnixSocket
	// contains filtered or unexported fields
}

func DialUnix

func DialUnix(laddr *UnixAddr, raddr *UnixAddr) (*UnixConn, error)

func (UnixConn) Accept

func (so UnixConn) Accept() (Socket, error)

func (UnixConn) Close

func (so UnixConn) Close() error

func (UnixConn) Connect

func (so UnixConn) Connect(addr Addr) error

func (UnixConn) Fd

func (so UnixConn) Fd() int

func (*UnixConn) LocalAddr

func (conn *UnixConn) LocalAddr() Addr

func (UnixConn) NetworkType

func (so UnixConn) NetworkType() NetworkType

func (UnixConn) Read

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

func (UnixConn) Readv

func (so UnixConn) Readv(iovs [][]byte) (n int, err error)

func (UnixConn) Recvmsg

func (so UnixConn) Recvmsg(buffers [][]byte, oob []byte) (n, oobn int, recvflags int, from Sockaddr, err error)

func (*UnixConn) RemoteAddr

func (conn *UnixConn) RemoteAddr() Addr

func (UnixConn) Sendmsg

func (so UnixConn) Sendmsg(buffers [][]byte, oob []byte, to Addr) (n int, err error)

func (*UnixConn) SetDeadline

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

func (*UnixConn) SetReadDeadline

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

func (*UnixConn) SetWriteDeadline

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

func (UnixConn) Write

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

func (UnixConn) Writev

func (so UnixConn) Writev(iovs [][]byte) (n int, err error)

type UnixListener

type UnixListener struct {
	*UnixSocket
	// contains filtered or unexported fields
}

func ListenUnix

func ListenUnix(laddr *UnixAddr) (*UnixListener, error)

func (*UnixListener) Accept

func (l *UnixListener) Accept() (Conn, error)

func (*UnixListener) Addr

func (l *UnixListener) Addr() Addr

func (*UnixListener) Close

func (l *UnixListener) Close() error

func (UnixListener) Connect

func (so UnixListener) Connect(addr Addr) error

func (UnixListener) Fd

func (so UnixListener) Fd() int

func (UnixListener) NetworkType

func (so UnixListener) NetworkType() NetworkType

func (UnixListener) Read

func (so UnixListener) Read(b []byte) (n int, err error)

func (UnixListener) Readv

func (so UnixListener) Readv(iovs [][]byte) (n int, err error)

func (UnixListener) Recvmsg

func (so UnixListener) Recvmsg(buffers [][]byte, oob []byte) (n, oobn int, recvflags int, from Sockaddr, err error)

func (UnixListener) Sendmsg

func (so UnixListener) Sendmsg(buffers [][]byte, oob []byte, to Addr) (n int, err error)

func (UnixListener) Write

func (so UnixListener) Write(b []byte) (n int, err error)

func (UnixListener) Writev

func (so UnixListener) Writev(iovs [][]byte) (n int, err error)

type UnixSocket

type UnixSocket struct {
	// contains filtered or unexported fields
}

func (UnixSocket) Accept

func (so UnixSocket) Accept() (Socket, error)

func (UnixSocket) Close

func (so UnixSocket) Close() error

func (UnixSocket) Connect

func (so UnixSocket) Connect(addr Addr) error

func (UnixSocket) Fd

func (so UnixSocket) Fd() int

func (UnixSocket) NetworkType

func (so UnixSocket) NetworkType() NetworkType

func (*UnixSocket) Protocol

func (so *UnixSocket) Protocol() UnderlyingProtocol

func (UnixSocket) Read

func (so UnixSocket) Read(b []byte) (n int, err error)

func (UnixSocket) Readv

func (so UnixSocket) Readv(iovs [][]byte) (n int, err error)

func (UnixSocket) Recvmsg

func (so UnixSocket) Recvmsg(buffers [][]byte, oob []byte) (n, oobn int, recvflags int, from Sockaddr, err error)

func (UnixSocket) Sendmsg

func (so UnixSocket) Sendmsg(buffers [][]byte, oob []byte, to Addr) (n int, err error)

func (*UnixSocket) Shutdown

func (so *UnixSocket) Shutdown(how int) error

func (UnixSocket) Write

func (so UnixSocket) Write(b []byte) (n int, err error)

func (UnixSocket) Writev

func (so UnixSocket) Writev(iovs [][]byte) (n int, err error)

type UnknownNetworkError

type UnknownNetworkError = net.UnknownNetworkError

UnknownNetworkError represents an error when an unknown network is encountered. The error is typically returned when unexpected network types are encountered in network-related operations.

type Uring

type Uring struct {
	*UringOptions
	Features *UringFeatures
	// contains filtered or unexported fields
}

func NewUring

func NewUring(options ...func(options *UringOptions)) (*Uring, error)

func (*Uring) Accept

func (ur *Uring) Accept(ctx context.Context, listener Socket, options ...UringOpOptionFunc) error

Accept accepts a new connection from listener

func (*Uring) AsyncCancel

func (ur *Uring) AsyncCancel(ctx context.Context, userdata *ioUringCtx, options ...UringOpOptionFunc) error

AsyncCancel cancels pending async operation

func (*Uring) Bind

func (ur *Uring) Bind(ctx context.Context, so Socket, addr Addr, options ...UringOpOptionFunc) error

func (*Uring) Close

func (ur *Uring) Close(ctx context.Context, file PollCloser, options ...UringOpOptionFunc) error

Close closes file descriptor

func (*Uring) Connect

func (ur *Uring) Connect(ctx context.Context, so Socket, remote Addr, options ...UringOpOptionFunc) error

Connect initiates socket connection to remote address

func (*Uring) Fallocate

func (ur *Uring) Fallocate(ctx context.Context, fd int, mode uint32, offset int64, length int64, options ...UringOpOptionFunc) error

Fallocate allocates space for file

func (*Uring) FileAdvise

func (ur *Uring) FileAdvise(ctx context.Context, fd int, offset int64, length int, advice int, options ...UringOpOptionFunc) error

FileAdvise provides advice about file access patterns

func (*Uring) LinkTimeout

func (ur *Uring) LinkTimeout(ctx context.Context, d time.Duration, options ...UringOpOptionFunc) error

LinkTimeout creates linked timeout operation

func (*Uring) Listen

func (ur *Uring) Listen(ctx context.Context, so Socket, options ...UringOpOptionFunc) error

Listen starts listening on a given socket with the specified options and manages I/O operations using io_uring. Listen starts socket listening with given options

func (*Uring) Nop

func (ur *Uring) Nop(ctx context.Context, options ...UringOpOptionFunc) error

Nop submits no-op request

func (*Uring) OpenAt

func (ur *Uring) OpenAt(ctx context.Context, dirfd int, pathname string, flags int, mode uint32, options ...UringOpOptionFunc) error

OpenAt opens file at given path relative to directory fd

func (*Uring) PollAdd

func (ur *Uring) PollAdd(ctx context.Context, fd int, events int, options ...UringOpOptionFunc) error

PollAdd adds file descriptor to poll set

func (*Uring) PollRemove

func (ur *Uring) PollRemove(ctx context.Context, options ...UringOpOptionFunc) error

PollRemove removes file descriptor from poll set

func (*Uring) Read

func (ur *Uring) Read(ctx context.Context, fd int, b []byte, options ...UringOpOptionFunc) error

Read performs read operation

func (*Uring) ReadFixed

func (ur *Uring) ReadFixed(ctx context.Context, fd int, bufIndex int, options ...UringOpOptionFunc) ([]byte, error)

ReadFixed performs read with fixed buffer

func (*Uring) ReadV

func (ur *Uring) ReadV(ctx context.Context, fd int, iovs [][]byte, options ...UringOpOptionFunc) error

ReadV performs vectored read operation

func (*Uring) Receive

func (ur *Uring) Receive(ctx context.Context, so Socket, b []byte, options ...UringOpOptionFunc) error

Receive performs socket receive operation

func (*Uring) RecvMsg

func (ur *Uring) RecvMsg(ctx context.Context, so PollFd, buffers [][]byte, oob []byte, options ...UringOpOptionFunc) error

RecvMsg receives message with control data

func (*Uring) SCTP4Socket

func (ur *Uring) SCTP4Socket(ctx context.Context, options ...UringOpOptionFunc) error

func (*Uring) SCTP6Socket

func (ur *Uring) SCTP6Socket(ctx context.Context, options ...UringOpOptionFunc) error

func (*Uring) Send

func (ur *Uring) Send(ctx context.Context, so Socket, p []byte, options ...UringOpOptionFunc) error

Send writes data to socket

func (*Uring) SendMsg

func (ur *Uring) SendMsg(ctx context.Context, so PollFd, buffers [][]byte, oob []byte, to Addr, options ...UringOpOptionFunc) error

SendMsg sends message with control data

func (*Uring) Shutdown

func (ur *Uring) Shutdown(ctx context.Context, so Socket, how int, options ...UringOpOptionFunc) error

Shutdown gracefully closes socket

func (*Uring) Socket

func (ur *Uring) Socket(ctx context.Context, network, address string, options ...UringOpOptionFunc) error

func (*Uring) SocketRaw

func (ur *Uring) SocketRaw(ctx context.Context, domain, typ, proto int, options ...UringOpOptionFunc) error

func (*Uring) Splice

func (ur *Uring) Splice(ctx context.Context, fdIn, fdOut int, len int, options ...UringOpOptionFunc) error

Splice transfers data between file descriptors

func (*Uring) Start

func (ur *Uring) Start(ctx context.Context) error

func (*Uring) Sync

func (ur *Uring) Sync(ctx context.Context, fd int, options ...UringOpOptionFunc) error

Sync performs file sync operation

func (*Uring) SyncFileRange

func (ur *Uring) SyncFileRange(ctx context.Context, fd int, offset int64, length int, flags int, options ...UringOpOptionFunc) error

SyncFileRange syncs file range to storage

func (*Uring) TCP4Socket

func (ur *Uring) TCP4Socket(ctx context.Context, options ...UringOpOptionFunc) error

func (*Uring) TCP6Socket

func (ur *Uring) TCP6Socket(ctx context.Context, options ...UringOpOptionFunc) error

func (*Uring) Tee

func (ur *Uring) Tee(ctx context.Context, fdIn, fdOut int, length int, options ...UringOpOptionFunc) error

Tee duplicates data between pipes

func (*Uring) Timeout

func (ur *Uring) Timeout(ctx context.Context, d time.Duration, options ...UringOpOptionFunc) error

Timeout submits timeout request with specified duration

func (*Uring) TimeoutRemove

func (ur *Uring) TimeoutRemove(ctx context.Context, userData unsafe.Pointer, options ...UringOpOptionFunc) error

TimeoutRemove removes timeout request

func (*Uring) UDP4Socket

func (ur *Uring) UDP4Socket(ctx context.Context, options ...UringOpOptionFunc) error

func (*Uring) UDP6Socket

func (ur *Uring) UDP6Socket(ctx context.Context, options ...UringOpOptionFunc) error

func (*Uring) UDPLITE4Socket

func (ur *Uring) UDPLITE4Socket(ctx context.Context, options ...UringOpOptionFunc) error

func (*Uring) UDPLITE6Socket

func (ur *Uring) UDPLITE6Socket(ctx context.Context, options ...UringOpOptionFunc) error

func (*Uring) UnixSocket

func (ur *Uring) UnixSocket(ctx context.Context, options ...UringOpOptionFunc) error

func (*Uring) Wait

func (ur *Uring) Wait(events []*UringEvent) (n int, err error)

func (*Uring) Write

func (ur *Uring) Write(ctx context.Context, fd int, b []byte, n int, options ...UringOpOptionFunc) error

Write performs write operation

func (*Uring) WriteFixed

func (ur *Uring) WriteFixed(ctx context.Context, fd int, bufIndex int, n int, options ...UringOpOptionFunc) error

WriteFixed performs write with fixed buffer

func (*Uring) WriteV

func (ur *Uring) WriteV(ctx context.Context, fd int, iovs [][]byte, options ...UringOpOptionFunc) error

WriteV performs vectored write operation

type UringEvent

type UringEvent struct {
	*UringEventData
	Result int32
	Flags  uint32
}

type UringEventData

type UringEventData struct {
	Operation uint8
	OpFlags   uint8
	Buffer    bufferGroupIndex // buf_index or buf_group
	FD        ioUringFd
	UserData  ioUringUserdata
}

type UringFeatures

type UringFeatures struct {
	SQEntries         int
	CQEntries         int
	UserdataByteOrder binary.ByteOrder
}

type UringOpOption

type UringOpOption struct {
	Flags           uint8
	Callback        uint8
	Ioprio          uint16
	FileIndex       uint32
	Backlog         int
	ReadBufferSize  int
	WriteBufferSize int
	Duration        time.Duration
	FileMode        os.FileMode
	Advice          int
	Offset          int64
	N               *int
	Count           int
}

func (*UringOpOption) Apply

func (uo *UringOpOption) Apply(opts ...UringOpOptionFunc)

type UringOpOptionFunc

type UringOpOptionFunc func(opt *UringOpOption)

type UringOptionFunc

type UringOptionFunc func(opt *UringOptions)
var (
	UringLargeLockedBufferMemOptions UringOptionFunc = func(opt *UringOptions) {
		opt.LockedBufferMem = registerBufferSize * registerBufferNum
	}
	UringMultiSizeBufferOptions UringOptionFunc = func(opt *UringOptions) {
		opt.MultiSizeBuffer = 1
	}
)

type UringOptions

type UringOptions struct {
	Entries                 int
	LockedBufferMem         int
	ReadBufferSize          int
	ReadBufferNum           int
	ReadBufferGidOffset     int
	WriteBufferSize         int
	WriteBufferNum          int
	MultiSizeBuffer         int
	MultiIssuers            bool
	NotifySucceed           bool
	IndirectSubmissionQueue bool
}

func (*UringOptions) Apply

func (uo *UringOptions) Apply(opts ...UringOptionFunc)

type WrittenHandler

type WrittenHandler interface {
	ServeWritten(ctx context.Context, writer PollWriter)
}

WrittenHandler handles send message completed events

Jump to

Keyboard shortcuts

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