Documentation
¶
Index ¶
- Constants
- type BaseConn
- type BaseContext
- type BaseSession
- type Conn
- type Context
- type EmptyListener
- func (listener *EmptyListener) OnClosed(session Session)
- func (listener *EmptyListener) OnOpened(session Session)
- func (listener *EmptyListener) OnReceive(session Session, msg any, msgLen int) (err error)
- func (listener *EmptyListener) OnReceiveMulti(session Session, msg []any, totalLen int) (err error)
- func (listener *EmptyListener) OnSend(session Session, msg any, msgLen int) (err error)
- func (listener *EmptyListener) OnSendMulti(session Session, msg []any, totalLen int) (err error)
- type Listener
- type Manager
- type Session
- type Writer
Constants ¶
View Source
const (
InvalidSessionId = 0
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseContext ¶
type BaseContext struct {
// contains filtered or unexported fields
}
func (*BaseContext) Deadline ¶
func (ctx *BaseContext) Deadline() int64
func (*BaseContext) Id ¶
func (ctx *BaseContext) Id() uint64
func (*BaseContext) Init ¶
func (ctx *BaseContext) Init(id uint64)
func (*BaseContext) SetDeadline ¶
func (ctx *BaseContext) SetDeadline(deadline int64)
type BaseSession ¶
type BaseSession struct {
// contains filtered or unexported fields
}
func (*BaseSession) Context ¶
func (sess *BaseSession) Context() Context
func (*BaseSession) Id ¶
func (sess *BaseSession) Id() uint64
func (*BaseSession) Register ¶
func (sess *BaseSession) Register(context Context) error
type Conn ¶
type Conn interface { net.Conn gnet.Reader Writer // Hash // @Description: get conn hash code // @return uint64 // Hash() uint64 // Context returns a user-defined context, it's not goroutine-safe, // you must invoke it within any method in EventHandler. Context() (ctx any) // SetContext sets a user-defined context, it's not goroutine-safe, // you must invoke it within any method in EventHandler. SetContext(ctx any) // IsClosed // @Description: get connection status and closed reason // @return bool closed or not // @return error closed reason // IsClosed() (bool, error) }
Conn
@Description: connection
type EmptyListener ¶
type EmptyListener struct { }
EmptyListener 空处理的会话监听器
func (*EmptyListener) OnClosed ¶
func (listener *EmptyListener) OnClosed(session Session)
func (*EmptyListener) OnOpened ¶
func (listener *EmptyListener) OnOpened(session Session)
func (*EmptyListener) OnReceive ¶
func (listener *EmptyListener) OnReceive(session Session, msg any, msgLen int) (err error)
func (*EmptyListener) OnReceiveMulti ¶
func (listener *EmptyListener) OnReceiveMulti(session Session, msg []any, totalLen int) (err error)
func (*EmptyListener) OnSend ¶
func (listener *EmptyListener) OnSend(session Session, msg any, msgLen int) (err error)
func (*EmptyListener) OnSendMulti ¶
func (listener *EmptyListener) OnSendMulti(session Session, msg []any, totalLen int) (err error)
type Listener ¶
type Listener interface { // OnOpened // @Description: 当会话开启 // @param session // OnOpened(session Session) // OnClosed // @Description: 当会话关闭 // @param session // OnClosed(session Session) // OnReceive // @Description: 成功接收消息 // @param session // @param msg 接收的消息体 // @param msgLen 消息长度 // @return err // OnReceive(session Session, msg any, msgLen int) (err error) // OnReceiveMulti // @Description: 成功接收消息 // @param session // @param msg 接收的消息体 // @param totalLen 消息长度 // @return err // OnReceiveMulti(session Session, msg []any, totalLen int) (err error) // OnSend // @Description: 成功发送消息 // @param session // @param msg 要发送的消息体 // @param msgLen 消息长度 // @return err // OnSend(session Session, msg any, msgLen int) (err error) // OnSendMulti // @Description: 成功发送消息 // @param session // @param msg 要发送的消息体 // @param totalLen 消息长度 // @return out 经过处理传出的消息体 // @return err // OnSendMulti(session Session, msg []any, totalLen int) (err error) }
Listener
@Description: 会话监听器
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) AddSession ¶
AddSession
@Description: 添加未注册的会话 @receiver manager @param Session 会话 @return error
func (*Manager) CheckSessions ¶
func (manager *Manager) CheckSessions()
CheckSessions
@Description: 检查会话的有效性 @receiver manager
func (*Manager) GetSession ¶
GetSession
@Description: 获取会话 @receiver manager @param sessionId @return Session
func (*Manager) RegisterSession ¶
RegisterSession
@Description: 注册会话 @receiver manager @param Session 会话 @return error
type Session ¶
type Session interface { // Id // @Description: 会话编号,仅关联后的会话有合法的id值,否则都返回 InvalidSessionId // @return ID 非nil值 // Id() uint64 // Context // @Description: 返回当前关联的业务对象 // @return Context // Context() Context // Register // @Description: 注册会话 // @param context // @return error // Register(context Context) error // Connection // @Description: 连接 // @return Conn // Connection() Conn // Close // @Description: 关闭会话 // @return error // Close() error // IsClosed // @Description: 是否已关闭 // @return bool // IsClosed() bool // SendMessage // @Description: 发送消息 // @param message // SendMessage(message any) // SendMessages // @Description: 发送消息 // @param messages // SendMessages(messages ...any) // contains filtered or unexported methods }
Session
@Description: 连接会话
type Writer ¶
type Writer interface { io.Writer // not goroutine-safe io.ReaderFrom // not goroutine-safe // Writev writes multiple byte slices to peer synchronously, it's not goroutine-safe, // you must invoke it within any method in EventHandler. Writev(bs [][]byte) (n int, err error) // Flush writes any buffered data to the underlying connection, it's not goroutine-safe, // you must invoke it within any method in EventHandler. Flush() (err error) // OutboundBuffered returns the number of bytes that can be read from the current buffer. // it's not goroutine-safe, you must invoke it within any method in EventHandler. OutboundBuffered() (n int) // AsyncWrite writes bytes to peer asynchronously, it's goroutine-safe, // you don't have to invoke it within any method in EventHandler, // usually you would call it in an individual goroutine. // // Note that it will go synchronously with UDP, so it is needless to call // this asynchronous method, we may disable this method for UDP and just // return ErrUnsupportedOp in the future, therefore, please don't rely on // this method to do something important under UDP, if you're working with UDP, // just call Conn.Write to send back your data. AsyncWrite(buf []byte, callback func(c Conn, err error) error) (err error) // AsyncWritev writes multiple byte slices to peer asynchronously, // you don't have to invoke it within any method in EventHandler, // usually you would call it in an individual goroutine. AsyncWritev(bs [][]byte, callback func(c Conn, err error) error) (err error) }
Click to show internal directories.
Click to hide internal directories.