Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Printer ¶
type Printer interface { Printf(format string, v ...interface{}) Println(v ...interface{}) }
Printer is a simple one method interface to allow a caller to provide a custom logger to this package.
var Logger Printer
Logger is a custom logger to use for this package. Logger is nil by default.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the high performance TCP server. When built by The NewServer function the server is not started and a call to Server.ListenTCP is needed. Server.Stop can be called to halt all of the listeners and shut down the server.
func NewServer ¶
func NewServer(laddr string, handler func(io.ReadWriter), options TCPOptions) *Server
NewServer returns a new Server instance configured to serve on a given local address with performance tweaks as defined in the provided TCPOptions.
The Server will call the provided handler function for each new TCP connection passing the underlying os.File as an argument.
The syntax of laddr is "host:port", like "127.0.0.1:8080". If host is omitted, as in ":8080", all available interfaces are used instead of just the interface with the given host address.
The Server will attempt to open multiple tcp listeners (one per CPU core) using the SO_REUSEPORT socket option if the OS supports it. See http://man7.org/linux/man-pages/man7/socket.7.html for details.
If the OS doesn't support this socket option, or fails to setup the socket like this for some other reason, the Server will degrade to using the standard library net.Listener implementation.
type TCPOptions ¶
TCPOptions is used to configure optional performance tweaks to the TCP socket listener.
DeferAccept corresponds to the TCP_DEFER_ACCEPT flag. If true the listener will set up the socket for this behaviour.See http://man7.org/linux/man-pages/man7/tcp.7.html for details.
Do not use the DeferAccept flag unless the server reads from the client before writing or it will cause the thread to hang.
FastOpen corresponds to the TCP_FASTOPEN flag. If true the listener will set up the socket for this behaviour. See https://lwn.net/Articles/508865/ for details.
IPv6 sets if the listener uses IPv6 or IPv4