Documentation
¶
Index ¶
- func SendBytes2Conn(conn net.Conn, bs []byte) error
- func SetWriteTimeout(d time.Duration)
- type BasicMetaInfo
- type ConnExitEvent
- type ConnHandler
- type ConnReaderFunc
- type ConnSenderFactory
- type ConnStartEvent
- type IConnSender
- type KeyIntBytesPair
- type KeyStrBytesPair
- type MetaInfo
- type QSender
- func (x *QSender) Close() error
- func (x *QSender) Conn() net.Conn
- func (x *QSender) LoopSend()
- func (x *QSender) MetaInfo() MetaInfo
- func (x *QSender) Put2Queue(bs []byte) error
- func (x *QSender) Put2SendMap(_ uint32, bs []byte) error
- func (x *QSender) Put2SendMaps(_ []KeyIntBytesPair) error
- func (x *QSender) Put2SendSMap(_ string, bs []byte) error
- func (x *QSender) Put2SendSMaps(_ []KeyStrBytesPair) error
- func (x *QSender) SetMetaInfo(m MetaInfo)
- type ServerAcceptCnf
- type TcpServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SendBytes2Conn ¶ added in v1.3.0
SendBytes2Conn send bytes to connection Utility function
func SetWriteTimeout ¶ added in v1.2.12
SetWriteTimeout set write timeout Utility function, it's a global setting If not set, default is 5 seconds
Types ¶
type BasicMetaInfo ¶ added in v1.2.12
type BasicMetaInfo struct {
RemoteAddr string
}
BasicMetaInfo basic meta info
func NewBasicMetaInfo ¶ added in v1.3.0
func NewBasicMetaInfo(conn net.Conn) *BasicMetaInfo
NewBasicMetaInfo new basic meta info
func (*BasicMetaInfo) GetRemoteAddr ¶ added in v1.3.0
func (m *BasicMetaInfo) GetRemoteAddr() string
GetRemoteAddr get remote address
func (*BasicMetaInfo) MarshalLogObject ¶ added in v1.2.12
func (m *BasicMetaInfo) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject marshal log object
type ConnExitEvent ¶ added in v1.2.12
type ConnExitEvent func(handler IConnSender)
ConnExitEvent on connection exit
type ConnHandler ¶ added in v1.2.12
type ConnHandler struct {
// contains filtered or unexported fields
}
ConnHandler connection handler
func NewConnRunner ¶ added in v1.3.0
func NewConnRunner(connReader ConnReaderFunc, connSender IConnSender) *ConnHandler
NewConnRunner : new connection runner
func (*ConnHandler) AddExitHook ¶ added in v1.2.12
func (x *ConnHandler) AddExitHook(hook ConnExitEvent)
AddExitHook add exit hook
func (*ConnHandler) AddStartHook ¶ added in v1.2.12
func (x *ConnHandler) AddStartHook(hook ConnStartEvent)
AddStartHook add start hook
func (*ConnHandler) Exit ¶ added in v1.3.0
func (x *ConnHandler) Exit()
Exit : exit connection handler
func (*ConnHandler) GetConnSender ¶ added in v1.3.0
func (x *ConnHandler) GetConnSender() IConnSender
GetConnSender get connection sender
func (*ConnHandler) Start ¶ added in v1.2.12
func (x *ConnHandler) Start()
Start : start connection handler
type ConnReaderFunc ¶ added in v1.3.0
type ConnReaderFunc func(handler IConnSender, conn net.Conn) error
ConnReaderFunc connection reader function
type ConnSenderFactory ¶ added in v1.3.0
type ConnSenderFactory func(conn net.Conn) IConnSender
ConnSenderFactory connection sender factory
type ConnStartEvent ¶ added in v1.2.12
type ConnStartEvent func(handler IConnSender)
ConnStartEvent on connection start
type IConnSender ¶ added in v1.3.0
type IConnSender interface {
// Conn : get connection (required)
Conn() net.Conn
// LoopSend : loop to send (required)
LoopSend()
// SetMetaInfo set meta info (required)
SetMetaInfo(m MetaInfo)
// MetaInfo get meta info (required)
MetaInfo() MetaInfo
// Close : close connection handler
Close() error
// Put2Queue put bytes to send queue (optional)
Put2Queue(bs []byte) error
// Put2SendMap put bytes to send map (optional)
Put2SendMap(key uint32, bs []byte) error
// Put2SendSMap put bytes to send map (optional)
Put2SendSMap(key string, bs []byte) error
// Put2SendMaps put multiple key uint32 and bytes pairs to send map (optional)
Put2SendMaps(pairs []KeyIntBytesPair) error
// Put2SendSMaps put multiple key string and bytes pairs to send map (optional)
Put2SendSMaps(pairs []KeyStrBytesPair) error
}
IConnSender connection handler interface all methods are goroutine safe user must implement this interface Conn/LoopSend/SetMetaInfo/MetaInfo/Close are required Put2Queue/Put2SendMap/Put2SendSMap/Put2SendMaps/Put2SendSMaps are optional, but at least one of them should be implemented, others can be no-op
type KeyIntBytesPair ¶ added in v1.3.0
KeyIntBytesPair key uint32 and bytes pair
type KeyStrBytesPair ¶ added in v1.3.0
KeyStrBytesPair key string and bytes pair
type MetaInfo ¶ added in v1.2.12
type MetaInfo interface {
zapcore.ObjectMarshaler
GetRemoteAddr() string
}
MetaInfo meta info for logging
type QSender ¶ added in v1.3.0
type QSender struct {
// contains filtered or unexported fields
}
QSender queue send connection sender send queue based connection sender user can put bytes to send queue async and LoopSend will send bytes in queue one by one
func NewQSendConnHandler ¶ added in v1.3.0
NewQSendConnHandler : new queue send connection handler sendQSize : send queue size, if sendQSize is 0, the send queue has unlimited capacity
otherwise, the send queue has limited capacity. if the send queue is full, Put2Queue will return error
func (*QSender) LoopSend ¶ added in v1.3.0
func (x *QSender) LoopSend()
LoopSend : loop to send (required)
func (*QSender) Put2SendMap ¶ added in v1.3.0
Put2SendMap put bytes to send map (not supported)
func (*QSender) Put2SendMaps ¶ added in v1.3.0
func (x *QSender) Put2SendMaps(_ []KeyIntBytesPair) error
Put2SendMaps put multiple key uint32 and bytes pairs to send map (not supported)
func (*QSender) Put2SendSMap ¶ added in v1.3.0
Put2SendSMap put bytes to send map (not supported)
func (*QSender) Put2SendSMaps ¶ added in v1.3.0
func (x *QSender) Put2SendSMaps(_ []KeyStrBytesPair) error
Put2SendSMaps put multiple key string and bytes pairs to send map (not supported)
func (*QSender) SetMetaInfo ¶ added in v1.3.0
SetMetaInfo set meta info (required)
type ServerAcceptCnf ¶ added in v1.2.12
type ServerAcceptCnf struct {
Address string `json:"address"`
AcceptDelay timex.Duration `json:"acceptDelay"`
AcceptMaxDelay timex.Duration `json:"acceptMaxDelay"`
AcceptMaxRetry int `json:"acceptMaxRetry"`
MaxConn int32 `json:"maxConn"`
}
ServerAcceptCnf server start config
func DefaultServerAcceptCnf ¶ added in v1.2.12
func DefaultServerAcceptCnf() *ServerAcceptCnf
DefaultServerAcceptCnf : get default start cnf
type TcpServer ¶ added in v1.3.0
type TcpServer struct {
// contains filtered or unexported fields
}
TcpServer tcp server
func NewTcpServer ¶ added in v1.3.0
func NewTcpServer(cnf *ServerAcceptCnf, connReader ConnReaderFunc, connSenderFactory ConnSenderFactory) *TcpServer
NewTcpServer : new tcp server
func (*TcpServer) Run ¶ added in v1.3.0
Run : run server errChan : error channel if server exit, the error will be sent to errChan
func (*TcpServer) SetExitHooker ¶ added in v1.3.0
func (x *TcpServer) SetExitHooker(hooker ConnExitEvent)
SetExitHooker : set connection exit hooker
func (*TcpServer) SetStartHooker ¶ added in v1.3.0
func (x *TcpServer) SetStartHooker(hooker ConnStartEvent)
SetStartHooker : set connection start hooker