Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-reuseport
Commits
ce9cd56d
Commit
ce9cd56d
authored
Jan 19, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
disregard eaddrinuse
parent
8437d27d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
29 deletions
+12
-29
impl_unix.go
impl_unix.go
+12
-29
No files found.
impl_unix.go
View file @
ce9cd56d
...
...
@@ -108,36 +108,19 @@ func dial(dialer net.Dialer, netw, addr string) (c net.Conn, err error) {
}
}
// try to connect in a loop for EADDRINUSE errors.
start
:=
time
.
Now
()
for
{
if
fd
,
err
=
socket
(
rfamily
,
socktype
,
rprotocol
);
err
!=
nil
{
return
nil
,
err
}
if
err
=
syscall
.
Bind
(
fd
,
localSockaddr
);
err
!=
nil
{
// fmt.Println("bind failed")
syscall
.
Close
(
fd
)
return
nil
,
err
}
if
err
=
connect
(
fd
,
remoteSockaddr
);
err
!=
nil
{
syscall
.
Close
(
fd
)
if
err
==
syscall
.
EADDRINUSE
{
// if we've waited longer than 2 seconds bail.
if
time
.
Now
()
.
Sub
(
start
)
>
2
*
time
.
Second
{
return
nil
,
err
}
// otherwise, wait a bit and try again
<-
time
.
After
(
20
*
time
.
Microsecond
)
continue
}
// fmt.Println("connect failed", localSockaddr, err)
return
nil
,
err
}
if
fd
,
err
=
socket
(
rfamily
,
socktype
,
rprotocol
);
err
!=
nil
{
return
nil
,
err
}
break
if
err
=
syscall
.
Bind
(
fd
,
localSockaddr
);
err
!=
nil
{
// fmt.Println("bind failed")
syscall
.
Close
(
fd
)
return
nil
,
err
}
if
err
=
connect
(
fd
,
remoteSockaddr
);
err
!=
nil
{
syscall
.
Close
(
fd
)
// fmt.Println("connect failed", localSockaddr, err)
return
nil
,
err
}
if
rprotocol
==
syscall
.
IPPROTO_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