Documentation
¶
Index ¶
- Variables
- func SetKeepAliveCount(conn *net.TCPConn, count int) (err error)
- type Client
- type ClientOption
- func WithClientConnContextFunc(f func(ctx context.Context, c net.Conn) context.Context) ClientOption
- func WithClientErrorLogFunc(errorLogFunc func(fmt string, args ...interface{})) ClientOption
- func WithClientHandler(h ConnHandler) ClientOption
- func WithClientKeepAliveCount(count int) ClientOption
- func WithClientKeepAlivePeriod(period time.Duration) ClientOption
- func WithConnectAddress(addr string) ClientOption
- type ClientOptions
- type Conn
- type ConnHandler
- type ConnState
- type RawTCPConnHandler
- type RawTCPHandler
- type Server
- type ServerOption
- func WithListenAddress(addr string) ServerOption
- func WithServerBaseContextFunc(f func(net.Listener) context.Context) ServerOption
- func WithServerConnContextFunc(f func(ctx context.Context, c net.Conn) context.Context) ServerOption
- func WithServerErrorLogFunc(errorLogFunc func(fmt string, args ...interface{})) ServerOption
- func WithServerHandler(h ConnHandler) ServerOption
- func WithServerKeepAliveCount(count int) ServerOption
- func WithServerKeepAlivePeriod(period time.Duration) ServerOption
- type ServerOptions
Constants ¶
This section is empty.
Variables ¶
var (
ClientContextKey = &contextKey{"tcp-client"}
)
connext keys
var DefaultConnHandler = &disconnectHandler{}
DefaultConnHandler is default connection handler
var (
DefaultErrorLogFunc = log.Printf
)
default tcp options
var ErrAbortHandler = errors.New("tnet/tcp: abort Handler")
ErrAbortHandler means abort handler error
var ErrClientClosed = errors.New("tnet/tcp: Client closed")
ErrClientClosed means client has been closed
var ErrConnectionRefused = errors.New("tnet/tcp: Connection refused")
ErrConnectionRefused means connection refused
var ErrServerClosed = errors.New("tnet/tcp: Server closed")
ErrServerClosed means server has been closed
var (
LocalAddrContextKey = &contextKey{"local-addr"}
)
context keys
var (
ServerContextKey = &contextKey{"tcp-server"}
)
context keys
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client over tcp
func (*Client) DialAndServe ¶
DialAndServe starts client
func (*Client) RegisterOnShutdown ¶
func (cli *Client) RegisterOnShutdown(f func())
RegisterOnShutdown registers OnShutdown funcs
type ClientOption ¶
type ClientOption func(opts *ClientOptions)
ClientOption is option setter for tcp client
func WithClientConnContextFunc ¶
func WithClientConnContextFunc(f func(ctx context.Context, c net.Conn) context.Context) ClientOption
WithClientConnContextFunc sets connection context hook function opt
func WithClientErrorLogFunc ¶
func WithClientErrorLogFunc(errorLogFunc func(fmt string, args ...interface{})) ClientOption
WithClientErrorLogFunc sets error log function opt
func WithClientHandler ¶
func WithClientHandler(h ConnHandler) ClientOption
WithClientHandler sets client handler opt
func WithClientKeepAliveCount ¶ added in v0.3.0
func WithClientKeepAliveCount(count int) ClientOption
WithClientKeepAliveCount sets tcp keepalive count opt
func WithClientKeepAlivePeriod ¶ added in v0.3.0
func WithClientKeepAlivePeriod(period time.Duration) ClientOption
WithClientKeepAlivePeriod sets tcp keepalive period opt
func WithConnectAddress ¶
func WithConnectAddress(addr string) ClientOption
WithConnectAddress sets connect address opt
type ClientOptions ¶
type ClientOptions struct {
// contains filtered or unexported fields
}
ClientOptions is options of tcp client
type Conn ¶
type Conn interface { Reader() io.Reader Writer() io.Writer BufferReader() *bufio.Reader BufferWriter() *bufio.Writer AbortPendingRead() CancelContext() }
Conn is tcp connection
type ConnHandler ¶
ConnHandler is connection handler
func NewRawTCPConnHandler ¶ added in v0.2.0
func NewRawTCPConnHandler(h RawTCPHandler) ConnHandler
NewRawTCPConnHandler creates a new raw tcp connection handler
type RawTCPConnHandler ¶ added in v0.2.0
type RawTCPConnHandler struct {
Handler RawTCPHandler
}
RawTCPConnHandler is raw tcp connection handler
type RawTCPHandler ¶
RawTCPHandler is raw tcp handler
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server over tcp
func (*Server) ListenAndServe ¶
ListenAndServe starts tcp server
func (*Server) RegisterOnShutdown ¶
func (srv *Server) RegisterOnShutdown(f func())
RegisterOnShutdown registers OnShutdown functions
type ServerOption ¶
type ServerOption func(opts *ServerOptions)
ServerOption is option setter for server
func WithListenAddress ¶
func WithListenAddress(addr string) ServerOption
WithListenAddress sets listen address opt
func WithServerBaseContextFunc ¶
func WithServerBaseContextFunc(f func(net.Listener) context.Context) ServerOption
WithServerBaseContextFunc sets server base context hook funcion opt
func WithServerConnContextFunc ¶
func WithServerConnContextFunc(f func(ctx context.Context, c net.Conn) context.Context) ServerOption
WithServerConnContextFunc sets new connection context hook funcion opt
func WithServerErrorLogFunc ¶
func WithServerErrorLogFunc(errorLogFunc func(fmt string, args ...interface{})) ServerOption
WithServerErrorLogFunc sets error log function opt
func WithServerHandler ¶
func WithServerHandler(h ConnHandler) ServerOption
WithServerHandler sets server handler opt
func WithServerKeepAliveCount ¶ added in v0.3.0
func WithServerKeepAliveCount(count int) ServerOption
WithServerKeepAliveCount sets tcp keepalive count opt
func WithServerKeepAlivePeriod ¶ added in v0.3.0
func WithServerKeepAlivePeriod(period time.Duration) ServerOption
WithServerKeepAlivePeriod sets tcp keepalive period opt
type ServerOptions ¶
type ServerOptions struct {
// contains filtered or unexported fields
}
ServerOptions is server options