mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-26 17:46:34 +03:00
mod acceptConn (#2005)
* add connKeepAliveer interface{}.
* use connKeepAliveer insteadof *net.TCPConn to set TCPKeepalive and TCPKeepalivePeriod
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user