 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
- Constants
- Variables
- func ListenAndServe(addr string, readMsg OnMsgReadHandler, handleMsg OnMsgHandleHandler) error
- type Client
- type ConnState
- type Handler
- type NopClient
- func (srv *NopClient) OnClose(w io.Writer, r io.Reader) error
- func (srv *NopClient) OnError(w io.Writer, r io.Reader, err error) error
- func (srv *NopClient) OnMsgHandle(w io.Writer, msg interface{}) error
- func (srv *NopClient) OnMsgRead(r io.Reader) (msg interface{}, err error)
- func (srv *NopClient) OnOpen(conn net.Conn) error
 
- type NopServer
- func (srv *NopServer) OnClose(w io.Writer, r io.Reader) error
- func (srv *NopServer) OnError(w io.Writer, r io.Reader, err error) error
- func (srv *NopServer) OnMsgHandle(w io.Writer, msg interface{}) error
- func (srv *NopServer) OnMsgRead(r io.Reader) (msg interface{}, err error)
- func (srv *NopServer) OnOpen(conn net.Conn) error
 
- type NotFound
- func (notfound *NotFound) HandleMsg(b *bufio.Writer, msg interface{}) error
- func (srv *NotFound) OnClose(w io.Writer, r io.Reader) error
- func (srv *NotFound) OnError(w io.Writer, r io.Reader, err error) error
- func (srv *NotFound) OnMsgHandle(w io.Writer, msg interface{}) error
- func (srv *NotFound) OnMsgRead(r io.Reader) (msg interface{}, err error)
- func (srv *NotFound) OnOpen(conn net.Conn) error
- func (notfound *NotFound) ReadMsg(b *bufio.Reader) (msg interface{}, err error)
 
- type OnCloseHandler
- type OnCloseHandlerFunc
- type OnErrorHandler
- type OnErrorHandlerFunc
- type OnMsgHandleHandler
- type OnMsgHandleHandlerFunc
- type OnMsgReadHandler
- type OnMsgReadHandlerFunc
- type OnOpenHandler
- type OnOpenHandlerFunc
- type ServeMux
- func (mux *ServeMux) Handle(handler Handler)
- func (mux *ServeMux) OnClose(w io.Writer, r io.Reader) error
- func (mux *ServeMux) OnError(w io.Writer, r io.Reader, err error) error
- func (mux *ServeMux) OnMsgHandle(w io.Writer, msg interface{}) error
- func (mux *ServeMux) OnMsgRead(r io.Reader) (req interface{}, err error)
- func (mux *ServeMux) OnOpen(conn net.Conn) error
 
- type Server
- type TCPConn
Constants ¶
      View Source
      
  
const DefaultMaxBytes = 1 << 20 // 1 MB
    Variables ¶
      View Source
      
  
    var ( // ServerContextKey is a context key. It can be used in TCP // handlers with context.WithValue to access the server that // started the handler. The associated value will be of // type *Server. ServerContextKey = &contextKey{"tcp-server"} // ClientContextKey is a context key. It can be used in TCP // handlers with context.WithValue to access the client that // started the handler. The associated value will be of // type *Client. ClientContextKey = &contextKey{"tcp-client"} // LocalAddrContextKey is a context key. It can be used in // TCP handlers with context.WithValue to access the local // address the connection arrived on. // The associated value will be of type net.Addr. LocalAddrContextKey = &contextKey{"local-addr"} )
      View Source
      
  var DefaultServeMux = &defaultServeMux
    DefaultServeMux is the default ServeMux used by Serve.
      View Source
      
  var ErrAbortHandler = errors.New("net/tcp: abort onMsgHandle")
    ErrAbortHandler is a sentinel panic value to abort a handler. While any panic from OnHandshake aborts the response to the client, panicking with ErrAbortHandler also suppresses logging of a stack trace to the server's error log.
      View Source
      
  
    var ErrClientClosed = errors.New("tcp: Client closed")
    
      View Source
      
  
    var ErrNotFound = errors.New("tcp: Server not found")
    
      View Source
      
  var ErrServerClosed = errors.New("tcp: Server closed")
    ErrServerClosed is returned by the Server's Serve and ListenAndServe methods after a call to Shutdown or Close.
      View Source
      
  
    var ErrUnImplement = errors.New("UnImplement Method")
    
      View Source
      
  
    var NopOnCloseHandler = nopSC
    
      View Source
      
  
    var NopOnErrorHandler = nopSC
    
      View Source
      
  
    var NopOnHTTPResponseHandler = nopSC
    
      View Source
      
  
    var NopOnMsgHandleHandler = nopSC
    
      View Source
      
  
    var NopOnMsgReadHandler = nopSC
    
      View Source
      
  
var NopOnOpenHandler = nopSC
    Functions ¶
func ListenAndServe ¶
func ListenAndServe(addr string, readMsg OnMsgReadHandler, handleMsg OnMsgHandleHandler) error
Types ¶
type Client ¶
type Client struct {
	*Server
}
    func NewClientFunc ¶
func NewClientFunc(onOpenHandler OnOpenHandler, onMsgReadHandler OnMsgReadHandler, onMsgHandleHandler OnMsgHandleHandler, onCloseHandler OnCloseHandler, onErrorHandler OnErrorHandler) *Client
func (*Client) DialAndServe ¶
        
          
            func (*Client) ListenAndServe
            deprecated
            
          
  
    
  
      
      
    type ConnState ¶
type ConnState int
A ConnState represents the state of a client connection to a server. It's used by the optional Server.ConnState hook.
const ( // StateNew represents a new connection that is expected to // send a request immediately. Connections begin at this // state and then transition to either StateActive or // StateClosed. StateNew ConnState = iota // StateActive represents a connection that has read 1 or more // bytes of a request. The Server.ConnState hook for // StateActive fires before the request has entered a handler // and doesn't fire again until the request has been // handled. After the request is handled, the state // transitions to StateClosed, StateHijacked, or StateIdle. // For HTTP/2, StateActive fires on the transition from zero // to one active request, and only transitions away once all // active requests are complete. That means that ConnState // cannot be used to do per-request work; ConnState only notes // the overall state of the connection. StateActive // StateIdle represents a connection that has finished // handling a request and is in the keep-alive state, waiting // for a new request. Connections transition from StateIdle // to either StateActive or StateClosed. StateIdle // StateHijacked represents a hijacked connection. // This is a terminal state. It does not transition to StateClosed. StateHijacked // StateClosed represents a closed connection. // This is a terminal state. Hijacked connections do not // transition to StateClosed. StateClosed )
type Handler ¶
type Handler interface {
	OnOpenHandler
	OnMsgReadHandler
	OnMsgHandleHandler
	OnCloseHandler
	OnErrorHandler
}
    func NotFoundHandler ¶
func NotFoundHandler() Handler
type NopClient ¶
type NopClient struct {
	// contains filtered or unexported fields
}
    func (*NopClient) OnMsgHandle ¶
type NopServer ¶
type NopServer struct {
	// contains filtered or unexported fields
}
    func (*NopServer) OnMsgHandle ¶
type NotFound ¶
NotFoundHandler returns a simple request handler that replies to each request with a “404 page not found” reply.
func (*NotFound) OnMsgHandle ¶
type OnCloseHandlerFunc ¶
type OnErrorHandler ¶
type OnErrorHandlerFunc ¶
type OnMsgHandleHandler ¶
type OnMsgHandleHandlerFunc ¶
func (OnMsgHandleHandlerFunc) OnMsgHandle ¶
func (f OnMsgHandleHandlerFunc) OnMsgHandle(w io.Writer, msg interface{}) error
type OnMsgReadHandler ¶
type OnMsgReadHandlerFunc ¶
type OnOpenHandler ¶
type OnOpenHandlerFunc ¶
type ServeMux ¶
type ServeMux struct {
	// contains filtered or unexported fields
}
    type Server ¶
type Server struct {
	Addr string // TCP address to listen on, ":tcp" if empty
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	IdleTimeout  time.Duration
	MaxBytes     int
	ErrorLog *log.Logger
	// ConnState specifies an optional callback function that is
	// called when a client connection changes state. See the
	// ConnState type and associated constants for details.
	ConnState func(net.Conn, ConnState)
	// contains filtered or unexported fields
}
    func NewServerFunc ¶
func NewServerFunc( onOpen OnOpenHandler, onMsgRead OnMsgReadHandler, onMsgHandle OnMsgHandleHandler, onClose OnCloseHandler, onError OnErrorHandler) *Server
func (*Server) CheckError ¶
func (*Server) ListenAndServe ¶
func (*Server) RegisterOnShutdown ¶
func (srv *Server) RegisterOnShutdown(f func())
type TCPConn ¶
type TCPConn struct {
	*bufio.ReadWriter
	// contains filtered or unexported fields
}
    func NewTCPConn ¶
func NewTCPConn(rw *bufio.ReadWriter) *TCPConn
 Click to show internal directories. 
   Click to hide internal directories.