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 ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.