Skip to content

Commit 9e457eb

Browse files
authored
mod acceptConn (#2005)
* add connKeepAliveer interface{}. * use connKeepAliveer insteadof *net.TCPConn to set TCPKeepalive and TCPKeepalivePeriod
1 parent 69a68df commit 9e457eb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

server.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1979,6 +1979,12 @@ func (s *Server) ShutdownWithContext(ctx context.Context) (err error) {
19791979
}
19801980
}
19811981

1982+
type connKeepAliveer interface {
1983+
SetKeepAlive(keepalive bool) error
1984+
SetKeepAlivePeriod(d time.Duration) error
1985+
io.Closer
1986+
}
1987+
19821988
func acceptConn(s *Server, ln net.Listener, lastPerIPErrorTime *time.Time) (net.Conn, error) {
19831989
for {
19841990
c, err := ln.Accept()
@@ -1995,7 +2001,7 @@ func acceptConn(s *Server, ln net.Listener, lastPerIPErrorTime *time.Time) (net.
19952001
return nil, io.EOF
19962002
}
19972003

1998-
if tc, ok := c.(*net.TCPConn); ok && s.TCPKeepalive {
2004+
if tc, ok := c.(connKeepAliveer); ok && s.TCPKeepalive {
19992005
if err := tc.SetKeepAlive(s.TCPKeepalive); err != nil {
20002006
_ = tc.Close()
20012007
return nil, err

0 commit comments

Comments
 (0)