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 11package gun
22
33import (
4+ "net"
5+ "net/http"
46 "sync"
7+ "time"
58 "unsafe"
69
710 "golang.org/x/net/http2"
@@ -13,19 +16,39 @@ type clientConnPool struct {
1316 conns map [string ][]* http2.ClientConn // key is host:port
1417}
1518
19+ type clientConn struct {
20+ t * http.Transport
21+ tconn net.Conn // usually *tls.Conn, except specialized impls
22+ }
23+
1624type efaceWords struct {
1725 typ unsafe.Pointer
1826 data unsafe.Pointer
1927}
2028
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+
2144func (tw * TransportWrap ) Close () error {
2245 connPool := transportConnPool (tw .Transport )
2346 p := (* clientConnPool )((* efaceWords )(unsafe .Pointer (& connPool )).data )
2447 p .mu .Lock ()
2548 defer p .mu .Unlock ()
2649 for _ , vv := range p .conns {
2750 for _ , cc := range vv {
28- cc . Close ( )
51+ closeClientConn ( cc )
2952 }
3053 }
3154 return nil
You can’t perform that action at this time.
0 commit comments