Skip to content

Commit

Permalink
Merge pull request #57 from openziti/enable-tcp-keepalive
Browse files Browse the repository at this point in the history
enable TCP keep-alive on inbound connections
  • Loading branch information
ekoby authored Aug 28, 2023
2 parents fbabe8f + 35f09a3 commit 1ea82dd
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tls/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ import (
"time"
)

const (
// same as golang Dial default
keepAlive = 15 * time.Second
)

var noProtocol = ""
var handlerKey = struct{}{}

Expand Down Expand Up @@ -193,6 +198,13 @@ type sharedListener struct {

func (self *sharedListener) processConn(conn *tls.Conn) {
log := self.log

if tcpConn, ok := conn.NetConn().(*net.TCPConn); ok {
_ = tcpConn.SetNoDelay(true)
_ = tcpConn.SetKeepAlive(true)
_ = tcpConn.SetKeepAlivePeriod(keepAlive)
}

// sharedListener.getConfig will select the right handler during handshake based on ClientHelloInfo
// no need to do another look up here
var handler *protocolHandler
Expand Down

0 comments on commit 1ea82dd

Please sign in to comment.