Documentation ¶
Overview ¶
Package localsrv provides helpers for running local TCP servers.
It is used by various machine-local authentication protocols to launch local listening servers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ServeFunc ¶
ServeFunc is called from internal goroutine to run the server loop.
When server stops, the given listener will be closed and the given context will be canceled. The wait group is used to wait for pending requests: increment it when starting processing a request, and decrement when done.
If ServeFunc returns after the listener is closed, the returned error is ignored (it is most likely caused by the closed listener).
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server runs a local TCP server.
func (*Server) Start ¶
func (s *Server) Start(ctx context.Context, name string, port int, serve ServeFunc) (*net.TCPAddr, error)
Start launches background goroutine with the serving loop 'serve'.
Returns the address the listening socket is bound to.
The provided context is used as base context for request handlers and for logging. 'name' identifies this server in logs, and 'port' specifies a TCP port number to bind to (or 0 to auto-pick one).
The server must be eventually stopped with Stop().
func (*Server) Stop ¶
Stop closes the listening socket, notifies pending requests to abort and stops the internal serving goroutine.
Safe to call multiple times. Once stopped, the server cannot be started again (make a new instance of Server instead).
Uses the given context for the deadline when waiting for the serving loop to stop.