Documentation ¶
Overview ¶
Package net implements functions for running network servers.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StartAcceptLoop ¶
StartAcceptLoop starts an accept loop for the given listener, returning accepted connections via a channel while handling temporary network errors. Fatal errors are returned via the error channel with the listener closed on return.
func StartForeverAcceptLoop ¶
StartForeverAcceptLoop starts an accept loop for the given listener that retries forever, returning accepted connections via a channel while handling temporary network errors. Fatal errors are returned via the error channel with the listener closed on return.
Example ¶
package main import ( "io" "log" "net" xnet "github.com/m3db/m3/src/x/net" "github.com/m3db/m3/src/x/retry" ) func main() { // Create a new listener. l, err := net.Listen("tcp", ":0") if err != nil { log.Fatal(err) } defer l.Close() // Start accepting incoming connections. var ( opts = retry.NewOptions() connCh, errCh = xnet.StartAcceptLoop(l, opts) ) for { select { case conn := <-connCh: // Handle the connection in a new goroutine. go func(c net.Conn) { io.Copy(c, c) c.Close() }(conn) case err := <-errCh: // Only fatal errors are returned on errCh. log.Fatal(err) } } }
Output:
Types ¶
type ListenerOption ¶ added in v0.15.0
type ListenerOption func(o *ListenerOptions)
ListenerOption is a listener option that can be applied to a set of listener options.
func ListenerReusePort ¶ added in v0.15.0
func ListenerReusePort(value bool) ListenerOption
ListenerReusePort is a listener option to reuse ports.
type ListenerOptions ¶ added in v0.15.0
type ListenerOptions struct {
// contains filtered or unexported fields
}
ListenerOptions is a set of listener options that can create listeners.
func NewListenerOptions ¶ added in v0.15.0
func NewListenerOptions(opts ...ListenerOption) ListenerOptions
NewListenerOptions creates a set of listener options with supplied options.