Documentation ¶
Index ¶
- Constants
- Variables
- func IsNetworkError(err error) bool
- func KeepAliveTCPConn(conn net.Conn, d time.Duration)
- func ListenAndServeTCP(addr string, keepalive time.Duration, handler ConnHandler, async bool, ...) error
- type ConnHandler
- type Option
- type Session
- type SessionEventHandler
- type TCPKeepAliveListener
- type TCPServer
Constants ¶
View Source
const (
// max length of content: 1G
MaxContentLength = 1 << 30
)
Variables ¶
View Source
var ( // content length greater than MaxContentLength ErrContentLengthOverflow = errors.New("content length overflow") )
Functions ¶
func IsNetworkError ¶
IsNetworkError returns whether the error is a network error or an EOF
func KeepAliveTCPConn ¶
KeepAliveTCPConn sets conn's keepalive duration
func ListenAndServeTCP ¶
func ListenAndServeTCP(addr string, keepalive time.Duration, handler ConnHandler, async bool, certs ...tls.Certificate) error
ListenAndServeTCP wraps TCPServer's ListenAndServeTCP
Types ¶
type Option ¶
type Option func(*option)
Option represents options of NewSession
func WithTimeout ¶
WithTimeout specify read timeout of session
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session wraps network session
func NewSession ¶
func NewSession(conn net.Conn, handler SessionEventHandler, options ...Option) *Session
NewSession creates a session
type SessionEventHandler ¶
type SessionEventHandler interface { OnReady() // ready to read/write OnClose(err error) // session closed, err maybe nil OnMessage(body proto.Body) error // received a message }
SessionEventHandler handles session events
type TCPKeepAliveListener ¶
type TCPKeepAliveListener struct { *net.TCPListener // contains filtered or unexported fields }
TCPKeepAliveListener wraps TCPListener with a keepalive duration
func NewTCPKeepAliveListener ¶
func NewTCPKeepAliveListener(ln *net.TCPListener, d time.Duration) *TCPKeepAliveListener
NewTCPKeepAliveListener creates a TCPKeepAliveListener
type TCPServer ¶
type TCPServer struct {
// contains filtered or unexported fields
}
TCPServer represents a tcp server
func NewTCPServer ¶
func NewTCPServer(addr string, handler ConnHandler) *TCPServer
NewTCPServer creates a tcp server
func (*TCPServer) ListenAndServe ¶
func (server *TCPServer) ListenAndServe(async bool, keepalive time.Duration, certs ...tls.Certificate) error
ListenAndServe starts the tcp server
Click to show internal directories.
Click to hide internal directories.