mod acceptConn (#2005)

* add connKeepAliveer interface{}.
* use connKeepAliveer insteadof *net.TCPConn to set TCPKeepalive and TCPKeepalivePeriod
This commit is contained in:
shawn wang
2025-05-07 13:14:06 +08:00
committed by GitHub
parent 69a68df4eb
commit 9e457ebd98
+7 -1
View File
@@ -1979,6 +1979,12 @@ func (s *Server) ShutdownWithContext(ctx context.Context) (err error) {
}
}
type connKeepAliveer interface {
SetKeepAlive(keepalive bool) error
SetKeepAlivePeriod(d time.Duration) error
io.Closer
}
func acceptConn(s *Server, ln net.Listener, lastPerIPErrorTime *time.Time) (net.Conn, error) {
for {
c, err := ln.Accept()
@@ -1995,7 +2001,7 @@ func acceptConn(s *Server, ln net.Listener, lastPerIPErrorTime *time.Time) (net.
return nil, io.EOF
}
if tc, ok := c.(*net.TCPConn); ok && s.TCPKeepalive {
if tc, ok := c.(connKeepAliveer); ok && s.TCPKeepalive {
if err := tc.SetKeepAlive(s.TCPKeepalive); err != nil {
_ = tc.Close()
return nil, err