Documentation ¶
Index ¶
- Variables
- func DetectPort(addr string, fn func(a *Address, port int) (interface{}, error)) (interface{}, error)
- func GetLocalIP() string
- func GetPrivateIPv4() ([]*net.IPAddr, error)
- func GetPublicIPv6() ([]*net.IPAddr, error)
- func GetRemoteAddress(ses Session) (string, bool)
- func JoinAddress(host string, port int) string
- func NewSessionManager() *sessionManager
- func QueuedCall(queue EventQueue, callback func())
- func RecvLTVPacket(reader io.Reader, maxPacketSize int) (msg interface{}, err error)
- func SendLTVPacket(writer io.Writer, data interface{}) error
- func SessionQueuedCall(ses Session, callback func())
- func SpliteAddress(addr string) (host string, port int, err error)
- type Address
- type CapturePanicNotifyFunc
- type CloseReason
- type ContextSet
- type Event
- type EventCallback
- type EventHooker
- type EventQueue
- type MessageTransmitter
- type MultiHooker
- type Peer
- type PeerProp
- func (this *PeerProp) Address() string
- func (this *PeerProp) ApplySocketOption(conn net.Conn)
- func (this *PeerProp) ApplySocketReadTimeout(conn net.Conn, callback func())
- func (this *PeerProp) ApplySocketWriteTimeout(conn net.Conn, callback func())
- func (this *PeerProp) EndStopping()
- func (this *PeerProp) GetProp() *PeerProp
- func (this *PeerProp) Init()
- func (this *PeerProp) IsRunning() bool
- func (this *PeerProp) IsStopping() bool
- func (self *PeerProp) MaxPacketSize() int
- func (this *PeerProp) Name() string
- func (this *PeerProp) ProcEvent(ev Event)
- func (this *PeerProp) Queue() EventQueue
- func (this *PeerProp) ReadMessage(ses Session) (msg interface{}, err error)
- func (this *PeerProp) SendMessage(ev Event)
- func (this *PeerProp) SetAddress(v string)
- func (this *PeerProp) SetCallback(v EventCallback)
- func (this *PeerProp) SetHooker(v EventHooker)
- func (self *PeerProp) SetMaxPacketSize(maxSize int)
- func (this *PeerProp) SetName(v string)
- func (this *PeerProp) SetQueue(v EventQueue)
- func (this *PeerProp) SetRunning(v bool)
- func (this *PeerProp) SetSocketBuffer(readBufferSize, writeBufferSize int, noDelay bool)
- func (self *PeerProp) SetSocketDeadline(read, write time.Duration)
- func (this *PeerProp) SetTransmitter(v MessageTransmitter)
- func (this *PeerProp) StartStopping()
- func (this *PeerProp) WaitStopFinished()
- type Pipe
- type ProcessorBundle
- type RecvMsgEvent
- type RemoteAddr
- type ReplyEvent
- type SendMsgEvent
- type Session
- type SessionAccepted
- type SessionCloseNotify
- type SessionClosed
- type SessionConnectError
- type SessionConnected
- type SessionInit
- type SessionManager
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrMaxPacket = errors.New("packet over size") ErrMinPacket = errors.New("packet short size") ErrShortPacket = errors.New("packet short length") ErrShortMsgId = errors.New("short msgid") )
View Source
var (
ErrInvalidPortRange = errors.New("invalid port range")
)
Functions ¶
func DetectPort ¶
func GetLocalIP ¶
func GetLocalIP() string
func GetPrivateIPv4 ¶
func GetPublicIPv6 ¶
func GetRemoteAddress ¶
func JoinAddress ¶
func NewSessionManager ¶
func NewSessionManager() *sessionManager
func RecvLTVPacket ¶
func SendLTVPacket ¶
func SessionQueuedCall ¶
func SessionQueuedCall(ses Session, callback func())
在会话对应的Peer上的事件队列中执行callback,如果没有队列,则马上执行
Types ¶
type CapturePanicNotifyFunc ¶
type CapturePanicNotifyFunc func(interface{}, EventQueue)
type CloseReason ¶
type CloseReason int32
const ( CloseReason_IO CloseReason = iota CloseReason_Manual )
func (CloseReason) String ¶
func (this CloseReason) String() string
type ContextSet ¶
type ContextSet struct {
// contains filtered or unexported fields
}
func (*ContextSet) FetchContext ¶
func (this *ContextSet) FetchContext(key, valuePtr interface{}) bool
func (*ContextSet) GetContext ¶
func (self *ContextSet) GetContext(key interface{}) (interface{}, bool)
func (*ContextSet) SetContext ¶
func (self *ContextSet) SetContext(key, v interface{})
type EventCallback ¶
type EventCallback func(ev Event)
func NewQueuedEventCallback ¶
func NewQueuedEventCallback(callback EventCallback) EventCallback
让EventCallback保证放在ses的队列里,而不是并发的
type EventHooker ¶
type EventHooker interface { OnInboundEvent(input Event) (output Event) OnOutboundEvent(input Event) (output Event) }
func NewMultiHooker ¶
func NewMultiHooker(h ...EventHooker) EventHooker
type EventQueue ¶
type EventQueue interface { StartLoop() EventQueue StopLoop() EventQueue Wait() Post(callback func()) EnableCapturePanic(v bool) }
type MessageTransmitter ¶
type MultiHooker ¶
type MultiHooker []EventHooker
当需要多个Hooker时,使用NewMultiHooker将多个hooker合并成1个hooker处理
func (MultiHooker) OnInboundEvent ¶
func (self MultiHooker) OnInboundEvent(input Event) (output Event)
func (MultiHooker) OnOutboundEvent ¶
func (self MultiHooker) OnOutboundEvent(input Event) (output Event)
type Peer ¶
type Peer interface { Start() Stop() TypeName() string Name() string Address() string Queue() EventQueue SetName(v string) SetAddress(v string) SetQueue(v EventQueue) Prop() *PeerProp }
type PeerProp ¶
type PeerProp struct {
// contains filtered or unexported fields
}
func NewPeerProp ¶
func NewPeerProp() *PeerProp
func (*PeerProp) ApplySocketOption ¶
func (*PeerProp) ApplySocketReadTimeout ¶
func (*PeerProp) ApplySocketWriteTimeout ¶
func (*PeerProp) EndStopping ¶
func (this *PeerProp) EndStopping()
func (*PeerProp) IsStopping ¶
func (*PeerProp) MaxPacketSize ¶
func (*PeerProp) Queue ¶
func (this *PeerProp) Queue() EventQueue
func (*PeerProp) ReadMessage ¶
func (*PeerProp) SendMessage ¶
func (*PeerProp) SetAddress ¶
func (*PeerProp) SetCallback ¶
func (this *PeerProp) SetCallback(v EventCallback)
func (*PeerProp) SetHooker ¶
func (this *PeerProp) SetHooker(v EventHooker)
func (*PeerProp) SetMaxPacketSize ¶
func (*PeerProp) SetQueue ¶
func (this *PeerProp) SetQueue(v EventQueue)
func (*PeerProp) SetRunning ¶
func (*PeerProp) SetSocketBuffer ¶
func (*PeerProp) SetSocketDeadline ¶
func (*PeerProp) SetTransmitter ¶
func (this *PeerProp) SetTransmitter(v MessageTransmitter)
func (*PeerProp) StartStopping ¶
func (this *PeerProp) StartStopping()
func (*PeerProp) WaitStopFinished ¶
func (this *PeerProp) WaitStopFinished()
type ProcessorBundle ¶
type ProcessorBundle interface { SetTransmitter(v MessageTransmitter) SetHooker(v EventHooker) SetCallback(v EventCallback) }
type RecvMsgEvent ¶
type RecvMsgEvent struct { Ses Session Msg interface{} }
接收到消息
func (*RecvMsgEvent) Message ¶
func (self *RecvMsgEvent) Message() interface{}
func (*RecvMsgEvent) Send ¶
func (self *RecvMsgEvent) Send(msg interface{})
func (*RecvMsgEvent) Session ¶
func (self *RecvMsgEvent) Session() Session
type RemoteAddr ¶
type SendMsgEvent ¶
type SendMsgEvent struct { Ses Session Msg interface{} // 用户需要发送的消息 }
会话开始发送数据事件
func (*SendMsgEvent) Message ¶
func (self *SendMsgEvent) Message() interface{}
func (*SendMsgEvent) Session ¶
func (self *SendMsgEvent) Session() Session
type Session ¶
type Session interface { Raw() interface{} GetPeer() Peer Send(msg interface{}) Close() Id() int64 SetContext(key interface{}, v interface{}) GetContext(key interface{}) (interface{}, bool) FetchContext(key, valuePtr interface{}) bool }
长连接
type SessionAccepted ¶
type SessionAccepted struct { }
func (*SessionAccepted) String ¶
func (this *SessionAccepted) String() string
func (*SessionAccepted) SystemMessage ¶
func (this *SessionAccepted) SystemMessage()
type SessionCloseNotify ¶
type SessionCloseNotify struct { }
func (*SessionCloseNotify) String ¶
func (this *SessionCloseNotify) String() string
func (*SessionCloseNotify) SystemMessage ¶
func (this *SessionCloseNotify) SystemMessage()
type SessionClosed ¶
type SessionClosed struct {
Reason CloseReason
}
func (*SessionClosed) String ¶
func (this *SessionClosed) String() string
func (*SessionClosed) SystemMessage ¶
func (this *SessionClosed) SystemMessage()
type SessionConnectError ¶
type SessionConnectError struct { }
func (*SessionConnectError) String ¶
func (this *SessionConnectError) String() string
func (*SessionConnectError) SystemMessage ¶
func (this *SessionConnectError) SystemMessage()
type SessionConnected ¶
type SessionConnected struct { }
func (*SessionConnected) String ¶
func (this *SessionConnected) String() string
func (*SessionConnected) SystemMessage ¶
func (this *SessionConnected) SystemMessage()
type SessionInit ¶
type SessionInit struct { }
func (*SessionInit) String ¶
func (this *SessionInit) String() string
func (*SessionInit) SystemMessage ¶
func (this *SessionInit) SystemMessage()
Click to show internal directories.
Click to hide internal directories.