Documentation ¶
Index ¶
- Constants
- Variables
- func GetLocalAddr() ([]string, error)
- func NewListener(addr string, opt *SocketOpt) (net.Listener, error)
- func Ping(addr string, to time.Duration) error
- func ServeHttp(tag string, addr string, handler http.Handler, timeout time.Duration, ...)
- func ServeHttps(tag string, addr string, handler http.Handler, timeout time.Duration, ...)
- type CipherGzip
- type CodecGob
- type CodecJson
- type CodecMsgpack
- type CodecProtobuf
- type HttpHandlerWrapper
- type HttpServer
- type ICipher
- type ICodec
- type IMessage
- type Listener
- type Message
- func (msg *Message) Body() []byte
- func (msg *Message) BodyLen() int
- func (msg *Message) Cmd() uint32
- func (msg *Message) Data() []byte
- func (msg *Message) Decrypt(seq int64, key uint32, cipher ICipher) ([]byte, error)
- func (msg *Message) Encrypt(seq int64, key uint32, cipher ICipher) []byte
- func (msg *Message) Ext() int64
- func (msg *Message) SetBody(data []byte)
- func (msg *Message) SetCmd(cmd uint32)
- func (msg *Message) SetData(data []byte)
- func (msg *Message) SetExt(ext int64)
- type RpcClient
- func (client *RpcClient) Call(method string, req interface{}, rsp interface{}, timeout time.Duration) error
- func (client *RpcClient) CallCmd(cmd uint32, req interface{}, rsp interface{}) error
- func (client *RpcClient) CallCmdWithTimeout(cmd uint32, req interface{}, rsp interface{}, timeout time.Duration) error
- func (client *RpcClient) CallWithTimer(method string, req interface{}, rsp interface{}, after *time.Timer) error
- func (client *RpcClient) Codec() ICodec
- type RpcContext
- func (ctx *RpcContext) Bind(v interface{}) error
- func (ctx *RpcContext) BindGob(v interface{}) error
- func (ctx *RpcContext) BindJson(v interface{}) error
- func (ctx *RpcContext) BindMsgpack(v interface{}) error
- func (ctx *RpcContext) BindProtobuf(v proto.Message) error
- func (ctx *RpcContext) Body() []byte
- func (ctx *RpcContext) Client() *TcpClient
- func (ctx *RpcContext) Cmd() uint32
- func (ctx *RpcContext) Error(errText string) error
- func (ctx *RpcContext) Method() string
- func (ctx *RpcContext) Write(v interface{}) error
- func (ctx *RpcContext) WriteData(data []byte) error
- func (ctx *RpcContext) WriteGob(v interface{}) error
- func (ctx *RpcContext) WriteJson(v interface{}) error
- func (ctx *RpcContext) WriteMsg(msg IMessage) error
- func (ctx *RpcContext) WriteMsgpack(v interface{}) error
- func (ctx *RpcContext) WriteProtobuf(v proto.Message) error
- type RpcMessage
- type SocketOpt
- type TcpClient
- func (client *TcpClient) Bind(data []byte, v interface{}) error
- func (client *TcpClient) CancelOnClose(tag interface{})
- func (client *TcpClient) Cipher() ICipher
- func (client *TcpClient) Ip() string
- func (client *TcpClient) Keepalive(interval time.Duration)
- func (client *TcpClient) OnClose(tag interface{}, cb func(client *TcpClient))
- func (client *TcpClient) Port() int
- func (client *TcpClient) Reader() io.Reader
- func (client *TcpClient) RecvKey() uint32
- func (client *TcpClient) RecvSeq() int64
- func (client *TcpClient) SendData(data []byte) error
- func (client *TcpClient) SendDataWithCallback(data []byte, cb func(*TcpClient, error)) error
- func (client *TcpClient) SendKey() uint32
- func (client *TcpClient) SendMsg(msg IMessage) error
- func (client *TcpClient) SendMsgWithCallback(msg IMessage, cb func(*TcpClient, error)) error
- func (client *TcpClient) SendSeq() int64
- func (client *TcpClient) SetCipher(cipher ICipher)
- func (client *TcpClient) SetRealIp(ip string)
- func (client *TcpClient) SetUserData(data interface{})
- func (client *TcpClient) Shutdown() error
- func (client *TcpClient) Stop() error
- func (client *TcpClient) UserData() interface{}
- type TcpEngin
- func (engine *TcpEngin) BroadCast(msg IMessage)
- func (engine *TcpEngin) CreateClient(conn *net.TCPConn, parent *TcpEngin, cipher ICipher) *TcpClient
- func (engine *TcpEngin) DefaultCreateClientHandler(conn *net.TCPConn, parent *TcpEngin, cipher ICipher) *TcpClient
- func (engine *TcpEngin) DefaultNewConnHandler(conn *net.TCPConn) error
- func (engine *TcpEngin) DefaultOnMessage(client *TcpClient, msg IMessage)
- func (engine *TcpEngin) DefaultRecvMsg(client *TcpClient) IMessage
- func (engine *TcpEngin) DefaultSend(client *TcpClient, data []byte) error
- func (engine *TcpEngin) Handle(cmd uint32, handler func(client *TcpClient, msg IMessage))
- func (engine *TcpEngin) HandleCreateClient(...)
- func (engine *TcpEngin) HandleDisconnected(onDisconnected func(client *TcpClient))
- func (engine *TcpEngin) HandleMessage(onMsg func(client *TcpClient, msg IMessage))
- func (engine *TcpEngin) HandleNewCipher(newCipher func() ICipher)
- func (engine *TcpEngin) HandleNewClient(onNewClient func(client *TcpClient))
- func (engine *TcpEngin) HandleNewConn(onNewConn func(conn *net.TCPConn) error)
- func (engine *TcpEngin) HandleRecv(recver func(client *TcpClient) IMessage)
- func (engine *TcpEngin) HandleRpcCmd(cmd uint32, handler func(ctx *RpcContext), async bool)
- func (engine *TcpEngin) HandleRpcMethod(method string, handler func(ctx *RpcContext), args ...interface{})
- func (engine *TcpEngin) HandleSend(sender func(client *TcpClient, data []byte) error)
- func (engine *TcpEngin) HandleSendQueueFull(h func(*TcpClient, interface{}))
- func (engine *TcpEngin) MultiSetRealIpEnabled() bool
- func (engine *TcpEngin) NewCipher() ICipher
- func (engine *TcpEngin) OnDisconnected(client *TcpClient)
- func (engine *TcpEngin) OnMessage(client *TcpClient, msg IMessage)
- func (engine *TcpEngin) OnNewClient(client *TcpClient)
- func (engine *TcpEngin) OnNewConn(conn *net.TCPConn) error
- func (engine *TcpEngin) OnSendQueueFull(client *TcpClient, msg interface{})
- func (engine *TcpEngin) RecvMsg(client *TcpClient) IMessage
- func (engine *TcpEngin) Send(client *TcpClient, data []byte) error
- func (engine *TcpEngin) SendQueueSize() int
- func (engine *TcpEngin) SetMultiSetRealIpEnabled(enable bool)
- func (engine *TcpEngin) SetSendQueueSize(size int)
- func (engine *TcpEngin) SetSockBufioReaderEnabled(enable bool)
- func (engine *TcpEngin) SetSockKeepAlive(enable bool)
- func (engine *TcpEngin) SetSockKeepaliveTime(keepaliveTime time.Duration)
- func (engine *TcpEngin) SetSockLingerSeconds(sec int)
- func (engine *TcpEngin) SetSockMaxPackLen(maxPackLen int)
- func (engine *TcpEngin) SetSockNoDelay(enable bool)
- func (engine *TcpEngin) SetSockRecvBlockTime(recvBlockTime time.Duration)
- func (engine *TcpEngin) SetSockRecvBufLen(recvBufLen int)
- func (engine *TcpEngin) SetSockSendBlockTime(sendBlockTime time.Duration)
- func (engine *TcpEngin) SetSockSendBufLen(sendBufLen int)
- func (engine *TcpEngin) SockBufioReaderEnabled() bool
- func (engine *TcpEngin) SockKeepAlive() bool
- func (engine *TcpEngin) SockKeepaliveTime() time.Duration
- func (engine *TcpEngin) SockLingerSeconds() int
- func (engine *TcpEngin) SockMaxPackLen() int
- func (engine *TcpEngin) SockNoDelay() bool
- func (engine *TcpEngin) SockRecvBlockTime() time.Duration
- func (engine *TcpEngin) SockRecvBufLen() int
- func (engine *TcpEngin) SockSendBlockTime() time.Duration
- func (engine *TcpEngin) SockSendBufLen() int
- type TcpServer
- func (server *TcpServer) AcceptedNum() int64
- func (server *TcpServer) Broadcast(msg IMessage)
- func (server *TcpServer) BroadcastWithFilter(msg IMessage, filter func(*TcpClient) bool)
- func (server *TcpServer) CurrLoad() int64
- func (server *TcpServer) EnableBroadcast()
- func (server *TcpServer) HandleServerStop(stopHandler func(server *TcpServer))
- func (server *TcpServer) MaxLoad() int64
- func (server *TcpServer) Serve(addr string, stopTimeout time.Duration)
- func (server *TcpServer) SetMaxConcurrent(maxLoad int64)
- func (server *TcpServer) Start(addr string) error
- func (server *TcpServer) Stop()
- func (server *TcpServer) StopWithTimeout(stopTimeout time.Duration, onStopTimeout func())
- type WSClient
- func (cli *WSClient) Bind(data []byte, v interface{}) error
- func (cli *WSClient) CancelOnClose(tag interface{})
- func (cli *WSClient) Cipher() ICipher
- func (cli *WSClient) Ip() string
- func (cli *WSClient) Keepalive(interval time.Duration)
- func (cli *WSClient) OnClose(tag interface{}, cb func(client *WSClient))
- func (cli *WSClient) Port() int
- func (cli *WSClient) RecvKey() uint32
- func (cli *WSClient) RecvSeq() int64
- func (cli *WSClient) SendData(data []byte) error
- func (cli *WSClient) SendDataWithCallback(data []byte, cb func(*WSClient, error)) error
- func (cli *WSClient) SendKey() uint32
- func (cli *WSClient) SendMsg(msg IMessage) error
- func (cli *WSClient) SendMsgWithCallback(msg IMessage, cb func(*WSClient, error)) error
- func (cli *WSClient) SendSeq() int64
- func (cli *WSClient) SetCipher(cipher ICipher)
- func (cli *WSClient) SetRealIp(ip string)
- func (cli *WSClient) SetUserData(data interface{})
- func (cli *WSClient) Stop()
- func (cli *WSClient) UserData() interface{}
- type WSEngine
- func (engine *WSEngine) Handle(cmd uint32, h func(cli *WSClient, msg IMessage))
- func (engine *WSEngine) HandleMessage(h func(cli *WSClient, msg IMessage))
- func (engine *WSEngine) HandleNewCipher(newCipher func() ICipher)
- func (engine *WSEngine) HandleRecv(recver func(cli *WSClient) IMessage)
- func (engine *WSEngine) HandleSend(sender func(cli *WSClient, data []byte) error)
- func (engine *WSEngine) HandleSendQueueFull(h func(cli *WSClient, msg interface{}))
- func (engine *WSEngine) NewCipher() ICipher
- func (engine *WSEngine) OnSendQueueFull(cli *WSClient, msg interface{})
- func (engine *WSEngine) RecvMsg(cli *WSClient) IMessage
- func (engine *WSEngine) Send(cli *WSClient, data []byte) error
- type WSServer
- func (s *WSServer) ClientNum() int
- func (server *WSServer) CurrLoad() int64
- func (s *WSServer) HandleConnect(h func(cli *WSClient, w http.ResponseWriter, r *http.Request) error)
- func (s *WSServer) HandleDisconnect(h func(cli *WSClient, w http.ResponseWriter, r *http.Request))
- func (s *WSServer) HandleHttp(h func(w http.ResponseWriter, r *http.Request))
- func (s *WSServer) HandleRequest(h func(w http.ResponseWriter, r *http.Request) error)
- func (s *WSServer) HandleWs(path string)
- func (server *WSServer) MaxLoad() int64
- func (s *WSServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (server *WSServer) SetMaxConcurrent(maxLoad int64)
- func (s *WSServer) SetUpgrader(upgrader *websocket.Upgrader)
- func (s *WSServer) Shutdown(timeout time.Duration, cb func(error))
Constants ¶
const ( CipherGzipAll = 0 CipherGzipNone = -1 DefaultThreshold = CipherGzipNone )
const ( // default message header length DEFAULT_MESSAGE_HEAD_LEN int = 16 // default body length begin idx DEFAULT_BODY_LEN_IDX_BEGIN int = 0 // default body length end idx DEFAULT_BODY_LEN_IDX_END int = 4 // default cmd begin idx DEFAULT_CMD_IDX_BEGIN int = 4 // default cmd end idx DEFAULT_CMD_IDX_END int = 8 // default extension begin idx DEFAULT_EXT_IDX_BEGIN int = 8 // default extension end idx DEFAULT_EXT_IDX_END int = 16 // default gzip cipher flag mask CmdFlagMaskGzip = uint32(1) << 31 // reserved cmd: ping CmdPing = uint32(0x1 << 24) // reserved cmd: ping2 CmdPing2 = uint32(0x1<<24 + 1) // reserved cmd: set real ip CmdSetReaIp = uint32(0x1<<24 + 2) // reserved cmd: rpc method CmdRpcMethod = uint32(0x1<<24 + 3) // reserved cmd: rpc error CmdRpcError = uint32(0x1<<24 + 4) // max user space cmd CmdUserMax = uint32(0xFFFFFF) )
Variables ¶
var ( DefaultCodec = json DefaultRpcCodecType = "json" )
var ( // default tcp nodlay DefaultSockNodelay = true // default tcp keepalive DefaultSockKeepalive = false // default tcp bufio reader DefaultSockBufioReaderEnabled = false // default tcp client send queue size DefaultSendQSize = 512 // default tcp client read buf length DefaultSockRecvBufLen = 1024 // default tcp client write buf length DefaultSockSendBufLen = 1024 // default max tcp client packet length DefaultSockPackMaxLen = 1024 * 1024 // default tcp client linger time DefaultSockLingerSeconds = 0 // default tcp client keepalive interval DefaultSockKeepaliveTime = time.Second * 60 // default tcp client read block time DefaultSockRecvBlockTime = time.Second * 65 // default tcp client write block time DefaultSockSendBlockTime = time.Second * 5 // default rpc send queue size DefaultSockRpcSendQSize = 8192 // default rpc read block time DefaultSockRpcRecvBlockTime = time.Second * 3600 * 24 // default max concurrent DefaultMaxOnline = int64(40960) // default read block time DefaultReadTimeout = time.Second * 35 // default write block time DefaultWriteTimeout = time.Second * 5 // default shutdown timeout DefaultShutdownTimeout = time.Second * 5 // default max websocket read length DefaultReadLimit int64 = 1024 * 1024 // default enable set real ip multi times DefaultEnableMultiSetRealIp = false )
var ( ErrTcpClientIsStopped = errors.New("tcp client is stopped") ErrTcpClientWriteHalf = errors.New("tcp client write half") ErrTcpClientSendQueueIsFull = errors.New("tcp client's send queue is full") ErrRpcClientIsDisconnected = errors.New("rpc client disconnected") ErrRpcClientSendQueueIsFull = errors.New("rpc client's send queue is full") ErrRpcCallTimeout = errors.New("rpc call timeout") ErrRpcCallClientError = errors.New("rpc client error") ErrorRpcInvalidMessageHeadLen = errors.New("invalid Message Head Len") ErrorRpcInvalidPbMessage = errors.New("invalid pb Message") ErrorBroadcastNotEnabled = errors.New("broadcast not enabled") ErrorReservedCmdInternal = fmt.Errorf("cmd > %d/0x%X is reserved for internal, plz use other number", CmdUserMax, CmdUserMax) ErrorReservedCmdPing = fmt.Errorf("cmd %d/0x%X is reserved for ping, plz use other number", CmdPing, CmdPing) ErrorReservedCmdSetRealip = fmt.Errorf("cmd %d/0x%X is reserved for set client's real ip, plz use other number", CmdSetReaIp, CmdSetReaIp) ErrorReservedCmdRpcMethod = fmt.Errorf("cmd %d/0x%X is reserved for rpc method, plz use other number", CmdRpcMethod, CmdRpcMethod) ErrorReservedCmdRpcError = fmt.Errorf("cmd %d/0x%X is reserved for rpc method error, plz use other number", CmdRpcError, CmdRpcError) ErrWSClientIsStopped = errors.New("websocket client is stopped") ErrWSClientSendQueueIsFull = errors.New("websocket client's send queue is full") ErrClientWithoutCodec = errors.New("websocket client has no codec") ErrWSEngineShutdownTimeout = errors.New("shutdown timeout") )
errors
var (
ErrInvalidBody = errors.New("invalid body")
)
Functions ¶
func NewListener ¶
tcp listener factory
Types ¶
type CipherGzip ¶
type CipherGzip struct {
// contains filtered or unexported fields
}
default cipher with gzip
func (*CipherGzip) Encrypt ¶
func (cipher *CipherGzip) Encrypt(seq int64, key uint32, data []byte) []byte
encrypt message
func (*CipherGzip) Init ¶
func (cipher *CipherGzip) Init()
type CodecMsgpack ¶
type CodecMsgpack struct{}
msgpack codec
func (*CodecMsgpack) Marshal ¶
func (c *CodecMsgpack) Marshal(v interface{}) ([]byte, error)
marshal
func (*CodecMsgpack) Unmarshal ¶
func (c *CodecMsgpack) Unmarshal(data []byte, v interface{}) error
unmarshal
type CodecProtobuf ¶
type CodecProtobuf struct{}
protobuf codec
func (*CodecProtobuf) Marshal ¶
func (c *CodecProtobuf) Marshal(v interface{}) ([]byte, error)
marshal
func (*CodecProtobuf) Unmarshal ¶
func (c *CodecProtobuf) Unmarshal(data []byte, v interface{}) error
unmarshal
type HttpHandlerWrapper ¶
http middleware
func (*HttpHandlerWrapper) EnablePProf ¶
func (wrapper *HttpHandlerWrapper) EnablePProf(root string)
enable pprof
func (*HttpHandlerWrapper) ServeHTTP ¶
func (wrapper *HttpHandlerWrapper) ServeHTTP(w http.ResponseWriter, r *http.Request)
serve http
type HttpServer ¶
type HttpServer struct {
// contains filtered or unexported fields
}
http server
func NewHttpServer ¶
func NewHttpServer(tag string, addr string, handler http.Handler, to time.Duration, opt *SocketOpt, onTimeout func()) (*HttpServer, error)
http server factory
func (*HttpServer) SetSocketOpt ¶
func (svr *HttpServer) SetSocketOpt(opt *SocketOpt)
setting tcp socket option
type ICipher ¶
type ICipher interface { Init() Encrypt(seq int64, key uint32, data []byte) []byte Decrypt(seq int64, key uint32, data []byte) ([]byte, error) }
cipher interface
func NewCipherGzip ¶
type ICodec ¶
type ICodec interface { Marshal(v interface{}) ([]byte, error) Unmarshal(data []byte, v interface{}) error }
codec interface
type IMessage ¶
type IMessage interface { // message body length BodyLen() int // message cmd Cmd() uint32 // setting message cmd SetCmd(cmd uint32) // message extension Ext() int64 // setting message extension SetExt(ext int64) // all message data Data() []byte // setting all message data SetData(data []byte) // message body Body() []byte // setting message body SetBody(body []byte) // encrypt message Encrypt(seq int64, key uint32, cipher ICipher) []byte // decrypt message Decrypt(seq int64, key uint32, cipher ICipher) ([]byte, error) }
message interface
type Listener ¶
type Listener struct { *net.TCPListener // contains filtered or unexported fields }
tcp listener
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
default message implementation
func NewRpcMessage ¶
rpc message factory
type RpcClient ¶
type RpcClient struct { *TcpClient // contains filtered or unexported fields }
rpc client
func NewRpcClient ¶
func NewRpcClient(addr string, engine *TcpEngin, codec ICodec, onConnected func(*RpcClient)) (*RpcClient, error)
rpc client factory
func (*RpcClient) Call ¶
func (client *RpcClient) Call(method string, req interface{}, rsp interface{}, timeout time.Duration) error
rpc call
func (*RpcClient) CallCmdWithTimeout ¶
func (client *RpcClient) CallCmdWithTimeout(cmd uint32, req interface{}, rsp interface{}, timeout time.Duration) error
call cmd with timeout
type RpcContext ¶
type RpcContext struct {
// contains filtered or unexported fields
}
rpc context
func (*RpcContext) BindMsgpack ¶
func (ctx *RpcContext) BindMsgpack(v interface{}) error
bind msgpack data
func (*RpcContext) BindProtobuf ¶
func (ctx *RpcContext) BindProtobuf(v proto.Message) error
bind protobuf data
func (*RpcContext) Write ¶
func (ctx *RpcContext) Write(v interface{}) error
write data marshal by default codec
func (*RpcContext) WriteJson ¶
func (ctx *RpcContext) WriteJson(v interface{}) error
write json data
func (*RpcContext) WriteMsgpack ¶
func (ctx *RpcContext) WriteMsgpack(v interface{}) error
write msgpack data
func (*RpcContext) WriteProtobuf ¶
func (ctx *RpcContext) WriteProtobuf(v proto.Message) error
write protobuf data
type SocketOpt ¶
type SocketOpt struct { NoDelay bool Keepalive bool KeepaliveInterval time.Duration ReadBufLen int WriteBufLen int ReadTimeout time.Duration ReadHeaderTimeout time.Duration WriteTimeout time.Duration MaxHeaderBytes int }
tcp socket option
type TcpClient ¶
type TcpClient struct { sync.RWMutex // tcp connection Conn *net.TCPConn // contains filtered or unexported fields }
tcp client
func NewTcpClient ¶
func (*TcpClient) CancelOnClose ¶
func (client *TcpClient) CancelOnClose(tag interface{})
unsetting close handler
func (*TcpClient) SendDataWithCallback ¶
send data with callback
func (*TcpClient) SendMsgWithCallback ¶
send message with callback
func (*TcpClient) SetUserData ¶
func (client *TcpClient) SetUserData(data interface{})
setting user data
type TcpEngin ¶
type TcpEngin struct { sync.RWMutex // graceful sync.WaitGroup // codec Codec ICodec // new connection handler OnNewConnHandler func(conn *net.TCPConn) error // create tcp client handler CreateClientHandler func(conn *net.TCPConn, parent *TcpEngin, cipher ICipher) *TcpClient // new tcp client handler OnNewClientHandler func(client *TcpClient) // new cipher handler NewCipherHandler func() ICipher // tcp client disconnected handler OnDisconnectedHandler func(client *TcpClient) // tcp client send queue full handler SendQueueFullHandler func(*TcpClient, interface{}) // tcp client receive handler RecvHandler func(client *TcpClient) IMessage // tcp client send handler SendHandler func(client *TcpClient, data []byte) error // tcp client message handler OnMsgHandler func(client *TcpClient, msg IMessage) // contains filtered or unexported fields }
tcp engine
func (*TcpEngin) CreateClient ¶
func (engine *TcpEngin) CreateClient(conn *net.TCPConn, parent *TcpEngin, cipher ICipher) *TcpClient
create client
func (*TcpEngin) DefaultCreateClientHandler ¶
func (engine *TcpEngin) DefaultCreateClientHandler(conn *net.TCPConn, parent *TcpEngin, cipher ICipher) *TcpClient
create client
func (*TcpEngin) DefaultNewConnHandler ¶
on new connection
func (*TcpEngin) DefaultOnMessage ¶
func (*TcpEngin) DefaultRecvMsg ¶
recv message
func (*TcpEngin) DefaultSend ¶
tcp client send data
func (*TcpEngin) HandleCreateClient ¶
func (engine *TcpEngin) HandleCreateClient(createClient func(conn *net.TCPConn, parent *TcpEngin, cipher ICipher) *TcpClient)
setting create tcp client handler
func (*TcpEngin) HandleDisconnected ¶
setting disconnected handler
func (*TcpEngin) HandleMessage ¶
setting message handler
func (*TcpEngin) HandleNewCipher ¶
setting new cipher handler
func (*TcpEngin) HandleNewClient ¶
setting new client handler
func (*TcpEngin) HandleNewConn ¶
handle new connection
func (*TcpEngin) HandleRecv ¶
setting receive message handler
func (*TcpEngin) HandleRpcCmd ¶
func (engine *TcpEngin) HandleRpcCmd(cmd uint32, handler func(ctx *RpcContext), async bool)
handle rpc cmd
func (*TcpEngin) HandleRpcMethod ¶
func (engine *TcpEngin) HandleRpcMethod(method string, handler func(ctx *RpcContext), args ...interface{})
setting handle rpc method
func (*TcpEngin) HandleSend ¶
setting tcp client send data handler
func (*TcpEngin) HandleSendQueueFull ¶
setting tcp client send queue full handler
func (*TcpEngin) MultiSetRealIpEnabled ¶
multi set realip
func (*TcpEngin) OnDisconnected ¶
on disconnected
func (*TcpEngin) OnSendQueueFull ¶
on tcp client send queue full
func (*TcpEngin) SetMultiSetRealIpEnabled ¶
setting multi set realip
func (*TcpEngin) SetSendQueueSize ¶
setting socket send queue size
func (*TcpEngin) SetSockBufioReaderEnabled ¶
setting socket bufio reader
func (*TcpEngin) SetSockKeepAlive ¶
setting socket keepalive
func (*TcpEngin) SetSockKeepaliveTime ¶
setting socket keepalive interval
func (*TcpEngin) SetSockLingerSeconds ¶
setting socket linger time
func (*TcpEngin) SetSockMaxPackLen ¶
setting socket max packet length
func (*TcpEngin) SetSockNoDelay ¶
setting socket nodelay
func (*TcpEngin) SetSockRecvBlockTime ¶
setting socket receive block time
func (*TcpEngin) SetSockRecvBufLen ¶
setting socket receive buf length
func (*TcpEngin) SetSockSendBlockTime ¶
setting socket send block time
func (*TcpEngin) SetSockSendBufLen ¶
setting send receive buf length
func (*TcpEngin) SockBufioReaderEnabled ¶
socket bufio reader
func (*TcpEngin) SockKeepaliveTime ¶
socket keepalive interval
func (*TcpEngin) SockLingerSeconds ¶
socket linger time
func (*TcpEngin) SockMaxPackLen ¶
socket max packet length
func (*TcpEngin) SockRecvBlockTime ¶
socket receive block time
func (*TcpEngin) SockRecvBufLen ¶
socket receive buf length
func (*TcpEngin) SockSendBlockTime ¶
socket send block time
func (*TcpEngin) SockSendBufLen ¶
socket send buf length
type TcpServer ¶
type TcpServer struct { *TcpEngin // contains filtered or unexported fields }
tcp server
func (*TcpServer) BroadcastWithFilter ¶
broadcast with filter
func (*TcpServer) HandleServerStop ¶
setting server stop handler
func (*TcpServer) SetMaxConcurrent ¶
set max concurrent
func (*TcpServer) StopWithTimeout ¶
stop with timeout
type WSClient ¶
type WSClient struct { *WSEngine sync.RWMutex // websocket connection Conn *websocket.Conn // contains filtered or unexported fields }
websocket client
func NewWebsocketClient ¶
websocket client factory
func NewWebsocketTLSClient ¶
func (*WSClient) CancelOnClose ¶
func (cli *WSClient) CancelOnClose(tag interface{})
unsetting close handler
func (*WSClient) SendDataWithCallback ¶
send data with callback
func (*WSClient) SendMsgWithCallback ¶
send message with callback
type WSEngine ¶
type WSEngine struct { sync.Mutex sync.WaitGroup // 序列化 Codec ICodec // 读超时时间 ReadTimeout time.Duration // 写超时时间 WriteTimeout time.Duration // 读最大包长限制 ReadLimit int64 // 发送队列容量 SendQSize int // websocket消息类型 MessageType int // contains filtered or unexported fields }
websocket engine
func (*WSEngine) HandleMessage ¶
setting user defined message handler
func (*WSEngine) HandleNewCipher ¶
setting new cipher handler
func (*WSEngine) HandleRecv ¶
setting receive message handler
func (*WSEngine) HandleSend ¶
setting send message handler
func (*WSEngine) HandleSendQueueFull ¶
setting send queue full handler
func (*WSEngine) OnSendQueueFull ¶
handle send queue full
type WSServer ¶
type WSServer struct { *WSEngine // http server *HttpServer // contains filtered or unexported fields }
func NewWebsocketServer ¶
websocket server factory
func (*WSServer) HandleConnect ¶
func (s *WSServer) HandleConnect(h func(cli *WSClient, w http.ResponseWriter, r *http.Request) error)
setting websocket connection handler
func (*WSServer) HandleDisconnect ¶
setting websocket disconnected handler
func (*WSServer) HandleHttp ¶
func (s *WSServer) HandleHttp(h func(w http.ResponseWriter, r *http.Request))
setting http router
func (*WSServer) HandleRequest ¶
setting request handler
func (*WSServer) ServeHTTP ¶
func (s *WSServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
serve http
func (*WSServer) SetMaxConcurrent ¶
setting max concurrent
func (*WSServer) SetUpgrader ¶
setting websocket upgrader