func (ce ConnectionEvent) ConnectFailure() bool {
	return ce == ConnectFailed || ce == ConnectTimeout
}
ConnectFailure represents whether the event is triggered by connection failure
package api
import (
	"context"
	"net"
	"time"
	"github.com/rcrowley/go-metrics"
)
type ConnState int
const (
	ConnInit ConnState = iota
	ConnActive
	ConnClosed
)
type ConnectionCloseType string
const (
	FlushWrite ConnectionCloseType = "FlushWrite"
	NoFlush ConnectionCloseType = "NoFlush"
)
type Connection interface {
	ID() uint64
	Start(lctx context.Context)
	Write(buf ...IoBuffer) error
	Close(ccType ConnectionCloseType, eventType ConnectionEvent) error
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	SetRemoteAddr(address net.Addr)
	AddConnectionEventListener(listener ConnectionEventListener)
	AddBytesReadListener(listener func(bytesRead uint64))
	AddBytesSentListener(listener func(bytesSent uint64))
	NextProtocol() string
	SetNoDelay(enable bool)
	SetReadDisable(disable bool)
	ReadEnabled() bool
	TLS() net.Conn
	SetBufferLimit(limit uint32)
	BufferLimit() uint32
	SetLocalAddress(localAddress net.Addr, restored bool)
	SetCollector(read, write metrics.Counter)
	LocalAddressRestored() bool
	GetWriteBuffer() []IoBuffer
	GetReadBuffer() IoBuffer
	FilterManager() FilterManager
	RawConn() net.Conn
	SetTransferEventListener(listener func() bool)
	SetIdleTimeout(readTimeout time.Duration, idleTimeout time.Duration)
	State() ConnState
	OnRead(buffer IoBuffer)
}
type ConnectionEvent string
const (
	RemoteClose     ConnectionEvent = "RemoteClose"
	LocalClose      ConnectionEvent = "LocalClose"
	OnReadErrClose  ConnectionEvent = "OnReadErrClose"
	OnWriteErrClose ConnectionEvent = "OnWriteErrClose"
	OnConnect       ConnectionEvent = "OnConnect"
	Connected       ConnectionEvent = "ConnectedFlag"
	ConnectTimeout  ConnectionEvent = "ConnectTimeout"
	ConnectFailed   ConnectionEvent = "ConnectFailed"
	OnReadTimeout   ConnectionEvent = "OnReadTimeout"
	OnWriteTimeout  ConnectionEvent = "OnWriteTimeout"
)
func (ce ConnectionEvent) IsClose() bool {
	return ce == LocalClose || ce == RemoteClose ||
		ce == OnReadErrClose || ce == OnWriteErrClose || ce == OnWriteTimeout
}