Documentation
¶
Index ¶
- func SendBytes2Conn(conn net.Conn, bs []byte) error
- func SetWriteTimeout(d time.Duration)
- type BasicConnIO
- type BasicMetaInfo
- type BytesMsg
- type ConnExitEvent
- type ConnHandler
- type ConnIOFactory
- type ConnReaderFactory
- type ConnStartEvent
- type IConnIO
- type IConnReader
- type IConnSender
- type IMsg
- type MetaInfo
- type QSendConn
- 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 BasicConnIO ¶ added in v1.3.6
type BasicConnIO struct {
// contains filtered or unexported fields
}
BasicConnIO basic connection io
func NewBasicConnIO ¶ added in v1.3.6
func NewBasicConnIO(conn net.Conn, reader IConnReader) *BasicConnIO
NewBasicConnIO : new basic connection io
func (*BasicConnIO) CloseX ¶ added in v1.3.6
func (x *BasicConnIO) CloseX(closeFn func() error) error
CloseX 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 closeFn : custom close function, if nil, use x.conn.Close()
func (*BasicConnIO) Conn ¶ added in v1.3.6
func (x *BasicConnIO) Conn() net.Conn
Conn returns the underlying network connection
func (*BasicConnIO) MetaInfo ¶ added in v1.3.6
func (x *BasicConnIO) MetaInfo() MetaInfo
MetaInfo gets meta info for logging (required, goroutine-safe)
func (*BasicConnIO) ReadFrame ¶ added in v1.3.6
func (x *BasicConnIO) ReadFrame(conn net.Conn) ([]byte, error)
ReadFrame reads one frame(an entire message bytes) from connection
func (*BasicConnIO) SetMetaInfo ¶ added in v1.3.6
func (x *BasicConnIO) SetMetaInfo(m MetaInfo)
SetMetaInfo sets meta info for logging (required, goroutine-safe, re-entrant)
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 BytesMsg ¶ added in v1.3.6
type BytesMsg struct {
Bs []byte
}
BytesMsg : bytes message
func NewBytesMsg ¶ added in v1.3.6
NewBytesMsg : new bytes message
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: - Multiple calls to Close() should be safe (may return error but MUST NOT panic) - Resource cleanup operations should be idempotent
type IConnReader ¶ added in v1.3.3
type IConnReader interface {
// ReadFrame reads one frame(an entire message bytes) from connection
// conn : connection to read from
// return : read buffer and error if any
ReadFrame(conn net.Conn) ([]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
// PutMsg put message to send (required, goroutine-safe)
// return : error if any
PutMsg(msg IMsg) error
// PopMsgBytes pop message bytes to send (required, goroutine-safe)
// return : message bytes and error if any
PopMsgBytes() ([]byte, error)
// contains filtered or unexported methods
}
IConnSender connection sender interface
Thread Safety & Re-entrance Requirements: - ALL methods 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
type IMsg ¶ added in v1.3.6
type IMsg interface {
// Name : message name
Name() string
}
IMsg : message interface
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 {
*BasicConnIO
// contains filtered or unexported fields
}
QSendConn queue send connection sender send queue based connection sender user can put bytes to send queue async then send bytes in queue one by one
func NewQSendConnHandler ¶ added in v1.3.0
func NewQSendConnHandler(conn net.Conn, sendQSize int, reader IConnReader) *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) PopMsgBytes ¶ added in v1.3.6
PopMsgBytes pop message bytes to send (optional, 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