github.com/hoffie/larasync@v0.0.0-20151025221940-0384d2bddcef/api/server/tcpkeepalive.go (about) 1 package server 2 3 import ( 4 "net" 5 "time" 6 ) 7 8 // from net/http; sadly it's private... 9 10 // tcpKeepAliveListener sets TCP keep-alive timeouts on accepted 11 // connections. It's used by ListenAndServe and ListenAndServeTLS so 12 // dead TCP connections (e.g. closing laptop mid-download) eventually 13 // go away. 14 type tcpKeepAliveListener struct { 15 *net.TCPListener 16 } 17 18 func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) { 19 tc, err := ln.AcceptTCP() 20 if err != nil { 21 return 22 } 23 tc.SetKeepAlive(true) 24 tc.SetKeepAlivePeriod(3 * time.Minute) 25 return tc, nil 26 }