Documentation ¶
Overview ¶
Package tao implements a light-weight TCP network programming framework.
Server represents a TCP server with various ServerOption supported.
1. Provides custom codec by CustomCodecOption; 2. Provides TLS server by TLSCredsOption; 3. Provides callback on connected by OnConnectOption; 4. Provides callback on meesage arrived by OnMessageOption; 5. Provides callback on closed by OnCloseOption; 6. Provides callback on error occurred by OnErrorOption;
ServerConn represents a connection on the server side.
ClientConn represents a connection connect to other servers. You can make it reconnectable by passing ReconnectOption when creating.
AtomicInt64, AtomicInt32 and AtomicBoolean are providing concurrent-safe atomic types in a Java-like style while ConnMap is a go-routine safe map for connection management.
Every handler function is defined as func(context.Context, WriteCloser). Usually a meesage and a net ID are shifted within the Context, developers can retrieve them by calling the following functions.
func NewContextWithMessage(ctx context.Context, msg Message) context.Context func MessageFromContext(ctx context.Context) Message func NewContextWithNetID(ctx context.Context, netID int64) context.Context func NetIDFromContext(ctx context.Context) int64
Programmers are free to define their own request-scoped data and put them in the context, but must be sure that the data is safe for multiple go-routines to access.
Every message must define according to the interface and a deserialization function:
type Message interface { MessageNumber() int32 Serialize() ([]byte, error) } func Deserialize(data []byte) (message Message, err error)
There is a TypeLengthValueCodec defined, but one can also define his/her own codec:
type Codec interface { Decode(net.Conn) (Message, error) Encode(Message) ([]byte, error) }
TimingWheel is a safe timer for running timed callbacks on connection.
WorkerPool is a go-routine pool for running message handlers, you can fetch one by calling func WorkerPoolInstance() *WorkerPool.
Index ¶
- Constants
- Variables
- 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
- type 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
- 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
- func (cc *ClientConn) AddPendingTimer(timerID int64)
- func (cc *ClientConn) CancelTimer(timerID int64)
- func (cc *ClientConn) Close()
- func (cc *ClientConn) ContextValue(k interface{}) interface{}
- func (cc *ClientConn) HeartBeat() int64
- func (cc *ClientConn) LocalAddr() net.Addr
- func (cc *ClientConn) Name() string
- func (cc *ClientConn) NetID() int64
- 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
- func (cc *ClientConn) WriteData(data []byte) error
- type Codec
- type ErrUndefined
- type Handler
- type HandlerFunc
- type Hashable
- type HeartBeatMessage
- type Message
- type MessageHandler
- type OnTimeOut
- type Server
- func (s *Server) Broadcast(msg Message)
- func (s *Server) Conn(id int64) (*ServerConn, bool)
- func (s *Server) ConnsSize() int
- 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
- func (sc *ServerConn) AddPendingTimer(timerID int64)
- func (sc *ServerConn) CancelTimer(timerID int64)
- func (sc *ServerConn) Close()
- func (sc *ServerConn) ContextValue(k interface{}) interface{}
- func (sc *ServerConn) HeartBeat() int64
- func (sc *ServerConn) LocalAddr() net.Addr
- func (sc *ServerConn) Name() string
- func (sc *ServerConn) NetID() int64
- 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 BufferSizeOption(indicator int) ServerOption
- 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
- func WorkerSizeOption(workerSz int) ServerOption
- type TimingWheel
- type TypeLengthValueCodec
- type UnmarshalFunc
- type WorkerPool
- type WriteCloser
Constants ¶
const ( // MessageTypeBytes is the length of type header. MessageTypeBytes = 4 // MessageLenBytes is the length of length header. MessageLenBytes = 4 // MessageMaxBytes is the maximum bytes allowed for application data. MessageMaxBytes = 1 << 23 // 8M )
const ( MaxConnections = 1000 BufferSize128 = 128 BufferSize256 = 256 BufferSize512 = 512 BufferSize1024 = 1024 )
definitions about some constants.
const (
// HeartBeat is the default heart beat message number.
HeartBeat = 0
)
Variables ¶
var ( ErrParameter = errors.New("parameter error") ErrNilKey = errors.New("nil key") ErrNilValue = errors.New("nil value") ErrWouldBlock = errors.New("would block") ErrNotHashable = errors.New("not hashable") ErrNilData = errors.New("nil data") ErrBadData = errors.New("more than 8M data") ErrNotRegistered = errors.New("handler not registered") ErrServerClosed = errors.New("server has been closed") )
Error codes returned by failures dealing with server or connection.
Functions ¶
func HandleHeartBeat ¶
func HandleHeartBeat(ctx context.Context, c WriteCloser)
HandleHeartBeat updates connection heart beat timestamp.
func LoadTLSConfig ¶
LoadTLSConfig returns a TLS configuration with the specified cert and key file.
func NetIDFromContext ¶
NetIDFromContext returns a net ID from a Context.
func NewContextWithMessage ¶
NewContextWithMessage returns a new Context that carries message.
func NewContextWithNetID ¶
NewContextWithNetID returns a new Context that carries net ID.
func Register ¶
func Register(msgType int32, unmarshaler func([]byte) (Message, error), handler func(context.Context, WriteCloser))
Register registers the unmarshal and handle functions for msgType. If no unmarshal function provided, the message will not be parsed. If no handler function provided, the message will not be handled unless you set a default one by calling SetOnMessageCallback. If Register being called twice on one msgType, it will panics.
Types ¶
type AtomicBoolean ¶
type AtomicBoolean int32
AtomicBoolean provides atomic boolean type.
func NewAtomicBoolean ¶
func NewAtomicBoolean(initialValue bool) *AtomicBoolean
NewAtomicBoolean returns an atomic boolean type.
func (*AtomicBoolean) CompareAndSet ¶
func (a *AtomicBoolean) CompareAndSet(oldValue, newValue bool) bool
CompareAndSet compares boolean with expected value, if equals as expected then sets the updated value, this operation performs atomically.
func (*AtomicBoolean) Get ¶
func (a *AtomicBoolean) Get() bool
Get returns the value of boolean atomically.
func (*AtomicBoolean) GetAndSet ¶
func (a *AtomicBoolean) GetAndSet(newValue bool) bool
GetAndSet sets new value and returns the old atomically.
func (*AtomicBoolean) Set ¶
func (a *AtomicBoolean) Set(newValue bool)
Set sets the value of boolean atomically.
func (*AtomicBoolean) String ¶
func (a *AtomicBoolean) String() string
type AtomicInt32 ¶
type AtomicInt32 int32
AtomicInt32 provides atomic int32 type.
func NewAtomicInt32 ¶
func NewAtomicInt32(initialValue int32) *AtomicInt32
NewAtomicInt32 returns an atomoic int32 type.
func (*AtomicInt32) AddAndGet ¶
func (a *AtomicInt32) AddAndGet(delta int32) int32
AddAndGet adds the value by delta and then gets the value, this operation performs atomically.
func (*AtomicInt32) CompareAndSet ¶
func (a *AtomicInt32) CompareAndSet(expect, update int32) bool
CompareAndSet compares int64 with expected value, if equals as expected then sets the updated value, this operation performs atomically.
func (*AtomicInt32) DecrementAndGet ¶
func (a *AtomicInt32) DecrementAndGet() int32
DecrementAndGet decrements the value by 1 and then gets the value, this operation performs atomically.
func (*AtomicInt32) Get ¶
func (a *AtomicInt32) Get() int32
Get returns the value of int32 atomically.
func (*AtomicInt32) GetAndAdd ¶
func (a *AtomicInt32) GetAndAdd(delta int32) int32
GetAndAdd gets the old value and then add by delta, this operation performs atomically.
func (*AtomicInt32) GetAndDecrement ¶
func (a *AtomicInt32) GetAndDecrement() int32
GetAndDecrement gets the old value and then decrement by 1, this operation performs atomically.
func (*AtomicInt32) GetAndIncrement ¶
func (a *AtomicInt32) GetAndIncrement() int32
GetAndIncrement gets the old value and then increment by 1, this operation performs atomically.
func (*AtomicInt32) GetAndSet ¶
func (a *AtomicInt32) GetAndSet(newValue int32) (oldValue int32)
GetAndSet sets new value and returns the old atomically.
func (*AtomicInt32) IncrementAndGet ¶
func (a *AtomicInt32) IncrementAndGet() int32
IncrementAndGet increments the value by 1 and then gets the value, this operation performs atomically.
func (*AtomicInt32) Set ¶
func (a *AtomicInt32) Set(newValue int32)
Set sets the value of int32 atomically.
func (*AtomicInt32) String ¶
func (a *AtomicInt32) String() string
type AtomicInt64 ¶
type AtomicInt64 int64
AtomicInt64 provides atomic int64 type.
func NewAtomicInt64 ¶
func NewAtomicInt64(initialValue int64) *AtomicInt64
NewAtomicInt64 returns an atomic int64 type.
func (*AtomicInt64) AddAndGet ¶
func (a *AtomicInt64) AddAndGet(delta int64) int64
AddAndGet adds the value by delta and then gets the value, this operation performs atomically.
func (*AtomicInt64) CompareAndSet ¶
func (a *AtomicInt64) CompareAndSet(expect, update int64) bool
CompareAndSet compares int64 with expected value, if equals as expected then sets the updated value, this operation performs atomically.
func (*AtomicInt64) DecrementAndGet ¶
func (a *AtomicInt64) DecrementAndGet() int64
DecrementAndGet decrements the value by 1 and then gets the value, this operation performs atomically.
func (*AtomicInt64) Get ¶
func (a *AtomicInt64) Get() int64
Get returns the value of int64 atomically.
func (*AtomicInt64) GetAndAdd ¶
func (a *AtomicInt64) GetAndAdd(delta int64) int64
GetAndAdd gets the old value and then add by delta, this operation performs atomically.
func (*AtomicInt64) GetAndDecrement ¶
func (a *AtomicInt64) GetAndDecrement() int64
GetAndDecrement gets the old value and then decrement by 1, this operation performs atomically.
func (*AtomicInt64) GetAndIncrement ¶
func (a *AtomicInt64) GetAndIncrement() int64
GetAndIncrement gets the old value and then increment by 1, this operation performs atomically.
func (*AtomicInt64) GetAndSet ¶
func (a *AtomicInt64) GetAndSet(newValue int64) int64
GetAndSet sets new value and returns the old atomically.
func (*AtomicInt64) IncrementAndGet ¶
func (a *AtomicInt64) IncrementAndGet() int64
IncrementAndGet increments the value by 1 and then gets the value, this operation performs atomically.
func (*AtomicInt64) Set ¶
func (a *AtomicInt64) Set(newValue int64)
Set sets the value of int64 atomically.
func (*AtomicInt64) String ¶
func (a *AtomicInt64) String() string
type ClientConn ¶
type ClientConn struct {
// contains filtered or unexported fields
}
ClientConn represents a client connection to a TCP server.
func NewClientConn ¶
func NewClientConn(netid int64, c net.Conn, opt ...ServerOption) *ClientConn
NewClientConn returns a new client connection which has not started to serve requests yet.
func (*ClientConn) AddPendingTimer ¶
func (cc *ClientConn) AddPendingTimer(timerID int64)
AddPendingTimer adds a new timer ID to client connection.
func (*ClientConn) CancelTimer ¶
func (cc *ClientConn) CancelTimer(timerID int64)
CancelTimer cancels a timer with the specified ID.
func (*ClientConn) Close ¶
func (cc *ClientConn) Close()
Close gracefully closes the client connection. It blocked until all sub go-routines are completed and returned.
func (*ClientConn) ContextValue ¶
func (cc *ClientConn) ContextValue(k interface{}) interface{}
ContextValue gets extra data from client connection.
func (*ClientConn) HeartBeat ¶
func (cc *ClientConn) HeartBeat() int64
HeartBeat gets the heart beats of client connection.
func (*ClientConn) LocalAddr ¶
func (cc *ClientConn) LocalAddr() net.Addr
LocalAddr returns the local address of server connection.
func (*ClientConn) Name ¶
func (cc *ClientConn) Name() string
Name gets the name of client connection.
func (*ClientConn) NetID ¶
func (cc *ClientConn) NetID() int64
NetID returns the net ID of client connection.
func (*ClientConn) RemoteAddr ¶
func (cc *ClientConn) RemoteAddr() net.Addr
RemoteAddr returns the remote address of server connection.
func (*ClientConn) RunAfter ¶
func (cc *ClientConn) RunAfter(duration time.Duration, callback func(time.Time, WriteCloser)) int64
RunAfter runs a callback right after the specified duration ellapsed.
func (*ClientConn) RunAt ¶
func (cc *ClientConn) RunAt(timestamp time.Time, callback func(time.Time, WriteCloser)) int64
RunAt runs a callback at the specified timestamp.
func (*ClientConn) RunEvery ¶
func (cc *ClientConn) RunEvery(interval time.Duration, callback func(time.Time, WriteCloser)) int64
RunEvery runs a callback on every interval time.
func (*ClientConn) SetContextValue ¶
func (cc *ClientConn) SetContextValue(k, v interface{})
SetContextValue sets extra data to client connection.
func (*ClientConn) SetHeartBeat ¶
func (cc *ClientConn) SetHeartBeat(heart int64)
SetHeartBeat sets the heart beats of client connection.
func (*ClientConn) SetName ¶
func (cc *ClientConn) SetName(name string)
SetName sets the name of client connection.
func (*ClientConn) Start ¶
func (cc *ClientConn) Start()
Start starts the client connection, creating go-routines for reading, writing and handlng.
func (*ClientConn) Write ¶
func (cc *ClientConn) Write(message Message) error
Write writes a message to the client.
func (*ClientConn) WriteData ¶
func (cc *ClientConn) WriteData(data []byte) error
type Codec ¶
Codec is the interface for message coder and decoder. Application programmer can define a custom codec themselves.
type ErrUndefined ¶
type ErrUndefined int32
ErrUndefined for undefined message type.
func (ErrUndefined) Error ¶
func (e ErrUndefined) Error() string
type HandlerFunc ¶
type HandlerFunc func(context.Context, WriteCloser)
HandlerFunc serves as an adapter to allow the use of ordinary functions as handlers.
func GetHandlerFunc ¶
func GetHandlerFunc(msgType int32) HandlerFunc
GetHandlerFunc returns the corresponding handler function for msgType.
func (HandlerFunc) Handle ¶
func (f HandlerFunc) Handle(ctx context.Context, c WriteCloser)
Handle calls f(ctx, c)
type Hashable ¶
type Hashable interface {
HashCode() int32
}
Hashable is a interface for hashable object.
type HeartBeatMessage ¶
type HeartBeatMessage struct {
Timestamp int64
}
HeartBeatMessage for application-level keeping alive.
func (HeartBeatMessage) MessageNumber ¶
func (hbm HeartBeatMessage) MessageNumber() int32
MessageNumber returns message number.
func (HeartBeatMessage) Serialize ¶
func (hbm HeartBeatMessage) Serialize() ([]byte, error)
Serialize serializes HeartBeatMessage into bytes.
type Message ¶
Message represents the structured data that can be handled.
func DeserializeHeartBeat ¶
DeserializeHeartBeat deserializes bytes into Message.
func MessageFromContext ¶
MessageFromContext extracts a message from a Context.
type MessageHandler ¶
type MessageHandler struct {
// contains filtered or unexported fields
}
MessageHandler is a combination of message and its handler function.
type OnTimeOut ¶
type OnTimeOut struct { Callback func(time.Time, WriteCloser) Ctx context.Context }
OnTimeOut represents a timed task.
func NewOnTimeOut ¶
NewOnTimeOut returns OnTimeOut.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a server to serve TCP requests.
func NewServer ¶
func NewServer(opt ...ServerOption) *Server
NewServer returns a new TCP server which has not started to serve requests yet.
func ServerFromContext ¶
ServerFromContext returns the server within the context.
func (*Server) Conn ¶
func (s *Server) Conn(id int64) (*ServerConn, bool)
Conn returns a server connection with specified ID.
func (*Server) Start ¶
Start starts the TCP server, accepting new clients and creating service go-routine for each. The service go-routines read messages and then call the registered handlers to handle them. Start returns when failed with fatal errors, the listener willl be closed when returned.
type ServerConn ¶
type ServerConn struct {
// contains filtered or unexported fields
}
ServerConn represents a server connection to a TCP server, it implments Conn.
func NewServerConn ¶
func NewServerConn(id int64, s *Server, c net.Conn) *ServerConn
NewServerConn returns a new server connection which has not started to serve requests yet.
func (*ServerConn) AddPendingTimer ¶
func (sc *ServerConn) AddPendingTimer(timerID int64)
AddPendingTimer adds a timer ID to server Connection.
func (*ServerConn) CancelTimer ¶
func (sc *ServerConn) CancelTimer(timerID int64)
CancelTimer cancels a timer with the specified ID.
func (*ServerConn) Close ¶
func (sc *ServerConn) Close()
Close gracefully closes the server connection. It blocked until all sub go-routines are completed and returned.
func (*ServerConn) ContextValue ¶
func (sc *ServerConn) ContextValue(k interface{}) interface{}
ContextValue gets extra data from server connection.
func (*ServerConn) HeartBeat ¶
func (sc *ServerConn) HeartBeat() int64
HeartBeat returns the heart beats of server connection.
func (*ServerConn) LocalAddr ¶
func (sc *ServerConn) LocalAddr() net.Addr
LocalAddr returns the local address of server connection.
func (*ServerConn) Name ¶
func (sc *ServerConn) Name() string
Name returns the name of server connection.
func (*ServerConn) NetID ¶
func (sc *ServerConn) NetID() int64
NetID returns net ID of server connection.
func (*ServerConn) RemoteAddr ¶
func (sc *ServerConn) RemoteAddr() net.Addr
RemoteAddr returns the remote address of server connection.
func (*ServerConn) RunAfter ¶
func (sc *ServerConn) RunAfter(duration time.Duration, callback func(time.Time, WriteCloser)) int64
RunAfter runs a callback right after the specified duration ellapsed.
func (*ServerConn) RunAt ¶
func (sc *ServerConn) RunAt(timestamp time.Time, callback func(time.Time, WriteCloser)) int64
RunAt runs a callback at the specified timestamp.
func (*ServerConn) RunEvery ¶
func (sc *ServerConn) RunEvery(interval time.Duration, callback func(time.Time, WriteCloser)) int64
RunEvery runs a callback on every interval time.
func (*ServerConn) SetContextValue ¶
func (sc *ServerConn) SetContextValue(k, v interface{})
SetContextValue sets extra data to server connection.
func (*ServerConn) SetHeartBeat ¶
func (sc *ServerConn) SetHeartBeat(heart int64)
SetHeartBeat sets the heart beats of server connection.
func (*ServerConn) SetName ¶
func (sc *ServerConn) SetName(name string)
SetName sets name of server connection.
func (*ServerConn) Start ¶
func (sc *ServerConn) Start()
Start starts the server connection, creating go-routines for reading, writing and handlng.
func (*ServerConn) Write ¶
func (sc *ServerConn) Write(message Message) error
Write writes a message to the client.
type ServerOption ¶
type ServerOption func(*options)
ServerOption sets server options.
func BufferSizeOption ¶
func BufferSizeOption(indicator int) ServerOption
BufferSizeOption returns a ServerOption that is the size of buffered channel, for example an indicator of BufferSize256 means a size of 256.
func CustomCodecOption ¶
func CustomCodecOption(codec Codec) ServerOption
CustomCodecOption returns a ServerOption that will apply a custom Codec.
func OnCloseOption ¶
func OnCloseOption(cb func(WriteCloser)) ServerOption
OnCloseOption returns a ServerOption that will set callback to call when client closed.
func OnConnectOption ¶
func OnConnectOption(cb func(WriteCloser) bool) ServerOption
OnConnectOption returns a ServerOption that will set callback to call when new client connected.
func OnErrorOption ¶
func OnErrorOption(cb func(WriteCloser)) ServerOption
OnErrorOption returns a ServerOption that will set callback to call when error occurs.
func OnMessageOption ¶
func OnMessageOption(cb func(Message, WriteCloser)) ServerOption
OnMessageOption returns a ServerOption that will set callback to call when new message arrived.
func ReconnectOption ¶
func ReconnectOption() ServerOption
ReconnectOption returns a ServerOption that will make ClientConn reconnectable.
func TLSCredsOption ¶
func TLSCredsOption(config *tls.Config) ServerOption
TLSCredsOption returns a ServerOption that will set TLS credentials for server connections.
func WorkerSizeOption ¶
func WorkerSizeOption(workerSz int) ServerOption
WorkerSizeOption returns a ServerOption that will set the number of go-routines in WorkerPool.
type TimingWheel ¶
type TimingWheel struct {
// contains filtered or unexported fields
}
TimingWheel manages all the timed task.
func NewTimingWheel ¶
func NewTimingWheel(ctx context.Context) *TimingWheel
NewTimingWheel returns a *TimingWheel ready for use.
func (*TimingWheel) CancelTimer ¶
func (tw *TimingWheel) CancelTimer(timerID int64)
CancelTimer cancels a timed task with specified timer ID.
func (*TimingWheel) Size ¶
func (tw *TimingWheel) Size() int
Size returns the number of timed tasks.
func (*TimingWheel) TimeOutChannel ¶
func (tw *TimingWheel) TimeOutChannel() chan *OnTimeOut
TimeOutChannel returns the timeout channel.
type TypeLengthValueCodec ¶
type TypeLengthValueCodec struct{}
TypeLengthValueCodec defines a special codec. Format: type-length-value |4 bytes|4 bytes|n bytes <= 8M|
type UnmarshalFunc ¶
UnmarshalFunc unmarshals bytes into Message.
func GetUnmarshalFunc ¶
func GetUnmarshalFunc(msgType int32) UnmarshalFunc
GetUnmarshalFunc returns the corresponding unmarshal function for msgType.
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool is a pool of go-routines running functions.
func WorkerPoolInstance ¶
func WorkerPoolInstance() *WorkerPool
WorkerPoolInstance returns the global pool.
func (*WorkerPool) Close ¶
func (wp *WorkerPool) Close()
Close closes the pool, stopping it from executing functions.
func (*WorkerPool) Put ¶
func (wp *WorkerPool) Put(k interface{}, cb func()) error
Put appends a function to some worker's channel.
type WriteCloser ¶
WriteCloser is the interface that groups Write and Close methods.