Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1316)

Unified Diff: src/pkg/net/dial.go

Issue 6575050: code review 6575050: net: close dialing fds in DialTimeout (Closed)
Patch Set: diff -r c81f0e83b70b https://go.googlecode.com/hg/ Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/pkg/net/iprawsock_posix.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/net/dial.go
===================================================================
--- a/src/pkg/net/dial.go
+++ b/src/pkg/net/dial.go
@@ -93,13 +93,13 @@
if err != nil {
return nil, err
}
- return dialAddr(net, addr, addri)
+ return dialAddr(net, addr, addri, nil)
}
-func dialAddr(net, addr string, addri Addr) (c Conn, err error) {
+func dialAddr(net, addr string, addri Addr, beforeConnect chan<- *netFD) (c Conn, err error) {
switch ra := addri.(type) {
case *TCPAddr:
- c, err = DialTCP(net, nil, ra)
+ c, err = dialTCP(net, nil, ra, beforeConnect)
case *UDPAddr:
c, err = DialUDP(net, nil, ra)
case *IPAddr:
@@ -130,6 +130,7 @@
}
ch := make(chan pair, 1)
resolvedAddr := make(chan Addr, 1)
+ fdc := make(chan *netFD, 1)
go func() {
_, addri, err := resolveNetAddr("dial", net, addr)
if err != nil {
@@ -137,7 +138,7 @@
return
}
resolvedAddr <- addri // in case we need it for OpError
- c, err := dialAddr(net, addr, addri)
+ c, err := dialAddr(net, addr, addri, fdc)
ch <- pair{c, err}
}()
select {
@@ -157,6 +158,14 @@
Addr: addri,
Err: &timeoutError{},
}
+
+ // Try to close the *netFD, if it was sent.
+ select {
+ case fd := <-fdc:
+ fd.Close()
+ default:
+ }
+
return nil, err
case p := <-ch:
return p.Conn, p.error
« no previous file with comments | « no previous file | src/pkg/net/iprawsock_posix.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b