Documentation ¶
Index ¶
- Constants
- Variables
- func Intn(a int) int
- type CallbackWsPath
- type Hub
- func (self *Hub) Callback() ISessionCallback
- func (self *Hub) ChQuit() <-chan struct{}
- func (self *Hub) Conf() *HubConfig
- func (self *Hub) DelSession(id uint64) error
- func (self *Hub) GetAllSessions() map[uint64]ISession
- func (self *Hub) GetSession(id uint64) (ISession, error)
- func (self *Hub) GetSessionNum() int
- func (self *Hub) PeekSession(id uint64) (ISession, error)
- func (self *Hub) Protocol() IProtocol
- func (self *Hub) PutSession(id uint64, ses ISession) error
- func (self *Hub) RandSession() (ISession, error)
- func (self *Hub) Wg() *sync.WaitGroup
- type HubConfig
- type IConn
- type IHandler
- type IHub
- type IMiddleware
- type IPacket
- type IProtocol
- type ISession
- type ISessionCallback
- type Packet
- type Protocol
- type Session
- func (self *Session) AWrite(pkt IPacket, timeout time.Duration) (err error)
- func (self *Session) Close(reason int32)
- func (self *Session) Do()
- func (self *Session) GetData() interface{}
- func (self *Session) GetRawConn() IConn
- func (self *Session) Id() uint64
- func (self *Session) IsClosed() bool
- func (self *Session) SetData(data interface{})
- func (self *Session) SetId(id uint64)
- func (self *Session) UpdateId(id uint64)
- func (self *Session) Write(pkt IPacket, timeout time.Duration) error
- type TCPClient
- type TcpConn
- type TcpServer
- type WsClient
- type WsConn
- type WsServer
Constants ¶
View Source
const ( // Close Reason 是一个 int32 型数据,这是系统预置的几个代码 CLOSE_REASON_READ = 0 CLOSE_REASON_WRITE = 0 CLOSE_REASON_PROTOCOL = 1 CLOSE_REASON_READTIMEOUT = 4 // HEARTBEAT CLOSE_REASON_SERVER_CLOSED = 16 // 本服务器关闭 )
关闭原因
Variables ¶
View Source
var ( ErrExistsAlready = errors.New("item already exists") ErrNotExists = errors.New("item not exists") ErrConnectionReject = errors.New("connection rejected by logic") ErrConnClosing = errors.New("use of closed network connection") ErrWriteBlocking = errors.New("write packet was blocking") ErrReadBlocking = errors.New("read packet was blocking") ErrEmptySlice = errors.New("the slice is empty") ErrSliceOutOfRange = errors.New("the slice is out of range") ErrBufferSizeInsufficient = errors.New("buffer size is too small") ErrInterface = errors.New("interface convertion failed") )
Functions ¶
Types ¶
type CallbackWsPath ¶
type CallbackWsPath func(http.ResponseWriter, *http.Request)
type Hub ¶
func (*Hub) Callback ¶
func (self *Hub) Callback() ISessionCallback
type HubConfig ¶
type IConn ¶
type IHub ¶
type IHub interface { Lock() // support locker semantics Unlock() Wg() *sync.WaitGroup // object ChQuit() <-chan struct{} // 返回一个通道,用于退出 hub 循环 Conf() *HubConfig // 返回配置信息 Callback() ISessionCallback // 返回回调对象 Protocol() IProtocol // 返回数据协议 Start() error // 启动 hub Stop() error // 停止 hub DoJob(int) // 执行 hub 中其他任务 PutSession(uint64, ISession) error // session 管理,这里的 session 必须基于 id DelSession(uint64) error GetSession(uint64) (ISession, error) PeekSession(uint64) (ISession, error) RandSession() (ISession, error) GetSessionNum() int GetAllSessions() map[uint64]ISession }
type IMiddleware ¶
type IPacket ¶
type IProtocol ¶
type ISession ¶
type ISessionCallback ¶
type Packet ¶
type Packet struct {
// contains filtered or unexported fields
}
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
长连接
func (*Session) AWrite ¶
public 异步写入
type TCPClient ¶
type TCPClient struct { *Hub // contains filtered or unexported fields }
type TcpServer ¶
type TcpServer struct { *Hub // contains filtered or unexported fields }
func NewTcpServer ¶
func NewTcpServer(cf *HubConfig, cb ISessionCallback, p IProtocol, ls *net.TCPListener) *TcpServer
type WsClient ¶
type WsClient struct { *Hub // contains filtered or unexported fields }
客户端组
type WsConn ¶
Click to show internal directories.
Click to hide internal directories.