Fix http2 transport close

This commit is contained in:
世界 2023-03-30 19:06:57 +08:00
parent 2012c0ca1e
commit 19a35ec6a4
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
3 changed files with 24 additions and 0 deletions

View file

@ -12,6 +12,7 @@ import (
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/common/tls"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-box/transport/v2rayhttp"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
@ -93,3 +94,8 @@ func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
}()
return conn, nil
}
func (c *Client) Close() error {
v2rayhttp.CloseIdleConnections(c.transport)
return nil
}

View file

@ -167,3 +167,8 @@ func (c *Client) dialHTTP2(ctx context.Context) (net.Conn, error) {
}()
return conn, nil
}
func (c *Client) Close() error {
CloseIdleConnections(c.transport)
return nil
}

View file

@ -0,0 +1,13 @@
package v2rayhttp
import "net/http"
type ConnectionPool interface {
CloseIdleConnections()
}
func CloseIdleConnections(transport http.RoundTripper) {
if connectionPool, ok := transport.(ConnectionPool); ok {
connectionPool.CloseIdleConnections()
}
}