Documentation ¶
Index ¶
- Constants
- Variables
- func IP(req *http.Request) string
- func IsNetworkError(err error) bool
- func KeepAliveTCPConn(conn net.Conn, d time.Duration)
- func ListenAndServeTCP(addr string, keepalive time.Duration, handler ConnHandler, ...) error
- type Command
- type CommandHandler
- 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 ( ErrNotHandshaked = errors.New("hello command required") ErrInvalidCommand = errors.New("invalid command") )
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, certs ...tls.Certificate) error
ListenAndServeTCP listen and serve a tcp address
Types ¶
type Command ¶ added in v0.0.18
type Command interface { Name() string // Name of command NArg() int // Number of arguments Arg(i int) string // Arg returns ith argument }
Command represents textproto command
type CommandHandler ¶ added in v0.0.18
CommandHandler handles textproto command
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
func (*Session) ContentType ¶ added in v0.0.18
func (s *Session) ContentType() proto.ContentType
ContentType returns type of content
type SessionEventHandler ¶
type SessionEventHandler interface { OnOpen() // ready to read/write OnClose(err error) // session closed, err maybe nil OnHandshake(proto.ContentType) error // session handshaked OnMessage(proto.Type, 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 ListenTCP ¶ added in v0.0.18
func ListenTCP(addr string, handler ConnHandler, keepalive time.Duration, certs ...tls.Certificate) (*TCPServer, net.Listener, error)
ListenTCP creates a tcp server
Click to show internal directories.
Click to hide internal directories.