backup

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AE_NONE     = 0x0000 /* No events registered. */
	AE_ERROR    = 0x0008
	AE_ADD      = 0x1000 // 添加事件
	AE_DEL      = 0x2000 // 删除事件
	AE_READABLE = 0x0001 /* Fire when descriptor is readable. */
	AE_WRITABLE = 0x0002 /* Fire when descriptor is writable. */
	AE_BARRIER  = 0x0004 /* With WRITABLE, never fire the event if the
	   READABLE event already fired in the same event
	   loop iteration. Useful when you want to persist
	   things to disk before sending replies, and want
	   to do that in a group fashion. */
)
View Source
const (
	INVALID = socket_t(-1)

	ERROR     = syscall.Errno(__errno_base + 1)
	EAGAIN    = syscall.Errno(__errno_base + 2)
	EBUSY     = syscall.Errno(__errno_base + 3)
	EDONE     = syscall.Errno(__errno_base + 4)
	EDECLINED = syscall.Errno(__errno_base + 5)
	EABORT    = syscall.Errno(__errno_base + 6)
	EOF       = syscall.Errno(__errno_base + 7)
	EBADF     = syscall.Errno(__errno_base + 8)
)

Variables

View Source
var (
	// 无效的socket
	SOCKET_INVALID = -1
	// 超时30秒
	SOCKET_TIMEOUT int64 = 30
)
View Source
var (
	SO_REUSEPORT = 0x0F
)
View Source
var (
	SUCCESS error = nil
)

Functions

func Accept

func Accept(fd socket_t) (socket_t, syscall.Sockaddr, error)

Accept 在non-blocking模式下, 如果返回值为-1, 且errno == EAGAIN或errno == EWOULDBLOCK表示no connections没有新连接请求

func CheckoutTimeout

func CheckoutTimeout(fd socket_t, deadline time.Time) error

func Close

func Close(fd socket_t) error

func CloseEx

func CloseEx(fd socket_t) error

func Connect

func Connect(fd socket_t, addr string) error

在non-bloking模式下, 如果返回-1, 且errno = EINPROGRESS表示正在连接

func CreateEngine

func CreateEngine(numLoops int, engineHandler EngineHandler) (*engine, error)

func DefaultAccept

func DefaultAccept(loop *EventLoop, ev *Event) error

func DefaultClose

func DefaultClose(loop *EventLoop, ev *Event) error

func DefaultRead

func DefaultRead(loop *EventLoop, ev *Event) error

func DefaultWrite

func DefaultWrite(loop *EventLoop, ev *Event) error

func FD_SET

func FD_SET(fd uintptr, p *syscall.FdSet)

func FD_VALID

func FD_VALID(fd int) bool

func Listen

func Listen(addr string) (socket_t, error)

func ParseAddr

func ParseAddr(addr string) (network, address string)

func Recv

func Recv(fd socket_t, data []byte) (int, error)

在non-blocking模式下, 如果返回值为-1, 且errno == EAGAIN表示没有可接受的数据或很在接受尚未完成

func STATUS_IS_SUCCESS

func STATUS_IS_SUCCESS(err error) bool

func Select

func Select(nfd int, r *syscall.FdSet, w *syscall.FdSet, e *syscall.FdSet, timeout *syscall.Timeval) (n int, err error)

func Send

func Send(fd socket_t, data []byte) (int, error)

func SendTimeout

func SendTimeout(fd socket_t, data []byte, deadline time.Time) (int, error)

func Setsockopt

func Setsockopt(fd socket_t) error

func SetsockoptLinger

func SetsockoptLinger(fd socket_t, ttl int32)

func Socket

func Socket() (socket_t, error)

func StartListen

func StartListen(numLoops int, handler DataHandler)

启动一个server

Types

type Callback

type Callback struct {
	Owner     interface{}
	OnAccept  DataHandler
	OnConnect DataHandler
	Opened    func(addr syscall.Sockaddr)
	OnRead    func(cb *Callback, packet []byte) error
	OnWrite   func(ev *Callback) ([]byte, error)
	OnTimeout DataHandler
	Closed    DataHandler
}

type DataHandler

type DataHandler func(cb *Callback) error

type Engine

type Engine struct {
	AfterEvent EventHandler
}

type EngineHandler

type EngineHandler func(loop *EventLoop) bool

type Event

type Event struct {
	Fd   socket_t
	Addr syscall.Sockaddr

	Out      []byte // write buffer
	Context  interface{}
	Accept   EventHandler
	Connect  EventHandler
	Read     EventHandler
	Write    EventHandler
	Timeout  EventHandler
	Close    EventHandler
	NumLoops int
	// contains filtered or unexported fields
}

type EventHandler

type EventHandler func(loop *EventLoop, ev *Event) error

type EventLoop

type EventLoop struct {
	Index int

	Packet  []byte
	WaitFor EngineHandler
	// contains filtered or unexported fields
}

func NewLoop

func NewLoop(index int) (*EventLoop, error)

func (*EventLoop) CloseSocket

func (loop *EventLoop) CloseSocket(ev *Event)

func (*EventLoop) Detach

func (loop *EventLoop) Detach(ev *Event)

func (*EventLoop) GetEvent

func (loop *EventLoop) GetEvent(fd socket_t) *Event

func (*EventLoop) GetPoll

func (loop *EventLoop) GetPoll() *Poll

func (*EventLoop) StartLoop

func (loop *EventLoop) StartLoop() error

func (*EventLoop) Watch

func (loop *EventLoop) Watch(event *Event, mask int) error

type InputStream

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

InputStream is a helper type for managing input streams from inside the Data event.

func (*InputStream) Begin

func (is *InputStream) Begin(packet []byte) (data []byte)

Begin accepts a new packet and returns a working sequence of unprocessed bytes.

func (*InputStream) End

func (is *InputStream) End(data []byte)

End shifts the stream to match the unprocessed data.

type LoadBalance

type LoadBalance int

LoadBalance sets the load balancing method.

const (
	// Random requests that connections are randomly distributed.
	Random LoadBalance = iota
	// RoundRobin requests that connections are distributed to a loop in a
	// round-robin fashion.
	RoundRobin
	// LeastConnections assigns the next accepted connection to the loop with
	// the least number of active connections.
	LeastConnections
)

type Poll

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

Poll ...

func OpenPoll

func OpenPoll(index int) (*Poll, error)

func (*Poll) Close

func (p *Poll) Close() error

Close ...

func (*Poll) Modify

func (poll *Poll) Modify(ev *Event, mask int) error

func (*Poll) Trigger

func (p *Poll) Trigger(note interface{}) error

Trigger ...

func (*Poll) Wait

func (p *Poll) Wait(changes map[int]*Event, events []*Event, timeout time.Duration) (n int, err error)

Wait ...

type Poller

type Poller interface {
	//Add(event *Event, mask int) error
	Modify(event *Event, mask int) error
	//Del(event *Event, mask int) error
	Wait(changes map[int]*Event, evs []*Event, timeout time.Duration) (n int, err error)
	Close() error
}

type Status

type Status int

type TcpSocket

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

Directories

Path Synopsis
examples
v1 command
v2 command
v3 command
v4 command
v5 command
v6 command
v7 command
v8 command

Jump to

Keyboard shortcuts

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