Documentation ¶
Index ¶
- Variables
- func IsPrivateIP(ip string) bool
- func LocalOutgoingIP() (string, error)
- func RandomListen(ip ...string) (l net.Listener, port string, err error)
- func RandomPort(ip ...string) (port string, err error)
- func Read(c net.Conn, bufSize int) (d string, err error)
- func ReadBytes(c net.Conn, bufSize int) (d []byte, err error)
- func Write(addr, data string) (err error)
- func WriteBytes(addr string, data []byte) (err error)
- func WriteTo(writer io.Writer, data string) (n int, err error)
- type AESCodec
- type AESOptions
- type AcceptHandler
- type Addr
- type BufferedConn
- type CloseHandler
- type Codec
- type CodecFactory
- type Conn
- func (s *Conn) AddCodec(codec Codec) *Conn
- func (s *Conn) AddFilter(f ConnFilter)
- func (s *Conn) Close() (err error)
- func (s *Conn) Ctx() Context
- func (s *Conn) RawConn() net.Conn
- func (s *Conn) Read(b []byte) (n int, err error)
- func (s *Conn) ReadBytes() int64
- func (s *Conn) ReadTimeout() time.Duration
- func (s *Conn) SetAutoCloseOnReadWriteError(b bool)
- func (s *Conn) SetReadTimeout(readTimeout time.Duration) *Conn
- func (s *Conn) SetTimeout(readWriteTimeout time.Duration) *Conn
- func (s *Conn) SetWriteTimeout(writeTimeout time.Duration) *Conn
- func (s *Conn) Write(b []byte) (n int, err error)
- func (s *Conn) WriteBytes() int64
- func (s *Conn) WriteTimeout() time.Duration
- type ConnBinder
- func (s *ConnBinder) Ctx() Context
- func (s *ConnBinder) OnClose(onClose func()) *ConnBinder
- func (s *ConnBinder) OnDstClose(onDstClose CloseHandler) *ConnBinder
- func (s *ConnBinder) OnSrcClose(onSrcClose CloseHandler) *ConnBinder
- func (s *ConnBinder) SetAutoClose(autoClose bool)
- func (s *ConnBinder) SetReadBufSize(readBufSize int) *ConnBinder
- func (s *ConnBinder) Start()
- func (s *ConnBinder) StartAndWait()
- type ConnFilter
- type Context
- type DataHandler
- type ErrorHandler
- type EventConn
- func (s *EventConn) AddCodec(codec Codec) *EventConn
- func (s *EventConn) AddConnFilter(f ConnFilter) *EventConn
- func (s *EventConn) Close()
- func (s *EventConn) Ctx() Context
- func (s *EventConn) LocalAddr() net.Addr
- func (s *EventConn) OnClose(onClose CloseHandler) *EventConn
- func (s *EventConn) OnData(onData DataHandler) *EventConn
- func (s *EventConn) OnReadError(onReadError ErrorHandler) *EventConn
- func (s *EventConn) OnWriterError(onWriterError ErrorHandler) *EventConn
- func (s *EventConn) ReadBytes() int64
- func (s *EventConn) ReadTimeout() time.Duration
- func (s *EventConn) RemoteAddr() net.Addr
- func (s *EventConn) SetReadBufferSize(readBufferSize int) *EventConn
- func (s *EventConn) SetReadTimeout(readTimeout time.Duration) *EventConn
- func (s *EventConn) SetTimeout(readWriteTimeout time.Duration) *EventConn
- func (s *EventConn) SetWriteTimeout(writeTimeout time.Duration) *EventConn
- func (s *EventConn) Start()
- func (s *EventConn) StartAndWait()
- func (s *EventConn) Write(b []byte) (n int, err error)
- func (s *EventConn) WriteBytes() int64
- func (s *EventConn) WriteTimeout() time.Duration
- type EventListener
- func (s *EventListener) AddCodecFactory(codecFactory CodecFactory) *EventListener
- func (s *EventListener) AddConnFilter(f ConnFilter) *EventListener
- func (s *EventListener) AddListenerFilter(f ConnFilter) *EventListener
- func (s *EventListener) Addr() *Addr
- func (s *EventListener) Close() *EventListener
- func (s *EventListener) ConnCount() int64
- func (s *EventListener) Ctx() Context
- func (s *EventListener) OnAccept(h AcceptHandler) *EventListener
- func (s *EventListener) OnAcceptError(h ErrorHandler) *EventListener
- func (s *EventListener) OnFistReadTimeout(h FirstReadTimeoutHandler) *EventListener
- func (s *EventListener) SetAutoCloseConn(autoCloseConn bool)
- func (s *EventListener) SetAutoCloseConnOnReadWriteError(b bool) *EventListener
- func (s *EventListener) SetFirstReadTimeout(firstReadTimeout time.Duration) *EventListener
- func (s *EventListener) SetOnConnClose(onConnClose CloseHandler) *EventListener
- func (s *EventListener) Start() *EventListener
- func (s *EventListener) StartAndWait()
- type FirstReadTimeoutHandler
- type HeartbeatCodec
- func (s *HeartbeatCodec) Close() (err error)
- func (s *HeartbeatCodec) Initialize(ctx Context) (err error)
- func (s *HeartbeatCodec) Interval() time.Duration
- func (s *HeartbeatCodec) Read(b []byte) (n int, err error)
- func (s *HeartbeatCodec) SetConn(c net.Conn) Codec
- func (s *HeartbeatCodec) SetInterval(interval time.Duration) *HeartbeatCodec
- func (s *HeartbeatCodec) SetTimeout(timeout time.Duration) *HeartbeatCodec
- func (s *HeartbeatCodec) Timeout() time.Duration
- func (s *HeartbeatCodec) Write(b []byte) (n int, err error)
- type Listener
- func (s *Listener) Accept() (c net.Conn, err error)
- func (s *Listener) AddCodecFactory(codecFactory CodecFactory) *Listener
- func (s *Listener) AddConnFilter(f ConnFilter) *Listener
- func (s *Listener) AddListenerFilter(f ConnFilter) *Listener
- func (s *Listener) Addr() net.Addr
- func (s *Listener) Close() error
- func (s *Listener) ConnCount() int64
- func (s *Listener) Ctx() Context
- func (s *Listener) NewProtocolListener(opt *ProtocolListenerOption) *Listener
- func (s *Listener) OnFistReadTimeout(h FirstReadTimeoutHandler)
- func (s *Listener) SetAutoCloseConnOnReadWriteError(b bool)
- func (s *Listener) SetFirstReadTimeout(firstReadTimeout time.Duration) *Listener
- func (s *Listener) SetOnConnClose(onConnClose CloseHandler) *Listener
- type ProtocolChecker
- type ProtocolListener
- type ProtocolListenerOption
- type RateCodec
- type TLSClientCodec
- func (s *TLSClientCodec) AddCertificate(certPEMBytes, keyPEMBytes []byte) (err error)
- func (s *TLSClientCodec) AddServerCa(caPEMBytes []byte) *TLSClientCodec
- func (s *TLSClientCodec) AddToHTTPClient(httpClient *http.Client) *TLSClientCodec
- func (s *TLSClientCodec) Initialize(ctx Context) (err error)
- func (s *TLSClientCodec) LoadSystemCas()
- func (s *TLSClientCodec) PinServerCert(serverCertPEMBytes []byte) (err error)
- func (s *TLSClientCodec) SetConn(c net.Conn) Codec
- func (s *TLSClientCodec) SetHandshakeTimeout(handshakeTimeout time.Duration)
- func (s *TLSClientCodec) SetServerName(serverName string) *TLSClientCodec
- func (s *TLSClientCodec) SkipVerify(b bool) *TLSClientCodec
- func (s *TLSClientCodec) SkipVerifyCommonName(skipVerifyCommonName bool) *TLSClientCodec
- type TLSServerCodec
- func (s *TLSServerCodec) AddCertificate(certPEMBytes, keyPEMBytes []byte) (err error)
- func (s *TLSServerCodec) AddClientCa(caPEMBytes []byte) *TLSServerCodec
- func (s *TLSServerCodec) Initialize(ctx Context) (err error)
- func (s *TLSServerCodec) LoadSystemCas()
- func (s *TLSServerCodec) RequireClientAuth(b bool) *TLSServerCodec
- func (s *TLSServerCodec) SetConn(c net.Conn) Codec
- func (s *TLSServerCodec) SetHandshakeTimeout(handshakeTimeout time.Duration)
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrClosedListener = errors.New("listener is closed")
)
View Source
var (
ErrFirstReadTimeout = fmt.Errorf("ErrFirstReadTimeout")
)
Functions ¶
func IsPrivateIP ¶
func LocalOutgoingIP ¶
func RandomPort ¶
func WriteBytes ¶
Types ¶
type AESCodec ¶
func NewAESCodec ¶
func NewAESCodecFromOptions ¶
func NewAESCodecFromOptions(c *AESOptions) *AESCodec
func (*AESCodec) Initialize ¶
type AESOptions ¶
type AESOptions struct { // Password required. Password string // Salt optionally. A good random salt at least 8 bytes is recommended. Salt []byte // Type optionally. It must be: aes-128 or aes-192 or aes-256, if empty default is aes-256. Type string // HashFunc optionally, default is sha256.New HashFunc func() hash.Hash }
type AcceptHandler ¶
type Addr ¶
type Addr struct {
// contains filtered or unexported fields
}
func NewTCPAddr ¶
func (*Addr) PortAddr ¶
PortAddr returns address string with 'withIP:Addr.Port()', 'withIP' can be a valid ip or domain or empty.
func (*Addr) PortLocalAddr ¶
PortLocalAddr returns address string with '127.0.0.1:Addr.Port()',
type BufferedConn ¶
type BufferedConn interface { net.Conn Peek(n int) ([]byte, error) ReadByte() (byte, error) UnreadByte() error Buffered() int PeekMax(n int) (d []byte, err error) }
func NewBufferedConn ¶
func NewBufferedConn(c net.Conn) BufferedConn
func NewBufferedConnSize ¶
func NewBufferedConnSize(c net.Conn, n int) BufferedConn
type CloseHandler ¶
type CloseHandler func(ctx Context)
type CodecFactory ¶
type Conn ¶
func (*Conn) AddFilter ¶
func (s *Conn) AddFilter(f ConnFilter)
func (*Conn) ReadTimeout ¶
func (*Conn) SetAutoCloseOnReadWriteError ¶
func (*Conn) WriteBytes ¶
func (*Conn) WriteTimeout ¶
type ConnBinder ¶
type ConnBinder struct {
// contains filtered or unexported fields
}
func NewConnBinder ¶
func NewConnBinder(src net.Conn, dst net.Conn) *ConnBinder
func NewContextConnBinder ¶
func (*ConnBinder) Ctx ¶
func (s *ConnBinder) Ctx() Context
func (*ConnBinder) OnClose ¶
func (s *ConnBinder) OnClose(onClose func()) *ConnBinder
func (*ConnBinder) OnDstClose ¶
func (s *ConnBinder) OnDstClose(onDstClose CloseHandler) *ConnBinder
func (*ConnBinder) OnSrcClose ¶
func (s *ConnBinder) OnSrcClose(onSrcClose CloseHandler) *ConnBinder
func (*ConnBinder) SetAutoClose ¶
func (s *ConnBinder) SetAutoClose(autoClose bool)
func (*ConnBinder) SetReadBufSize ¶
func (s *ConnBinder) SetReadBufSize(readBufSize int) *ConnBinder
func (*ConnBinder) Start ¶
func (s *ConnBinder) Start()
func (*ConnBinder) StartAndWait ¶
func (s *ConnBinder) StartAndWait()
type Context ¶
type Context interface { Clone() Context EventConn() *EventConn SetEventConn(eventConn *EventConn) Context EventListener() *EventListener SetEventListener(eventListener *EventListener) Context ConnBinder() *ConnBinder SetConnBinder(connBinder *ConnBinder) Context IsHijacked() bool Hijack() IsBreak() bool Break() IsContinue() bool Continue() ReadBytes() int64 WriteBytes() int64 Data(key interface{}) interface{} SetData(key, value interface{}) Context SetConn(c net.Conn) Context Conn() net.Conn RawConn() net.Conn Listener() *Listener SetListener(listener *Listener) Context ReadTimeout() time.Duration WriteTimeout() time.Duration RemoteAddr() net.Addr LocalAddr() net.Addr IsTLS() bool }
func NewContext ¶
func NewContext() Context
type DataHandler ¶
type ErrorHandler ¶
type EventConn ¶
type EventConn struct {
// contains filtered or unexported fields
}
func NewEventConn ¶
func (*EventConn) AddConnFilter ¶
func (s *EventConn) AddConnFilter(f ConnFilter) *EventConn
func (*EventConn) OnClose ¶
func (s *EventConn) OnClose(onClose CloseHandler) *EventConn
func (*EventConn) OnData ¶
func (s *EventConn) OnData(onData DataHandler) *EventConn
func (*EventConn) OnReadError ¶
func (s *EventConn) OnReadError(onReadError ErrorHandler) *EventConn
func (*EventConn) OnWriterError ¶
func (s *EventConn) OnWriterError(onWriterError ErrorHandler) *EventConn
func (*EventConn) ReadTimeout ¶
func (*EventConn) RemoteAddr ¶
func (*EventConn) SetReadBufferSize ¶
func (*EventConn) SetReadTimeout ¶
func (*EventConn) SetTimeout ¶
func (*EventConn) SetWriteTimeout ¶
func (*EventConn) StartAndWait ¶
func (s *EventConn) StartAndWait()
func (*EventConn) WriteBytes ¶
func (*EventConn) WriteTimeout ¶
type EventListener ¶
type EventListener struct {
// contains filtered or unexported fields
}
func ListenEvent ¶
func ListenEvent(addr string) (l *EventListener, err error)
func NewContextEventListener ¶
func NewContextEventListener(ctx Context, l net.Listener) *EventListener
func NewEventListener ¶
func NewEventListener(l net.Listener) *EventListener
func NewEventListenerAddr ¶
func NewEventListenerAddr(addr string) (*EventListener, error)
func (*EventListener) AddCodecFactory ¶
func (s *EventListener) AddCodecFactory(codecFactory CodecFactory) *EventListener
func (*EventListener) AddConnFilter ¶
func (s *EventListener) AddConnFilter(f ConnFilter) *EventListener
func (*EventListener) AddListenerFilter ¶
func (s *EventListener) AddListenerFilter(f ConnFilter) *EventListener
func (*EventListener) Addr ¶
func (s *EventListener) Addr() *Addr
func (*EventListener) Close ¶
func (s *EventListener) Close() *EventListener
func (*EventListener) ConnCount ¶
func (s *EventListener) ConnCount() int64
func (*EventListener) Ctx ¶
func (s *EventListener) Ctx() Context
func (*EventListener) OnAccept ¶
func (s *EventListener) OnAccept(h AcceptHandler) *EventListener
func (*EventListener) OnAcceptError ¶
func (s *EventListener) OnAcceptError(h ErrorHandler) *EventListener
func (*EventListener) OnFistReadTimeout ¶
func (s *EventListener) OnFistReadTimeout(h FirstReadTimeoutHandler) *EventListener
func (*EventListener) SetAutoCloseConn ¶
func (s *EventListener) SetAutoCloseConn(autoCloseConn bool)
SetAutoCloseConn if true, EventListener will close Conn after accept handler return.
func (*EventListener) SetAutoCloseConnOnReadWriteError ¶
func (s *EventListener) SetAutoCloseConnOnReadWriteError(b bool) *EventListener
func (*EventListener) SetFirstReadTimeout ¶
func (s *EventListener) SetFirstReadTimeout(firstReadTimeout time.Duration) *EventListener
func (*EventListener) SetOnConnClose ¶
func (s *EventListener) SetOnConnClose(onConnClose CloseHandler) *EventListener
func (*EventListener) Start ¶
func (s *EventListener) Start() *EventListener
func (*EventListener) StartAndWait ¶
func (s *EventListener) StartAndWait()
type FirstReadTimeoutHandler ¶
type HeartbeatCodec ¶
type HeartbeatCodec struct { net.Conn sync.Mutex sync.Once // contains filtered or unexported fields }
func NewHeartbeatCodec ¶
func NewHeartbeatCodec() *HeartbeatCodec
func (*HeartbeatCodec) Close ¶
func (s *HeartbeatCodec) Close() (err error)
func (*HeartbeatCodec) Initialize ¶
func (s *HeartbeatCodec) Initialize(ctx Context) (err error)
func (*HeartbeatCodec) Interval ¶
func (s *HeartbeatCodec) Interval() time.Duration
func (*HeartbeatCodec) SetInterval ¶
func (s *HeartbeatCodec) SetInterval(interval time.Duration) *HeartbeatCodec
func (*HeartbeatCodec) SetTimeout ¶
func (s *HeartbeatCodec) SetTimeout(timeout time.Duration) *HeartbeatCodec
func (*HeartbeatCodec) Timeout ¶
func (s *HeartbeatCodec) Timeout() time.Duration
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
func NewListener ¶
func NewListenerAddr ¶
func (*Listener) AddCodecFactory ¶
func (s *Listener) AddCodecFactory(codecFactory CodecFactory) *Listener
func (*Listener) AddConnFilter ¶
func (s *Listener) AddConnFilter(f ConnFilter) *Listener
func (*Listener) AddListenerFilter ¶
func (s *Listener) AddListenerFilter(f ConnFilter) *Listener
func (*Listener) NewProtocolListener ¶
func (s *Listener) NewProtocolListener(opt *ProtocolListenerOption) *Listener
func (*Listener) OnFistReadTimeout ¶
func (s *Listener) OnFistReadTimeout(h FirstReadTimeoutHandler)
func (*Listener) SetAutoCloseConnOnReadWriteError ¶
func (*Listener) SetFirstReadTimeout ¶
func (*Listener) SetOnConnClose ¶
func (s *Listener) SetOnConnClose(onConnClose CloseHandler) *Listener
type ProtocolChecker ¶
type ProtocolChecker func(listener *Listener, conn BufferedConn) bool
type ProtocolListener ¶
type ProtocolListener struct {
// contains filtered or unexported fields
}
func (*ProtocolListener) Addr ¶
func (s *ProtocolListener) Addr() net.Addr
func (*ProtocolListener) Close ¶
func (s *ProtocolListener) Close() error
type ProtocolListenerOption ¶
type ProtocolListenerOption struct { Name string Checker ProtocolChecker ConnQueueSize int OnQueueOverflow func(l net.Listener, opt *ProtocolListenerOption, conn BufferedConn) OverflowAutoClose bool }
type TLSClientCodec ¶
type TLSClientCodec struct {
// contains filtered or unexported fields
}
func NewTLSClientCodec ¶
func NewTLSClientCodec() *TLSClientCodec
func (*TLSClientCodec) AddCertificate ¶
func (*TLSClientCodec) AddServerCa ¶
func (s *TLSClientCodec) AddServerCa(caPEMBytes []byte) *TLSClientCodec
func (*TLSClientCodec) AddToHTTPClient ¶
func (s *TLSClientCodec) AddToHTTPClient(httpClient *http.Client) *TLSClientCodec
func (*TLSClientCodec) Initialize ¶
func (s *TLSClientCodec) Initialize(ctx Context) (err error)
func (*TLSClientCodec) LoadSystemCas ¶
func (s *TLSClientCodec) LoadSystemCas()
func (*TLSClientCodec) PinServerCert ¶
func (s *TLSClientCodec) PinServerCert(serverCertPEMBytes []byte) (err error)
func (*TLSClientCodec) SetHandshakeTimeout ¶
func (*TLSClientCodec) SetServerName ¶
func (s *TLSClientCodec) SetServerName(serverName string) *TLSClientCodec
func (*TLSClientCodec) SkipVerify ¶
func (s *TLSClientCodec) SkipVerify(b bool) *TLSClientCodec
func (*TLSClientCodec) SkipVerifyCommonName ¶
func (s *TLSClientCodec) SkipVerifyCommonName(skipVerifyCommonName bool) *TLSClientCodec
type TLSServerCodec ¶
type TLSServerCodec struct {
// contains filtered or unexported fields
}
func NewTLSServerCodec ¶
func NewTLSServerCodec() *TLSServerCodec
func (*TLSServerCodec) AddCertificate ¶
func (*TLSServerCodec) AddClientCa ¶
func (s *TLSServerCodec) AddClientCa(caPEMBytes []byte) *TLSServerCodec
func (*TLSServerCodec) Initialize ¶
func (s *TLSServerCodec) Initialize(ctx Context) (err error)
func (*TLSServerCodec) LoadSystemCas ¶
func (s *TLSServerCodec) LoadSystemCas()
func (*TLSServerCodec) RequireClientAuth ¶
func (s *TLSServerCodec) RequireClientAuth(b bool) *TLSServerCodec
func (*TLSServerCodec) SetHandshakeTimeout ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.