Documentation
¶
Overview ¶
Package netpoll implements a network poller based on epoll/kqueue.
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")
ErrServeFunc is the error when the Serve func is nil
var ErrServerClosed = errors.New("Server closed")
ErrServerClosed is returned by the Server's Serve and ListenAndServe methods after a call to Close.
var ErrUpgradeFunc = errors.New("Upgrade function must be not nil")
ErrUpgradeFunc is the error when the Upgrade func is nil
var Tag = "none"
Tag is the poll type.
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 (*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(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 {
}
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 do not work for consisted with other system.
NoAsync bool
UnsharedWorkers int
SharedWorkers int
// TasksPerWorker do not work for consisted with other system.
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.