Documentation ¶
Index ¶
- Constants
- Variables
- func Dispatch(dispatchers []*Dispatcher, agent NetAgent)
- func IsHeartbeatData(data []byte) bool
- func NeedDeserialize(dispatchers []*Dispatcher, t reflect.Type) bool
- func NewNetAddrFn(addr ...string) func() (addrs []*NetAddr, err error)
- func NewNetHub(heartbeat bool, lb bool) *netHub
- func NewNetKeyAddrFn(key_or_addr ...string) func() (addrs []*NetAddr, err error)
- func Serialize(serializer Serializer, v interface{}, h ...interface{}) (data []byte, err error)
- func TestCall(functions ...func())
- func TestDone(force ...bool)
- func TestWait(delay ...int)
- type ByteSerializer
- type Closer
- type Dispatcher
- func (p *Dispatcher) AddHandler(h func(agent NetAgent), idOrType ...interface{})
- func (p *Dispatcher) AddRawHandler(h func(agent NetAgent), idOrType ...interface{})
- func (p *Dispatcher) Destroy()
- func (p *Dispatcher) NeedDeserialize(t reflect.Type) bool
- func (p *Dispatcher) NewTicker(d time.Duration, h func(t *time.Time, params ...interface{}), ...) NetTimer
- func (p *Dispatcher) NewTimer(d time.Duration, h func(t *time.Time, params ...interface{}), ...) NetTimer
- func (p *Dispatcher) OnConnectionClosed(h func(agent NetAgent))
- func (p *Dispatcher) OnConnectionCreated(h func(agent NetAgent))
- func (p *Dispatcher) OnDestroy(h func())
- type EmptySerializer
- func (s *EmptySerializer) DeserializeId(raw []byte) (id interface{}, t reflect.Type, data []byte, err error)
- func (s *EmptySerializer) PreRawPack(rp *RawPack)
- func (s *EmptySerializer) RangeId(f func(id interface{}, t reflect.Type))
- func (s *EmptySerializer) RangeIdInt(f func(id int, t reflect.Type))
- func (s *EmptySerializer) RangeIdString(f func(id int, t reflect.Type))
- func (s *EmptySerializer) RegisterDeserializeId(v interface{}, one_id ...interface{}) (id interface{}, err error)
- func (s *EmptySerializer) RegisterId(v interface{}, one_id ...interface{}) (id interface{}, err error)
- func (s *EmptySerializer) RegisterSerializeId(v interface{}, one_id ...interface{}) (id interface{}, err error)
- func (s *EmptySerializer) SetIdInitValue(id int)
- type Intercepter
- type JsonSerializer
- type NetAddr
- type NetAgent
- type NetConn
- type NetHub
- type NetReader
- type NetSession
- type NetTimer
- type NetTimerEvent
- type NetWriter
- type ProtobufSerializer
- type RawPack
- type ReadMode
- type Serializer
- type StringSerializer
- type TCPClient
- func (c *TCPClient) AddDispatchers(dispatchers ...*Dispatcher) *TCPClient
- func (c *TCPClient) Close()
- func (c *TCPClient) Connect() *TCPClient
- func (c *TCPClient) DisableAutoReconnect() *TCPClient
- func (c *TCPClient) EnableMonitor(monitorLog *log4g.Loggers) *TCPClient
- func (c *TCPClient) SetHub(hub NetHub) *TCPClient
- func (c *TCPClient) SetReadIntercepter(intercepter Intercepter) *TCPClient
- func (c *TCPClient) SetSerializer(serializer Serializer) *TCPClient
- func (c *TCPClient) SetWriteIntercepter(intercepter Intercepter) *TCPClient
- func (c *TCPClient) Wait()
- type TCPServer
- func (s *TCPServer) AddDispatchers(dispatchers ...*Dispatcher) *TCPServer
- func (s *TCPServer) Close()
- func (s *TCPServer) EnableMonitor(monitorLog *log4g.Loggers) *TCPServer
- func (s *TCPServer) NewJsonSerializer() *TCPServer
- func (s *TCPServer) SetHub(hub NetHub) *TCPServer
- func (s *TCPServer) SetReadIntercepter(intercepter Intercepter) *TCPServer
- func (s *TCPServer) SetSerializer(serializer Serializer) *TCPServer
- func (s *TCPServer) SetWriteIntercepter(intercepter Intercepter) *TCPServer
- func (s *TCPServer) Start() *TCPServer
- func (s *TCPServer) Wait(others ...Closer)
Constants ¶
View Source
const ( HEART_BEAT_INTERVAL = 1 * time.Second HEART_BEAT_LAST_TIME = "__NET4G01" //SESSION_ID = "ID" SESSION_GROUP_NAME = "__NET4G02" SESSION_CONNECT_KEY = "__NET4G03" SESSION_CONNECT_KEY_USER = "__NET4G03_USER" SESSION_CONNECT_ESTABLISH_TIME = "__NET4G04" SESSION_CONNECT_LAST_READ_TIME = "__NET4G05" SESSION_CONNECT_LAST_WRITE_TIME = "__NET4G06" )
Variables ¶
View Source
var NetConfig netConfig
View Source
var Terminal os.Signal = syscall.SIGTERM
Functions ¶
func Dispatch ¶
func Dispatch(dispatchers []*Dispatcher, agent NetAgent)
func IsHeartbeatData ¶
func NeedDeserialize ¶
func NeedDeserialize(dispatchers []*Dispatcher, t reflect.Type) bool
func NewNetAddrFn ¶
func NewNetKeyAddrFn ¶
func Serialize ¶
func Serialize(serializer Serializer, v interface{}, h ...interface{}) (data []byte, err error)
Types ¶
type ByteSerializer ¶
type ByteSerializer struct {
*EmptySerializer
}
func (*ByteSerializer) DeserializeData ¶
func (s *ByteSerializer) DeserializeData(data []byte, t reflect.Type) (h interface{}, v interface{}, err error)
func (*ByteSerializer) Serialize ¶
func (s *ByteSerializer) Serialize(v, h interface{}) (data []byte, err error)
type Dispatcher ¶
type Dispatcher struct { Name string // contains filtered or unexported fields }
func NewDispatcher ¶
func NewDispatcher(goroutineNum ...int) *Dispatcher
func NewNamedDispatcher ¶
func NewNamedDispatcher(name string, goroutineNum ...int) *Dispatcher
func (*Dispatcher) AddHandler ¶
func (p *Dispatcher) AddHandler(h func(agent NetAgent), idOrType ...interface{})
func (*Dispatcher) AddRawHandler ¶
func (p *Dispatcher) AddRawHandler(h func(agent NetAgent), idOrType ...interface{})
func (*Dispatcher) Destroy ¶
func (p *Dispatcher) Destroy()
func (*Dispatcher) NeedDeserialize ¶
func (p *Dispatcher) NeedDeserialize(t reflect.Type) bool
func (*Dispatcher) OnConnectionClosed ¶
func (p *Dispatcher) OnConnectionClosed(h func(agent NetAgent))
func (*Dispatcher) OnConnectionCreated ¶
func (p *Dispatcher) OnConnectionCreated(h func(agent NetAgent))
func (*Dispatcher) OnDestroy ¶
func (p *Dispatcher) OnDestroy(h func())
type EmptySerializer ¶
type EmptySerializer struct { SerializerTypeIdMap map[reflect.Type]interface{} SerializerIdTypeMap map[interface{}]reflect.Type DeserializerTypeIdMap map[reflect.Type]interface{} DeserializerIdTypeMap map[interface{}]reflect.Type // contains filtered or unexported fields }
func NewEmptySerializer ¶
func NewEmptySerializer() *EmptySerializer
func (*EmptySerializer) DeserializeId ¶
func (*EmptySerializer) PreRawPack ¶
func (s *EmptySerializer) PreRawPack(rp *RawPack)
func (*EmptySerializer) RangeId ¶
func (s *EmptySerializer) RangeId(f func(id interface{}, t reflect.Type))
func (*EmptySerializer) RangeIdInt ¶
func (s *EmptySerializer) RangeIdInt(f func(id int, t reflect.Type))
func (*EmptySerializer) RangeIdString ¶
func (s *EmptySerializer) RangeIdString(f func(id int, t reflect.Type))
func (*EmptySerializer) RegisterDeserializeId ¶
func (s *EmptySerializer) RegisterDeserializeId(v interface{}, one_id ...interface{}) (id interface{}, err error)
func (*EmptySerializer) RegisterId ¶
func (s *EmptySerializer) RegisterId(v interface{}, one_id ...interface{}) (id interface{}, err error)
func (*EmptySerializer) RegisterSerializeId ¶
func (s *EmptySerializer) RegisterSerializeId(v interface{}, one_id ...interface{}) (id interface{}, err error)
func (*EmptySerializer) SetIdInitValue ¶
func (s *EmptySerializer) SetIdInitValue(id int)
type Intercepter ¶
type JsonSerializer ¶
type JsonSerializer struct {
*EmptySerializer
}
func (*JsonSerializer) DeserializeData ¶
func (s *JsonSerializer) DeserializeData(data []byte, t reflect.Type) (h, v interface{}, err error)
func (*JsonSerializer) Serialize ¶
func (s *JsonSerializer) Serialize(v, h interface{}) (data []byte, err error)
type NetAddr ¶
func NewKeyAddr ¶
type NetHub ¶
type NetHub interface { Add(key string, conn NetConn) Key(conn NetConn, key string) Get(key string) NetConn Remove(conn NetConn) Slice() []NetConn Count() int Heartbeat(conn NetConn) Kick(key string) SetSerializer(serializer Serializer) Broadcast(v interface{}, filter func(session NetSession) bool, h ...interface{}) error BroadcastAll(v interface{}, h ...interface{}) error BroadcastOthers(mySession NetSession, v interface{}, h ...interface{}) error BroadcastOne(v interface{}, errFunc func(error), h ...interface{}) error Send(key string, v interface{}) error MultiSend(keys []string, v interface{}) error SetGroup(session NetSession, group string) Group(group string, v interface{}, h ...interface{}) error GroupOne(group string, v interface{}, errFunc func(error), h ...interface{}) error RangeConn(f func(NetConn)) RangeSession(f func(session NetSession)) Statistics() PackCount() (totalRead int64, totalWrite int64, popRead int64, popWrite int64) DataUsage() (totalRead int64, totalWrite int64, popRead int64, popWrite int64) Closed() bool Destroy() }
type NetSession ¶
type NetSession interface { Set(key string, value interface{}) Get(key string, defaultValue ...interface{}) interface{} GetString(key string, defaultValue ...string) string GetInt(key string, defaultValue ...int) int GetInt64(key string, defaultValue ...int64) int64 GetBool(key string, defaultValue ...bool) bool Has(key string) bool Remove(key string) SetLogin() IsLogin() bool }
func NewNetSession ¶
func NewNetSession() NetSession
type NetTimerEvent ¶
type NetTimerEvent struct {
// contains filtered or unexported fields
}
type ProtobufSerializer ¶
type ProtobufSerializer struct {
*EmptySerializer
}
func (*ProtobufSerializer) DeserializeData ¶
func (s *ProtobufSerializer) DeserializeData(data []byte, t reflect.Type) (h, v interface{}, err error)
func (*ProtobufSerializer) Serialize ¶
func (s *ProtobufSerializer) Serialize(v, h interface{}) (data []byte, err error)
type Serializer ¶
type Serializer interface { SetIdInitValue(id int) RegisterId(v interface{}, one_id ...interface{}) (id interface{}, err error) RegisterSerializeId(v interface{}, one_id ...interface{}) (id interface{}, err error) RegisterDeserializeId(v interface{}, one_id ...interface{}) (id interface{}, err error) Serialize(v, h interface{}) (data []byte, err error) DeserializeId(raw []byte) (id interface{}, t reflect.Type, data []byte, err error) DeserializeData(data []byte, t reflect.Type) (h, v interface{}, err error) RangeId(f func(id interface{}, t reflect.Type)) }
func NewByteSerializer ¶
func NewByteSerializer() Serializer
func NewJsonSerializer ¶
func NewJsonSerializer() Serializer
func NewProtobufSerializer ¶
func NewProtobufSerializer() Serializer
func NewStringSerializer ¶
func NewStringSerializer() Serializer
type StringSerializer ¶
type StringSerializer struct {
*EmptySerializer
}
func (*StringSerializer) DeserializeData ¶
func (s *StringSerializer) DeserializeData(data []byte, t reflect.Type) (h, v interface{}, err error)
func (*StringSerializer) Serialize ¶
func (s *StringSerializer) Serialize(v, h interface{}) (raw []byte, err error)
type TCPClient ¶
type TCPClient struct { AutoReconnect bool // contains filtered or unexported fields }
func NewTcpClient ¶
func (*TCPClient) AddDispatchers ¶
func (c *TCPClient) AddDispatchers(dispatchers ...*Dispatcher) *TCPClient
func (*TCPClient) DisableAutoReconnect ¶
func (*TCPClient) EnableMonitor ¶
func (*TCPClient) SetReadIntercepter ¶
func (c *TCPClient) SetReadIntercepter(intercepter Intercepter) *TCPClient
func (*TCPClient) SetSerializer ¶
func (c *TCPClient) SetSerializer(serializer Serializer) *TCPClient
func (*TCPClient) SetWriteIntercepter ¶
func (c *TCPClient) SetWriteIntercepter(intercepter Intercepter) *TCPClient
type TCPServer ¶
type TCPServer struct { Name string Addr string Serializer Serializer Dispatcher *Dispatcher // contains filtered or unexported fields }
func NewNamedTcpServer ¶
func NewTcpServer ¶
func (*TCPServer) AddDispatchers ¶
func (s *TCPServer) AddDispatchers(dispatchers ...*Dispatcher) *TCPServer
func (*TCPServer) EnableMonitor ¶
func (*TCPServer) NewJsonSerializer ¶
func (*TCPServer) SetReadIntercepter ¶
func (s *TCPServer) SetReadIntercepter(intercepter Intercepter) *TCPServer
func (*TCPServer) SetSerializer ¶
func (s *TCPServer) SetSerializer(serializer Serializer) *TCPServer
func (*TCPServer) SetWriteIntercepter ¶
func (s *TCPServer) SetWriteIntercepter(intercepter Intercepter) *TCPServer
Source Files ¶
Click to show internal directories.
Click to hide internal directories.