listener

package
v0.13.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

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

func ListenAndServeAsync(server *http.Server) error

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

func ListenAndServeTLSAsync(server *http.Server, certFile, keyFile string) error

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.

func (*CachingTCPKeepAliveListener) Accept

func (ln *CachingTCPKeepAliveListener) Accept() (net.Conn, error)

Accept a connection, set its keepalive time, and cache its associated file descriptor for subsequent usage for measurement purposes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL