lib

package
v0.0.0-...-1c5b680 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

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 DetectPort(addr string, fn func(a *Address, port int) (interface{}, error)) (interface{}, error)

func GetLocalIP

func GetLocalIP() string

func GetPrivateIPv4

func GetPrivateIPv4() ([]*net.IPAddr, error)

func GetPublicIPv6

func GetPublicIPv6() ([]*net.IPAddr, error)

func GetRemoteAddress

func GetRemoteAddress(ses Session) (string, bool)

func JoinAddress

func JoinAddress(host string, port int) string

func NewSessionManager

func NewSessionManager() *sessionManager

func QueuedCall

func QueuedCall(queue EventQueue, callback func())

有队列时队列调用,无队列时直接调用

func RecvLTVPacket

func RecvLTVPacket(reader io.Reader, maxPacketSize int) (msg interface{}, err error)

func SendLTVPacket

func SendLTVPacket(writer io.Writer, data interface{}) error

func SessionQueuedCall

func SessionQueuedCall(ses Session, callback func())

在会话对应的Peer上的事件队列中执行callback,如果没有队列,则马上执行

func SpliteAddress

func SpliteAddress(addr string) (host string, port int, err error)

Types

type Address

type Address struct {
	Scheme  string
	Host    string
	MinPort int
	MaxPort int
	Path    string
}

func ParseAddress

func ParseAddress(addr string) (addrObj *Address, err error)

func (*Address) HostPortString

func (this *Address) HostPortString(port int) string

func (*Address) String

func (this *Address) String(port int) string

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 Event

type Event interface {
	Session() Session
	Message() 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)
}

func NewEventQueue

func NewEventQueue() EventQueue

创建默认长度的队列

type MessageTransmitter

type MessageTransmitter interface {
	OnRecvMessage(ses Session) (msg interface{}, err error)
	OnSendMessage(ses Session, msg interface{}) error
}

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) Address

func (this *PeerProp) Address() string

func (*PeerProp) ApplySocketOption

func (this *PeerProp) ApplySocketOption(conn net.Conn)

func (*PeerProp) ApplySocketReadTimeout

func (this *PeerProp) ApplySocketReadTimeout(conn net.Conn, callback func())

func (*PeerProp) ApplySocketWriteTimeout

func (this *PeerProp) ApplySocketWriteTimeout(conn net.Conn, callback func())

func (*PeerProp) EndStopping

func (this *PeerProp) EndStopping()

func (*PeerProp) GetProp

func (this *PeerProp) GetProp() *PeerProp

func (*PeerProp) Init

func (this *PeerProp) Init()

func (*PeerProp) IsRunning

func (this *PeerProp) IsRunning() bool

func (*PeerProp) IsStopping

func (this *PeerProp) IsStopping() bool

func (*PeerProp) MaxPacketSize

func (self *PeerProp) MaxPacketSize() int

func (*PeerProp) Name

func (this *PeerProp) Name() string

func (*PeerProp) ProcEvent

func (this *PeerProp) ProcEvent(ev Event)

func (*PeerProp) Queue

func (this *PeerProp) Queue() EventQueue

func (*PeerProp) ReadMessage

func (this *PeerProp) ReadMessage(ses Session) (msg interface{}, err error)

func (*PeerProp) SendMessage

func (this *PeerProp) SendMessage(ev Event)

func (*PeerProp) SetAddress

func (this *PeerProp) SetAddress(v string)

func (*PeerProp) SetCallback

func (this *PeerProp) SetCallback(v EventCallback)

func (*PeerProp) SetHooker

func (this *PeerProp) SetHooker(v EventHooker)

func (*PeerProp) SetMaxPacketSize

func (self *PeerProp) SetMaxPacketSize(maxSize int)

func (*PeerProp) SetName

func (this *PeerProp) SetName(v string)

func (*PeerProp) SetQueue

func (this *PeerProp) SetQueue(v EventQueue)

func (*PeerProp) SetRunning

func (this *PeerProp) SetRunning(v bool)

func (*PeerProp) SetSocketBuffer

func (this *PeerProp) SetSocketBuffer(readBufferSize, writeBufferSize int, noDelay bool)

func (*PeerProp) SetSocketDeadline

func (self *PeerProp) SetSocketDeadline(read, write time.Duration)

func (*PeerProp) SetTransmitter

func (this *PeerProp) SetTransmitter(v MessageTransmitter)

func (*PeerProp) StartStopping

func (this *PeerProp) StartStopping()

func (*PeerProp) WaitStopFinished

func (this *PeerProp) WaitStopFinished()

type Pipe

type Pipe struct {
	// contains filtered or unexported fields
}

不限制大小,添加不发生阻塞,接收阻塞等待

func NewPipe

func NewPipe() *Pipe

func (*Pipe) Add

func (self *Pipe) Add(msg interface{})

添加时不会发送阻塞

func (*Pipe) Pick

func (self *Pipe) Pick(retList *[]interface{}) (exit bool)

如果没有数据,发生阻塞

func (*Pipe) Reset

func (self *Pipe) Reset()

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) Reply

func (self *RecvMsgEvent) Reply(msg interface{})

兼容relay和rpc的回消息接口

func (*RecvMsgEvent) Send

func (self *RecvMsgEvent) Send(msg interface{})

func (*RecvMsgEvent) Session

func (self *RecvMsgEvent) Session() Session

type RemoteAddr

type RemoteAddr interface {
	RemoteAddr() net.Addr
}

type ReplyEvent

type ReplyEvent interface {
	Reply(msg interface{})
}

rpc, relay, 普通消息

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()

type SessionManager

type SessionManager interface {
	// cellnet.SessionAccessor
	GetSession(int64) Session
	VisitSession(func(Session) bool)
	SessionCount() int
	CloseAllSession()

	Add(Session)
	Remove(Session)
	Count() int

	SetIdBase(base int64)
}

完整功能的会话管理

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL