Documentation ¶
Index ¶
- Constants
- Variables
- func GetLogger() logger
- func NewHeaderLenEncoder(headerLen, writeBufferLen int) *headerLenEncoder
- func SetLogger(l logger)
- func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- type Buffer
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) CloseRead() error
- func (c *Conn) GetAddr() string
- func (c *Conn) GetBuffer() *Buffer
- func (c *Conn) GetData() interface{}
- func (c *Conn) GetFd() int32
- func (c *Conn) Read() error
- func (c *Conn) SetData(data interface{})
- func (c *Conn) Write(bytes []byte) (int, error)
- type Decoder
- type Encoder
- type Handler
- type Option
- type Server
Constants ¶
View Source
const ( EpollRead = syscall.EPOLLIN | syscall.EPOLLPRI | syscall.EPOLLERR | syscall.EPOLLHUP | unix.EPOLLET | syscall.EPOLLRDHUP EpollClose = uint32(syscall.EPOLLIN | syscall.EPOLLRDHUP) )
对端关闭连接 8193
View Source
const ( EventIn = 1 // 数据流入 EventClose = 2 // 断开连接 EventTimeout = 3 // 检测到超时 )
Variables ¶
View Source
var ErrNotEnough = errors.New("not enough")
View Source
var (
ErrReadTimeout = errors.New("tcp read timeout")
)
Functions ¶
func NewHeaderLenEncoder ¶
func NewHeaderLenEncoder(headerLen, writeBufferLen int) *headerLenEncoder
NewHeaderLenEncoder 创建基于头部长度的编码器 headerLen TCP包的头部内容,用来描述这个包的字节长度 writeBufferLen 服务器发送给客户端包的建议长度,当发送的包小于这个值时,会利用到内存池优化
func TimeEncoder ¶
func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer 读缓冲区,每个tcp长连接对应一个读缓冲区
func (*Buffer) ReadFromReader ¶
ReadFromReader 从reader里面读取数据,如果reader阻塞,会发生阻塞
type Decoder ¶
Decoder 解码器
func NewHeaderLenDecoder ¶
NewHeaderLenDecoder 创建基于头部长度的解码器 headerLen TCP包的头部内容,用来描述这个包的字节长度 readMaxLen 所读取的客户端包的最大长度,客户端发送的包不能超过这个长度
type Handler ¶
type Handler interface { OnConnect(c *Conn) // OnConnect 当TCP长连接建立成功是回调 OnMessage(c *Conn, bytes []byte) // OnMessage 当客户端有数据写入是回调 OnClose(c *Conn, err error) // OnClose 当客户端主动断开链接或者超时时回调,err返回关闭的原因 }
Handler Server 注册接口
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithIOEventQueueLen ¶
WithIOEventQueueLen 设置IO事件队列长度,默认值是1024
func WithTimeout ¶
WithTimeout 设置TCP超时检查的间隔时间以及超时时间
Source Files ¶
Click to show internal directories.
Click to hide internal directories.