mirror of https://github.com/gorilla/websocket.git
Set keepalive for TCP sockets
This commit is contained in:
parent
a91eba7f97
commit
986e17c2b6
|
@ -162,6 +162,12 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
|
||||||
}
|
}
|
||||||
var brw *bufio.ReadWriter
|
var brw *bufio.ReadWriter
|
||||||
netConn, brw, err = h.Hijack()
|
netConn, brw, err = h.Hijack()
|
||||||
|
tcpConn, ok := netConn.(*net.TCPConn)
|
||||||
|
if ok {
|
||||||
|
// Set TCP keepalive for connections
|
||||||
|
tcpConn.SetKeepAlive(true)
|
||||||
|
tcpConn.SetKeepAlivePeriod(10 * time.Second)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return u.returnError(w, r, http.StatusInternalServerError, err.Error())
|
return u.returnError(w, r, http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue