Documentation
¶
Index ¶
- func SendBytes2Conn(conn net.Conn, bs []byte) error
- func SetWriteTimeout(d time.Duration)
- type BasicMetaInfo
- type ConnExitEvent
- type ConnHandler
- type ConnIOFactory
- type ConnReaderFactory
- type ConnStartEvent
- type IConnIO
- type IConnReader
- type IConnSender
- type KeyIntBytesPair
- type KeyStrBytesPair
- type MetaInfo
- type QSendConn
- func (x *QSendConn) Close() error
- func (x *QSendConn) Conn() net.Conn
- func (x *QSendConn) MetaInfo() MetaInfo
- func (x *QSendConn) Put2Queue(bs []byte) error
- func (x *QSendConn) Put2SendMap(_ uint32, bs []byte) error
- func (x *QSendConn) Put2SendMaps(_ []KeyIntBytesPair) error
- func (x *QSendConn) Put2SendSMap(_ string, bs []byte) error
- func (x *QSendConn) Put2SendSMaps(_ []KeyStrBytesPair) error
- func (x *QSendConn) ReadFrame() ([]byte, error)
- func (x *QSendConn) SetMetaInfo(m MetaInfo)
- type ReadProcessor
- 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(iConnIO IConnIO)
ConnExitEvent on connection exit
type ConnHandler ¶ added in v1.2.12
type ConnHandler struct {
// contains filtered or unexported fields
}
ConnHandler connection handler
func NewConnHandler ¶ added in v1.2.12
func NewConnHandler(readerProcessor ReadProcessor, iConnIO IConnIO) *ConnHandler
NewConnHandler : new connection handler
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) GetIConn ¶ added in v1.3.3
func (x *ConnHandler) GetIConn() IConnIO
GetIConn get connection interface
func (*ConnHandler) Start ¶ added in v1.2.12
func (x *ConnHandler) Start()
Start : start connection handler
type ConnIOFactory ¶ added in v1.3.3
ConnIOFactory connection io factory
type ConnReaderFactory ¶ added in v1.3.3
type ConnReaderFactory func(conn net.Conn) IConnReader
ConnReaderFactory connection reader factory
type ConnStartEvent ¶ added in v1.2.12
type ConnStartEvent func(iConnIO IConnIO)
ConnStartEvent on connection start
type IConnIO ¶ added in v1.3.3
type IConnIO interface {
// IConnSender connection sender interface
IConnSender
// IConnReader connection reader interface
IConnReader
}
IConnIO connection io interface
Thread Safety & Re-entrance Requirements: - ALL methods except loopSend() MUST be goroutine-safe and re-entrant - Multiple calls to Close() should be safe (may return error but MUST NOT panic) - Resource cleanup operations should be idempotent
Method Categories:
- Required: Conn/SetMetaInfo/MetaInfo/Close/loopSend
- Optional: Put2Queue/Put2SendMap/Put2SendSMap/Put2SendMaps/Put2SendSMaps (at least one Put2* method should be implemented, others can be no-op)
Special Notes: - loopSend() is ONLY called by ConnHandler internally, NEVER call it from external code - loopSend() runs in its own goroutine and handles the sending loop logic
type IConnReader ¶ added in v1.3.3
type IConnReader interface {
// ReadFrame reads one frame from connection
ReadFrame() ([]byte, error)
}
IConnReader connection reader interface
type IConnSender ¶ added in v1.3.0
type IConnSender interface {
// Conn returns the underlying network connection (required, goroutine-safe)
Conn() net.Conn
// SetMetaInfo sets meta info for logging (required, goroutine-safe, re-entrant)
SetMetaInfo(m MetaInfo)
// MetaInfo gets meta info for logging (required, goroutine-safe)
MetaInfo() MetaInfo
// Close closes the connection (required, goroutine-safe, re-entrant)
// Multiple calls should be safe, may return error but MUST NOT panic
Close() error
// Put2Queue puts bytes to send queue (optional, goroutine-safe, re-entrant)
Put2Queue(bs []byte) error
// Put2SendMap puts bytes to send map (optional, goroutine-safe, re-entrant)
Put2SendMap(key uint32, bs []byte) error
// Put2SendSMap puts bytes to send map (optional, goroutine-safe, re-entrant)
Put2SendSMap(key string, bs []byte) error
// Put2SendMaps puts multiple key uint32 and bytes pairs to send map (optional, goroutine-safe, re-entrant)
Put2SendMaps(pairs []KeyIntBytesPair) error
// Put2SendSMaps puts multiple key string and bytes pairs to send map (optional, goroutine-safe, re-entrant)
Put2SendSMaps(pairs []KeyStrBytesPair) error
// contains filtered or unexported methods
}
IConnSender connection sender interface
Thread Safety & Re-entrance Requirements: - ALL methods except loopSend() MUST be goroutine-safe and re-entrant - Multiple calls to Close() should be safe (may return error but MUST NOT panic) - Resource cleanup operations should be idempotent
Method Categories:
- Required: Conn/SetMetaInfo/MetaInfo/Close/loopSend
- Optional: Put2Queue/Put2SendMap/Put2SendSMap/Put2SendMaps/Put2SendSMaps (at least one Put2* method should be implemented, others can be no-op)
Special Notes: - loopSend() is ONLY called by ConnHandler internally, NEVER call it from external code - loopSend() runs in its own goroutine and handles the sending loop logic
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 {
// ObjectMarshaler marshal log object
zapcore.ObjectMarshaler
// GetRemoteAddr get remote address
GetRemoteAddr() string
}
MetaInfo meta info for logging
type QSendConn ¶ added in v1.3.3
type QSendConn struct {
// contains filtered or unexported fields
}
QSendConn 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
func NewQSendConnHandler(conn net.Conn, sendQSize int, readerFactory ConnReaderFactory) *QSendConn
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 (*QSendConn) Close ¶ added in v1.3.3
Close closes connection handler (required, goroutine-safe, re-entrant) This method can be called directly via IConnSender/IConnIO interface to gracefully shutdown the connection and trigger the associated ConnHandler.Exit() through the goroutine defer chain Multiple calls are safe and will not panic
func (*QSendConn) Conn ¶ added in v1.3.3
Conn returns the underlying network connection (required, goroutine-safe)
func (*QSendConn) MetaInfo ¶ added in v1.3.3
MetaInfo gets meta info for logging (required, goroutine-safe)
func (*QSendConn) Put2Queue ¶ added in v1.3.3
Put2Queue send bytes async(put to send queue) (optional, goroutine-safe, re-entrant)
func (*QSendConn) Put2SendMap ¶ added in v1.3.3
Put2SendMap put bytes to send map (optional, goroutine-safe, re-entrant) Note: treats this as equivalent to Put2Queue, ignoring the key
func (*QSendConn) Put2SendMaps ¶ added in v1.3.3
func (x *QSendConn) Put2SendMaps(_ []KeyIntBytesPair) error
Put2SendMaps put multiple key uint32 and bytes pairs to send map (optional, goroutine-safe, re-entrant) Note: does not support batch operations
func (*QSendConn) Put2SendSMap ¶ added in v1.3.3
Put2SendSMap put bytes to send map (optional, goroutine-safe, re-entrant) Note: treats this as equivalent to Put2Queue, ignoring the key
func (*QSendConn) Put2SendSMaps ¶ added in v1.3.3
func (x *QSendConn) Put2SendSMaps(_ []KeyStrBytesPair) error
Put2SendSMaps put multiple key string and bytes pairs to send map (optional, goroutine-safe, re-entrant) Note: does not support batch operations
func (*QSendConn) SetMetaInfo ¶ added in v1.3.3
SetMetaInfo sets meta info for logging (required, goroutine-safe, re-entrant)
type ReadProcessor ¶ added in v1.3.3
ReadProcessor read handler logic iConnIO : connection io interface buffer : read buffer return : error if any Actually, this is the core function to process the read data
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, readerProcessor ReadProcessor, connIOFactory ConnIOFactory) *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