File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change 1
1
package gun
2
2
3
3
import (
4
+ "net"
5
+ "net/http"
4
6
"sync"
7
+ "time"
5
8
"unsafe"
6
9
7
10
"golang.org/x/net/http2"
@@ -13,19 +16,39 @@ type clientConnPool struct {
13
16
conns map [string ][]* http2.ClientConn // key is host:port
14
17
}
15
18
19
+ type clientConn struct {
20
+ t * http.Transport
21
+ tconn net.Conn // usually *tls.Conn, except specialized impls
22
+ }
23
+
16
24
type efaceWords struct {
17
25
typ unsafe.Pointer
18
26
data unsafe.Pointer
19
27
}
20
28
29
+ type tlsConn interface {
30
+ net.Conn
31
+ NetConn () net.Conn
32
+ }
33
+
34
+ func closeClientConn (cc * http2.ClientConn ) { // like forceCloseConn() in http2.ClientConn but also apply for tls-like conn
35
+ if conn , ok := (* clientConn )(unsafe .Pointer (cc )).tconn .(tlsConn ); ok {
36
+ t := time .AfterFunc (time .Second , func () {
37
+ _ = conn .NetConn ().Close ()
38
+ })
39
+ defer t .Stop ()
40
+ }
41
+ _ = cc .Close ()
42
+ }
43
+
21
44
func (tw * TransportWrap ) Close () error {
22
45
connPool := transportConnPool (tw .Transport )
23
46
p := (* clientConnPool )((* efaceWords )(unsafe .Pointer (& connPool )).data )
24
47
p .mu .Lock ()
25
48
defer p .mu .Unlock ()
26
49
for _ , vv := range p .conns {
27
50
for _ , cc := range vv {
28
- cc . Close ( )
51
+ closeClientConn ( cc )
29
52
}
30
53
}
31
54
return nil
You can’t perform that action at this time.
0 commit comments