From 894d0c7503a955fd680cfee067fcd32e2f8b6f8b Mon Sep 17 00:00:00 2001 From: ffdfgdfg Date: Mon, 5 Oct 2020 23:38:46 +0800 Subject: [PATCH] add tcp keep alive option for signal connections --- bridge/bridge.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bridge/bridge.go b/bridge/bridge.go index 50ecaa8..41568df 100755 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -233,6 +233,12 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int, vs string) { c.Close() return } + tcpConn, ok := c.Conn.(*net.TCPConn) + if ok { + // add tcp keep alive option for signal connection + _ = tcpConn.SetKeepAlive(true) + _ = tcpConn.SetKeepAlivePeriod(5 * time.Second) + } //the vKey connect by another ,close the client of before if v, ok := s.Client.LoadOrStore(id, NewClient(nil, nil, c, vs)); ok { if v.(*Client).signal != nil {