Versions in this module Expand all Collapse all v1 v1.5.1 Feb 22, 2017 Changes in this version + const HeartBeat + const MaxConnections + const MessageLenBytes + const MessageMaxBytes + const MessageTypeBytes + const WorkersNum + var ErrBadData = errors.New("more than 8M data") + var ErrNilData = errors.New("nil data") + var ErrNilKey = errors.New("nil key") + var ErrNilValue = errors.New("nil value") + var ErrNotHashable = errors.New("not hashable") + var ErrNotRegistered = errors.New("handler not registered") + var ErrParameter = errors.New("parameter error") + var ErrServerClosed = errors.New("server has been closed") + var ErrWouldBlock = errors.New("would block") + func HandleHeartBeat(ctx context.Context, c WriteCloser) + func LoadTLSConfig(certFile, keyFile string, isSkipVerify bool) (*tls.Config, error) + func MonitorOn(port int) + func NetIDFromContext(ctx context.Context) int64 + func NewContextWithMessage(ctx context.Context, msg Message) context.Context + func NewContextWithNetID(ctx context.Context, netID int64) context.Context + func Register(msgType int32, unmarshaler func([]byte) (Message, error), ...) + type AtomicBoolean int32 + func NewAtomicBoolean(initialValue bool) *AtomicBoolean + func (a *AtomicBoolean) CompareAndSet(oldValue, newValue bool) bool + func (a *AtomicBoolean) Get() bool + func (a *AtomicBoolean) GetAndSet(newValue bool) bool + func (a *AtomicBoolean) Set(newValue bool) + func (a *AtomicBoolean) String() string + type AtomicInt32 int32 + func NewAtomicInt32(initialValue int32) *AtomicInt32 + func (a *AtomicInt32) AddAndGet(delta int32) int32 + func (a *AtomicInt32) CompareAndSet(expect, update int32) bool + func (a *AtomicInt32) DecrementAndGet() int32 + func (a *AtomicInt32) Get() int32 + func (a *AtomicInt32) GetAndAdd(delta int32) int32 + func (a *AtomicInt32) GetAndDecrement() int32 + func (a *AtomicInt32) GetAndIncrement() int32 + func (a *AtomicInt32) GetAndSet(newValue int32) (oldValue int32) + func (a *AtomicInt32) IncrementAndGet() int32 + func (a *AtomicInt32) Set(newValue int32) + func (a *AtomicInt32) String() string + type AtomicInt64 int64 + func NewAtomicInt64(initialValue int64) *AtomicInt64 + func (a *AtomicInt64) AddAndGet(delta int64) int64 + func (a *AtomicInt64) CompareAndSet(expect, update int64) bool + func (a *AtomicInt64) DecrementAndGet() int64 + func (a *AtomicInt64) Get() int64 + func (a *AtomicInt64) GetAndAdd(delta int64) int64 + func (a *AtomicInt64) GetAndDecrement() int64 + func (a *AtomicInt64) GetAndIncrement() int64 + func (a *AtomicInt64) GetAndSet(newValue int64) int64 + func (a *AtomicInt64) IncrementAndGet() int64 + func (a *AtomicInt64) Set(newValue int64) + func (a *AtomicInt64) String() string + type ClientConn struct + func NewClientConn(netid int64, c net.Conn, opt ...ServerOption) *ClientConn + func (cc *ClientConn) AddPendingTimer(timerID int64) + func (cc *ClientConn) CancelTimer(timerID int64) + func (cc *ClientConn) Close() + func (cc *ClientConn) GetContextValue(k interface{}) interface{} + func (cc *ClientConn) GetHeartBeat() int64 + func (cc *ClientConn) GetName() string + func (cc *ClientConn) GetNetID() int64 + func (cc *ClientConn) LocalAddr() net.Addr + func (cc *ClientConn) RemoteAddr() net.Addr + func (cc *ClientConn) RunAfter(duration time.Duration, callback func(time.Time, WriteCloser)) int64 + func (cc *ClientConn) RunAt(timestamp time.Time, callback func(time.Time, WriteCloser)) int64 + func (cc *ClientConn) RunEvery(interval time.Duration, callback func(time.Time, WriteCloser)) int64 + func (cc *ClientConn) SetContextValue(k, v interface{}) + func (cc *ClientConn) SetHeartBeat(heart int64) + func (cc *ClientConn) SetName(name string) + func (cc *ClientConn) Start() + func (cc *ClientConn) Write(message Message) error + type Codec interface + Decode func(net.Conn) (Message, error) + Encode func(Message) ([]byte, error) + type ConnMap struct + func NewConnMap() *ConnMap + func (cm *ConnMap) Clear() + func (cm *ConnMap) Get(id int64) (*ServerConn, bool) + func (cm *ConnMap) IsEmpty() bool + func (cm *ConnMap) Put(id int64, sc *ServerConn) + func (cm *ConnMap) Remove(id int64) + func (cm *ConnMap) Size() int + type ErrUndefined int32 + func (e ErrUndefined) Error() string + type Handler interface + Handle func(context.Context, interface{}) + type HandlerFunc func(context.Context, WriteCloser) + func GetHandlerFunc(msgType int32) HandlerFunc + func (f HandlerFunc) Handle(ctx context.Context, c WriteCloser) + type Hashable interface + HashCode func() int32 + type HeartBeatMessage struct + Timestamp int64 + func (hbm HeartBeatMessage) MessageNumber() int32 + func (hbm HeartBeatMessage) Serialize() ([]byte, error) + type Message interface + MessageNumber func() int32 + Serialize func() ([]byte, error) + func DeserializeHeartBeat(data []byte) (message Message, err error) + func MessageFromContext(ctx context.Context) Message + type MessageHandler struct + type OnTimeOut struct + Callback func(time.Time, WriteCloser) + Ctx context.Context + func NewOnTimeOut(ctx context.Context, cb func(time.Time, WriteCloser)) *OnTimeOut + type Server struct + func NewServer(opt ...ServerOption) *Server + func ServerFromContext(ctx context.Context) (*Server, bool) + func (s *Server) Broadcast(msg Message) + func (s *Server) ConnsMap() *ConnMap + func (s *Server) GetConn(id int64) (*ServerConn, bool) + func (s *Server) Sched(dur time.Duration, sched func(time.Time, WriteCloser)) + func (s *Server) Start(l net.Listener) error + func (s *Server) Stop() + func (s *Server) Unicast(id int64, msg Message) error + type ServerConn struct + func NewServerConn(id int64, s *Server, c net.Conn) *ServerConn + func (sc *ServerConn) AddPendingTimer(timerID int64) + func (sc *ServerConn) CancelTimer(timerID int64) + func (sc *ServerConn) Close() + func (sc *ServerConn) GetContextValue(k interface{}) interface{} + func (sc *ServerConn) GetHeartBeat() int64 + func (sc *ServerConn) GetName() string + func (sc *ServerConn) GetNetID() int64 + func (sc *ServerConn) LocalAddr() net.Addr + func (sc *ServerConn) RemoteAddr() net.Addr + func (sc *ServerConn) RunAfter(duration time.Duration, callback func(time.Time, WriteCloser)) int64 + func (sc *ServerConn) RunAt(timestamp time.Time, callback func(time.Time, WriteCloser)) int64 + func (sc *ServerConn) RunEvery(interval time.Duration, callback func(time.Time, WriteCloser)) int64 + func (sc *ServerConn) SetContextValue(k, v interface{}) + func (sc *ServerConn) SetHeartBeat(heart int64) + func (sc *ServerConn) SetName(name string) + func (sc *ServerConn) Start() + func (sc *ServerConn) Write(message Message) error + type ServerOption func(*options) + func CustomCodecOption(codec Codec) ServerOption + func OnCloseOption(cb func(WriteCloser)) ServerOption + func OnConnectOption(cb func(WriteCloser) bool) ServerOption + func OnErrorOption(cb func(WriteCloser)) ServerOption + func OnMessageOption(cb func(Message, WriteCloser)) ServerOption + func ReconnectOption() ServerOption + func TLSCredsOption(config *tls.Config) ServerOption + type TimingWheel struct + func NewTimingWheel(ctx context.Context) *TimingWheel + func (tw *TimingWheel) AddTimer(when time.Time, interv time.Duration, to *OnTimeOut) int64 + func (tw *TimingWheel) CancelTimer(timerID int64) + func (tw *TimingWheel) GetTimeOutChannel() chan *OnTimeOut + func (tw *TimingWheel) Size() int + func (tw *TimingWheel) Stop() + type TypeLengthValueCodec struct + func (codec TypeLengthValueCodec) Decode(raw net.Conn) (Message, error) + func (codec TypeLengthValueCodec) Encode(msg Message) ([]byte, error) + type UnmarshalFunc func([]byte) (Message, error) + func GetUnmarshalFunc(msgType int32) UnmarshalFunc + type WorkerPool struct + func WorkerPoolInstance() *WorkerPool + func (wp *WorkerPool) Close() + func (wp *WorkerPool) Put(k interface{}, cb func()) error + type WriteCloser interface + Close func() + Write func(Message) error