Documentation ¶
Overview ¶
Package listener provides generic functions which extend the capabilities of the http package. This is a fork of github.com/m-lab/go which is specially tailored for the needs of ndt7. I believe we will want to enhance the code at github.com/m-lab/go and make this code unnecessary.
The code here eliminates an annoying race condition in net/http that prevents you from knowing when it is safe to connect to the server socket. For the functions in this package, the listening socket is fully estabished when the function returns, and it is safe to run an HTTP GET immediately.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServeAsync ¶
ListenAndServeAsync starts an http server. The server will run until Shutdown() or Close() is called, but this function will return once the listening socket is established. This means that when this function returns, the server is immediately available for an http GET to be run against it.
Returns a non-nil error if the listening socket can't be established. Logs a fatal error if the server dies for a reason besides ErrServerClosed. If the server.Addr is set to :0, then after this function returns server.Addr will contain the address and port which this server is listening on.
func ListenAndServeTLSAsync ¶
ListenAndServeTLSAsync starts an https server. The server will run until Shutdown() or Close() is called, but this function will return once the listening socket is established. This means that when this function returns, the server is immediately available for an https GET to be run against it.
Returns a non-nil error if the listening socket can't be established. Logs a fatal error if the server dies for a reason besides ErrServerClosed.
Types ¶
type CachingTCPKeepAliveListener ¶
type CachingTCPKeepAliveListener struct {
*net.TCPListener
}
CachingTCPKeepAliveListener sets TCP keep-alive timeouts on accepted connections. It's used by ListenAndServe and ListenAndServeTLS so dead TCP connections (e.g. closing laptop mid-download) eventually go away.