Documentation
¶
Index ¶
- Constants
- Variables
- func GetMsgBelongToControllerIdx(msgIndex int) int
- func GetMsgByIdx(msgIndex int) interface{}
- func GetMsgIdxByType(t reflect.Type) int
- func RegisterMsg(msgIndex, controllerIndex int, msg interface{})
- func RegisterPeer(peer Peer)
- func SubmitMsgToAntsPool(c MsgController, s Session, msg interface{})
- type MsgController
- type MsgControllers
- type Option
- func WithAddr(addr string) Option
- func WithOptions(options Options) Option
- func WithPanicHandler(panicHandler func(interface{})) Option
- func WithPeerType(peerType PeerType) Option
- func WithReadDeadline(dur time.Duration) Option
- func WithRoutinePoolSize(size int) Option
- func WithWriteDeadline(dur time.Duration) Option
- type Options
- type Peer
- type PeerIdentify
- type PeerType
- type Ping
- type Pong
- type ProtoCol
- type Session
- type SessionClose
- type SessionConnect
- type SessionIdentify
- type SystemMsgController
Constants ¶
View Source
const ( //无效会话id INVALID_SESSION_ID uint32 = 0 )
View Source
const (
POOL_DEFAULT_SIZE = 1
)
View Source
const SYSTEM_CONTROLLER_IDX = 0
Variables ¶
View Source
var Opts = &Options{}
View Source
var (
SessionManager = newSessionManager()
)
Functions ¶
func GetMsgByIdx ¶
func GetMsgByIdx(msgIndex int) interface{}
func GetMsgIdxByType ¶
func RegisterPeer ¶
func RegisterPeer(peer Peer)
func SubmitMsgToAntsPool ¶
func SubmitMsgToAntsPool(c MsgController, s Session, msg interface{})
提交到协程池处理消息
Types ¶
type MsgController ¶ added in v1.0.2
type MsgController interface {
//消息处理接口
ProcessMsg(session Session, msg interface{})
}
控制器
type MsgControllers ¶ added in v1.0.2
type MsgControllers struct {
// contains filtered or unexported fields
}
func (*MsgControllers) AddController ¶ added in v1.0.2
func (s *MsgControllers) AddController(index int, c MsgController)
func (*MsgControllers) GetController ¶ added in v1.0.2
func (s *MsgControllers) GetController(index int) (MsgController, error)
type Option ¶
type Option func(opts *Options)
Option represents the optional function.
func WithOptions ¶
WithOptions accepts the whole options config.
func WithPanicHandler ¶
func WithPanicHandler(panicHandler func(interface{})) Option
WithPanicHandler sets up panic handler.
type Options ¶
type Options struct {
//listen or dial addr
Addr string
//peer type
PeerType PeerType
//SetWriteDeadline sets the write deadline or read deadline on the underlying connection.
ReadDeadline, WriteDeadline time.Duration
//set the routine pool size
//0.mean use default set
PoolSize int
// PanicHandler is used to handle panics from each worker goroutine.
PanicHandler func(interface{})
}
type PeerIdentify ¶
type PeerIdentify struct {
// contains filtered or unexported fields
}
端属性
func (*PeerIdentify) Addr ¶
func (p *PeerIdentify) Addr() string
func (*PeerIdentify) SetAddr ¶
func (p *PeerIdentify) SetAddr(addr string)
func (*PeerIdentify) SetType ¶
func (p *PeerIdentify) SetType(t PeerType)
func (*PeerIdentify) Type ¶
func (p *PeerIdentify) Type() PeerType
type Session ¶
type Session interface {
//原始套接字
Socket() interface{}
// 发送消息,消息需要以指针格式传入
Send(msg interface{})
// 断开
Close()
// ID
ID() uint32
//数据存储
Value(v ...interface{}) interface{}
}
会话
type SessionClose ¶
type SessionClose struct {
}
type SessionIdentify ¶
type SessionIdentify struct {
// contains filtered or unexported fields
}
核心会话标志
func (*SessionIdentify) ID ¶
func (s *SessionIdentify) ID() uint32
func (*SessionIdentify) SetID ¶
func (s *SessionIdentify) SetID(id uint32)
type SystemMsgController ¶ added in v1.0.2
type SystemMsgController struct {
}
系统控制模块
func (*SystemMsgController) ProcessMsg ¶ added in v1.0.2
func (*SystemMsgController) ProcessMsg(session Session, msg interface{})
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
demo
|
|
|
tcp/client
command
|
|
|
tcp/server
command
|
|
|
udp/client
command
|
|
|
udp/server
command
|
|
|
ws/client
command
|
|
|
ws/server
command
|
|
|
peer
|
|
Click to show internal directories.
Click to hide internal directories.

