Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var EAGAIN = syscall.EAGAIN
EAGAIN is the error when resource temporarily unavailable
var EOF = io.EOF
EOF is the error returned by Read when no more input is available.
var ErrHandler = errors.New("Handler must be not nil")
ErrHandler is the error when the Handler is nil
var ErrHandlerFunc = errors.New("HandlerFunc must be not nil")
ErrHandlerFunc is the error when the HandlerFunc is nil
var ErrListener = errors.New("Listener must be not nil")
ErrListener is the error when the Listener is nil
var ErrServeFunc = errors.New("Serve function must be not nil")
var ErrServerClosed = errors.New("Server closed")
ErrServerClosed is returned by the Server's Serve and ListenAndServe methods after a call to Close.
var ErrTimeout = errors.New("non-positive interval for SetTimeout")
ErrTimeout is the error returned by SetTimeout when time.Duration d < time.Millisecond.
var ErrUpgradeFunc = errors.New("Upgrade function must be not nil")
ErrUpgradeFunc is the error when the Upgrade func is nil
Functions ¶
func ListenAndServe ¶
ListenAndServe listens on the network address and then calls Serve with handler to handle requests on incoming connections.
The handler must be not nil.
ListenAndServe always returns a non-nil error.
Types ¶
type ConnHandler ¶
type ConnHandler struct {
// contains filtered or unexported fields
}
ConnHandler implements the Handler interface.
func NewConHandler ¶
func NewConHandler() *ConnHandler
func (*ConnHandler) Serve ¶
func (h *ConnHandler) Serve(ctx Context) error
Serve implements the Handler Serve method.
func (*ConnHandler) SetServe ¶
func (h *ConnHandler) SetServe(serve func(Context) error) *ConnHandler
SetServe sets the Serve function for once serving.
func (*ConnHandler) SetUpgrade ¶
func (h *ConnHandler) SetUpgrade(upgrade func(conn net.Conn) (Context, error)) *ConnHandler
SetUpgrade sets the Upgrade function for upgrading the net.Conn.
type DataHandler ¶
type DataHandler struct { // Default NoShared is false to use the buffer pool for low memory usage. NoShared bool // NoCopy returns the bytes underlying buffer when NoCopy is true, // The bytes returned is shared by all invocations of Read, so do not modify it. // Default NoCopy is false to make a copy of data for every invocations of Read. NoCopy bool // BufferSize represents the buffer size. BufferSize int // HandlerFunc is the data Serve function. HandlerFunc func(req []byte) (res []byte) // contains filtered or unexported fields }
DataHandler implements the Handler interface.
func (*DataHandler) Serve ¶
func (h *DataHandler) Serve(ctx Context) error
Serve should serve a single request with the Context ctx.
func (*DataHandler) SetUpgrade ¶
SetUpgrade sets the Upgrade function for upgrading the net.Conn.
type Event ¶
type Event struct { // Fd is a file descriptor. Fd int // Mode represents the event mode. Mode Mode }
Event represents the poll event for the poller.
type Handler ¶
type Handler interface { // Upgrade upgrades the net.Conn to a Context. Upgrade(net.Conn) (Context, error) // Serve should serve a single request with the Context. Serve(Context) error }
Handler responds to a single request.
type Poll ¶
type Poll struct {
// contains filtered or unexported fields
}
Poll represents the poll that supports non-blocking I/O on file descriptors with polling.
func (*Poll) Close ¶
Close closes the poll fd. The underlying file descriptor is closed by the destroy method when there are no remaining references.
func (*Poll) SetTimeout ¶
SetTimeout sets the wait timeout.
func (*Poll) Unregister ¶
Unregister unregisters a file descriptor.
type Server ¶
type Server struct { Network string Address string // Handler responds to a single request. Handler Handler // NoAsync disables async. NoAsync bool TasksPerWorker int // contains filtered or unexported fields }
Server defines parameters for running a server.
func (*Server) ListenAndServe ¶
ListenAndServe listens on the network address and then calls Serve with handler to handle requests on incoming connections.
ListenAndServe always returns a non-nil error. After Close the returned error is ErrServerClosed.
func (*Server) Serve ¶
Serve accepts incoming connections on the listener l, and registers the conn fd to poll. The poll will trigger the fd to read requests and then call handler to reply to them.
The handler must be not nil.
Serve always returns a non-nil error. After Close the returned error is ErrServerClosed.