Set keep-alives for TCP connections

This commit is contained in:
Oleksii Shevchuk 2018-01-30 20:11:54 +02:00
parent c5cb7fe809
commit 70b1f77fc7
2 changed files with 16 additions and 0 deletions

View File

@ -5,6 +5,8 @@ import (
"net"
"net/http"
"time"
"sync/atomic"
log "github.com/sirupsen/logrus"
@ -65,6 +67,10 @@ func (d *Daemon) onListenerDisabled() {
func (d *Daemon) handle(conn net.Conn) {
defer conn.Close()
conn.(*net.TCPConn).SetKeepAlive(true)
conn.(*net.TCPConn).SetKeepAlivePeriod(1 * time.Minute)
conn.(*net.TCPConn).SetNoDelay(true)
brh := &BindRequestHeader{}
err := RecvMessage(conn, brh)

View File

@ -6,6 +6,8 @@ import (
"strconv"
"strings"
"time"
"errors"
"crypto/tls"
@ -201,6 +203,10 @@ func (d *Daemon) listenAcceptTCP(in net.Conn, port int, cherr chan error, chconn
log.Debug("Acceptor exited")
return
} else {
conn.(*net.TCPConn).SetKeepAlive(true)
conn.(*net.TCPConn).SetKeepAlivePeriod(1 * time.Minute)
conn.(*net.TCPConn).SetNoDelay(true)
chconn <- conn
}
@ -253,6 +259,10 @@ func (d *Daemon) listenAcceptTLS(in net.Conn, port int, cherr chan error, chconn
log.Debug("Acceptor exited")
return
} else {
conn.(*net.TCPConn).SetKeepAlive(true)
conn.(*net.TCPConn).SetKeepAlivePeriod(1 * time.Minute)
conn.(*net.TCPConn).SetNoDelay(true)
chconn <- conn
}