keep a context in the core, use it for listen/dial, cancel it when closing

This commit is contained in:
Arceliar 2021-06-12 06:06:39 -05:00
parent 3815b13ad5
commit 5b6f730f18
2 changed files with 15 additions and 8 deletions

View file

@ -153,7 +153,7 @@ func (t *tcp) listenURL(u *url.URL, sintf string) (*TcpListener, error) {
func (t *tcp) listen(listenaddr string, upgrade *TcpUpgrade) (*TcpListener, error) {
var err error
ctx := context.Background()
ctx := t.links.core.ctx
lc := net.ListenConfig{
Control: t.tcpContext,
}
@ -270,7 +270,7 @@ func (t *tcp) call(saddr string, options tcpOptions, sintf string) {
if err != nil {
return
}
ctx, done := context.WithTimeout(context.Background(), default_timeout)
ctx, done := context.WithTimeout(t.links.core.ctx, default_timeout)
conn, err = dialer.(proxy.ContextDialer).DialContext(ctx, "tcp", saddr)
done()
if err != nil {
@ -339,7 +339,7 @@ func (t *tcp) call(saddr string, options tcpOptions, sintf string) {
}
}
}
ctx, done := context.WithTimeout(context.Background(), default_timeout)
ctx, done := context.WithTimeout(t.links.core.ctx, default_timeout)
conn, err = dialer.DialContext(ctx, "tcp", dst.String())
done()
if err != nil {