internal

package
v0.0.0-...-bda8275 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PollerReadEvent  = PollerEvent(syscall.EPOLLIN)
	PollerWriteEvent = PollerEvent(syscall.EPOLLOUT)
)

Variables

View Source
var (
	ListenBacklog int = 2048
)

Functions

func ApplyOpts

func ApplyOpts(fd int, opts ...sonicopts.Option) error

func Connect

func Connect(
	network, addr string,
	opts ...sonicopts.Option,
) (fd int, localAddr, remoteAddr net.Addr, err error)

Connect connects to the specified endpoint. The created connection can be optionally bound to a local address by passing the option sonicopts.BindBeforeConnect(to net.Addr)

If network is of type UDP, then addr is the address to which datagrams are sent by default, and the only address from which datagrams are received.

func ConnectTCP

func ConnectTCP(
	network, addr string,
	timeout time.Duration,
	opts ...sonicopts.Option,
) (fd int, localAddr, remoteAddr net.Addr, err error)

func ConnectTimeout

func ConnectTimeout(
	network, addr string,
	timeout time.Duration,
	opts ...sonicopts.Option,
) (fd int, localAddr, remoteAddr net.Addr, err error)

func ConnectUDP

func ConnectUDP(
	network, addr string,
	timeout time.Duration,
	opts ...sonicopts.Option,
) (fd int, localAddr, remoteAddr net.Addr, err error)

func CreateSocketTCP

func CreateSocketTCP(
	network, addr string,
	nonblocking bool,
) (fd int, tcpAddr *net.TCPAddr, err error)

func CreateSocketUDP

func CreateSocketUDP(network, addr string) (fd int, udpAddr *net.UDPAddr, err error)

func FromSockaddr

func FromSockaddr(sockAddr syscall.Sockaddr) net.Addr

func FromSockaddrUDP

func FromSockaddrUDP(sockAddr syscall.Sockaddr, to *net.UDPAddr) *net.UDPAddr

func IsNoDelay

func IsNoDelay(fd int) (bool, error)

func IsNonblocking

func IsNonblocking(fd int) (bool, error)

func Listen

func Listen(network, addr string, opts ...sonicopts.Option) (int, net.Addr, error)

func ListenUDP

func ListenUDP(network, addr string, opts ...sonicopts.Option) (int, net.Addr, error)

func Sockaddr

func Sockaddr(fd int) (syscall.Sockaddr, error)

func SocketAddress

func SocketAddress(fd int) (net.Addr, error)

func ToSockaddr

func ToSockaddr(addr net.Addr) syscall.Sockaddr

Types

type Event

type Event struct {
	Mask uint32
	Data [8]byte
}

type EventFd

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

func NewEventFd

func NewEventFd(nonBlocking bool) (*EventFd, error)

func (*EventFd) Close

func (e *EventFd) Close() error

func (*EventFd) Fd

func (e *EventFd) Fd() int

func (*EventFd) Read

func (e *EventFd) Read(b []byte) (int, error)

func (*EventFd) Slot

func (e *EventFd) Slot() *Slot

func (*EventFd) Write

func (e *EventFd) Write(x uint64) (int, error)

type EventType

type EventType int8
const (
	ReadEvent EventType = iota
	WriteEvent
	MaxEvent
)

type Handler

type Handler func(error)

type ITimer

type ITimer interface {
	Set(time.Duration, func()) error
	Unset() error
	Close() error
}

type Pipe

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

func NewPipe

func NewPipe() (*Pipe, error)

func (*Pipe) Close

func (p *Pipe) Close() error

func (*Pipe) Read

func (p *Pipe) Read(b []byte) (int, error)

func (*Pipe) ReadFd

func (p *Pipe) ReadFd() int

func (*Pipe) SetReadNonblock

func (p *Pipe) SetReadNonblock() error

func (*Pipe) SetWriteNonblock

func (p *Pipe) SetWriteNonblock() error

func (*Pipe) Slot

func (p *Pipe) Slot() *Slot

func (*Pipe) Write

func (p *Pipe) Write(b []byte) (int, error)

func (*Pipe) WriteFd

func (p *Pipe) WriteFd() int

type Poller

type Poller interface {
	// Poll polls the status of the underlying events registered with SetRead or SetWrite, returning if any events
	// occurred.
	//
	// A call to Poll will block until either:
	//  - an event occurs
	//  - the call is interrupted by a signal handler; or
	//  - the timeout expires
	Poll(timeoutMs int) (n int, err error)

	// Pending returns the number of registered events which have not yet occurred.
	Pending() int64

	// Post instructs the Poller to execute the provided handler in the Poller's goroutine in the next Poll call.
	//
	// Post is safe for concurrent use.
	Post(func()) error

	// Posted returns the number of handlers registered with Post.
	//
	// Posted is safe for concurrent use.
	Posted() int

	// SetRead registers interest in read events on the provided slot.
	SetRead(slot *Slot) error

	// SetWrite registers interest in write events on the provided slot.
	SetWrite(slot *Slot) error

	// DelRead deregisters interest in read events on the provided slot.
	DelRead(slot *Slot) error

	// DelWrite deregisters interest in write events on the provided slot.
	DelWrite(slot *Slot) error

	// Del deregisters interest in all events on the provided slot.
	Del(slot *Slot) error

	// Close closes the Poller. No calls to Poll should be made after Close.
	//
	// Close is safe for concurrent use.
	Close() error

	// Closed returns true if the Poller has been closed.
	//
	// Closed is safe for concurrent use.
	Closed() bool
}

func NewPoller

func NewPoller() (Poller, error)

type PollerEvent

type PollerEvent uint32

type Slot

type Slot struct {
	Fd int // A file descriptor which uniquely identifies a Slot. Callers must set it up at construction time.

	// Events registered with this Slot. Essentially a bitmask. It can contain a read event, a write event, or both.
	// Every event from here has a corresponding Handler in Handlers.
	//
	// Defined by Poller, which is platform-specific. Since this is a bitmask, the Poller guarantees that each
	// platform-specific event is a power of two.
	Events PollerEvent

	// Callbacks registered with this Slot. The poller dispatches the appropriate read or write callback when it
	// receives an event that's in Events.
	Handlers [MaxEvent]Handler
}

func (*Slot) Set

func (s *Slot) Set(et EventType, h Handler)

type Timer

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

func NewTimer

func NewTimer(p Poller) (*Timer, error)

func (*Timer) Close

func (t *Timer) Close() error

func (*Timer) Set

func (t *Timer) Set(dur time.Duration, cb func()) error

func (*Timer) Unset

func (t *Timer) Unset() error

Jump to

Keyboard shortcuts

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