Commit 53a20713 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: document that ListenAndServe is a bit more than Listen+Serve

Document that ListenAndServe and ListenAndServeTLS also set TCP
keep-alives.

Fixes #12748

Change-Id: Iba2e8a58dd657eba326db49a6c872e2d972883a4
Reviewed-on: https://go-review.googlesource.com/17681Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 7a2913c9
...@@ -1994,6 +1994,7 @@ func (sh serverHandler) ServeHTTP(rw ResponseWriter, req *Request) { ...@@ -1994,6 +1994,7 @@ func (sh serverHandler) ServeHTTP(rw ResponseWriter, req *Request) {
// ListenAndServe listens on the TCP network address srv.Addr and then // ListenAndServe listens on the TCP network address srv.Addr and then
// calls Serve to handle requests on incoming connections. // calls Serve to handle requests on incoming connections.
// Accepted connections are configured to enable TCP keep-alives.
// If srv.Addr is blank, ":http" is used. // If srv.Addr is blank, ":http" is used.
// ListenAndServe always returns a non-nil error. // ListenAndServe always returns a non-nil error.
func (srv *Server) ListenAndServe() error { func (srv *Server) ListenAndServe() error {
...@@ -2074,8 +2075,10 @@ func (s *Server) logf(format string, args ...interface{}) { ...@@ -2074,8 +2075,10 @@ func (s *Server) logf(format string, args ...interface{}) {
// ListenAndServe listens on the TCP network address addr // ListenAndServe listens on the TCP network address addr
// and then calls Serve with handler to handle requests // and then calls Serve with handler to handle requests
// on incoming connections. Handler is typically nil, // on incoming connections.
// in which case the DefaultServeMux is used. // Accepted connections are configured to enable TCP keep-alives.
// Handler is typically nil, in which case the DefaultServeMux is
// used.
// //
// A trivial example server is: // A trivial example server is:
// //
...@@ -2131,13 +2134,14 @@ func ListenAndServe(addr string, handler Handler) error { ...@@ -2131,13 +2134,14 @@ func ListenAndServe(addr string, handler Handler) error {
// One can use generate_cert.go in crypto/tls to generate cert.pem and key.pem. // One can use generate_cert.go in crypto/tls to generate cert.pem and key.pem.
// //
// ListenAndServeTLS always returns a non-nil error. // ListenAndServeTLS always returns a non-nil error.
func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler) error { func ListenAndServeTLS(addr, certFile, keyFile string, handler Handler) error {
server := &Server{Addr: addr, Handler: handler} server := &Server{Addr: addr, Handler: handler}
return server.ListenAndServeTLS(certFile, keyFile) return server.ListenAndServeTLS(certFile, keyFile)
} }
// ListenAndServeTLS listens on the TCP network address srv.Addr and // ListenAndServeTLS listens on the TCP network address srv.Addr and
// then calls Serve to handle requests on incoming TLS connections. // then calls Serve to handle requests on incoming TLS connections.
// Accepted connections are configured to enable TCP keep-alives.
// //
// Filenames containing a certificate and matching private key for the // Filenames containing a certificate and matching private key for the
// server must be provided if the Server's TLSConfig.Certificates is // server must be provided if the Server's TLSConfig.Certificates is
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment