Documentation
¶
Index ¶
- Constants
- Variables
- func Accept(fd socket_t) (socket_t, syscall.Sockaddr, error)
- func CheckoutTimeout(fd socket_t, deadline time.Time) error
- func Close(fd socket_t) error
- func CloseEx(fd socket_t) error
- func Connect(fd socket_t, addr string) error
- func CreateEngine(numLoops int, engineHandler EngineHandler) (*engine, error)
- func DefaultAccept(loop *EventLoop, ev *Event) error
- func DefaultClose(loop *EventLoop, ev *Event) error
- func DefaultRead(loop *EventLoop, ev *Event) error
- func DefaultWrite(loop *EventLoop, ev *Event) error
- func FD_SET(fd uintptr, p *syscall.FdSet)
- func FD_VALID(fd int) bool
- func Listen(addr string) (socket_t, error)
- func ParseAddr(addr string) (network, address string)
- func Recv(fd socket_t, data []byte) (int, error)
- func STATUS_IS_SUCCESS(err error) bool
- func Select(nfd int, r *syscall.FdSet, w *syscall.FdSet, e *syscall.FdSet, ...) (n int, err error)
- func Send(fd socket_t, data []byte) (int, error)
- func SendTimeout(fd socket_t, data []byte, deadline time.Time) (int, error)
- func Setsockopt(fd socket_t) error
- func SetsockoptLinger(fd socket_t, ttl int32)
- func Socket() (socket_t, error)
- func StartListen(numLoops int, handler DataHandler)
- type Callback
- type DataHandler
- type Engine
- type EngineHandler
- type Event
- type EventHandler
- type EventLoop
- type InputStream
- type LoadBalance
- type Poll
- type Poller
- type Status
- type TcpSocket
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 ¶
Accept 在non-blocking模式下, 如果返回值为-1, 且errno == EAGAIN或errno == EWOULDBLOCK表示no connections没有新连接请求
func CheckoutTimeout ¶
func CreateEngine ¶
func CreateEngine(numLoops int, engineHandler EngineHandler) (*engine, error)
func DefaultAccept ¶
func DefaultClose ¶
func DefaultRead ¶
func DefaultWrite ¶
func STATUS_IS_SUCCESS ¶
func Setsockopt ¶
func Setsockopt(fd socket_t) error
func SetsockoptLinger ¶
func SetsockoptLinger(fd socket_t, ttl int32)
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 Engine ¶
type Engine struct {
AfterEvent EventHandler
}
type EngineHandler ¶
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 EventLoop ¶
type EventLoop struct {
Index int
Packet []byte
WaitFor EngineHandler
// contains filtered or unexported fields
}
func (*EventLoop) CloseSocket ¶
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 )
Source Files
¶
Click to show internal directories.
Click to hide internal directories.