Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
e1cf7d6f
Commit
e1cf7d6f
authored
Aug 06, 2012
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net: fix spurious EADDRNOTAVAIL errors
R=golang-dev, fullung CC=golang-dev
https://golang.org/cl/6443085
parent
8b5d4c3c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
tcpsock_posix.go
src/pkg/net/tcpsock_posix.go
+21
-2
No files found.
src/pkg/net/tcpsock_posix.go
View file @
e1cf7d6f
...
...
@@ -166,8 +166,17 @@ func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error) {
// use the result. See also:
// http://golang.org/issue/2690
// http://stackoverflow.com/questions/4949858/
for
i
:=
0
;
i
<
2
&&
err
==
nil
&&
laddr
==
nil
&&
selfConnect
(
fd
);
i
++
{
//
// The opposite can also happen: if we ask the kernel to pick an appropriate
// originating local address, sometimes it picks one that is already in use.
// So if the error is EADDRNOTAVAIL, we have to try again too, just for
// a different reason.
//
// The kernel socket code is no doubt enjoying watching us squirm.
for
i
:=
0
;
i
<
2
&&
(
laddr
==
nil
||
laddr
.
Port
==
0
)
&&
(
selfConnect
(
fd
,
err
)
||
spuriousENOTAVAIL
(
err
));
i
++
{
if
err
==
nil
{
fd
.
Close
()
}
fd
,
err
=
internetSocket
(
net
,
laddr
.
toAddr
(),
raddr
.
toAddr
(),
syscall
.
SOCK_STREAM
,
0
,
"dial"
,
sockaddrToTCP
)
}
...
...
@@ -177,7 +186,12 @@ func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error) {
return
newTCPConn
(
fd
),
nil
}
func
selfConnect
(
fd
*
netFD
)
bool
{
func
selfConnect
(
fd
*
netFD
,
err
error
)
bool
{
// If the connect failed, we clearly didn't connect to ourselves.
if
err
!=
nil
{
return
false
}
// The socket constructor can return an fd with raddr nil under certain
// unknown conditions. The errors in the calls there to Getpeername
// are discarded, but we can't catch the problem there because those
...
...
@@ -194,6 +208,11 @@ func selfConnect(fd *netFD) bool {
return
l
.
Port
==
r
.
Port
&&
l
.
IP
.
Equal
(
r
.
IP
)
}
func
spuriousENOTAVAIL
(
err
error
)
bool
{
e
,
ok
:=
err
.
(
*
OpError
)
return
ok
&&
e
.
Err
==
syscall
.
EADDRNOTAVAIL
}
// TCPListener is a TCP network listener.
// Clients should typically use variables of type Listener
// instead of assuming TCP.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment