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
eb450c7b
Commit
eb450c7b
authored
Jan 18, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
much simpler resolve
parent
d2ae70d3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
8 deletions
+44
-8
addr.go
addr.go
+20
-0
impl_unix.go
impl_unix.go
+2
-3
interface.go
interface.go
+1
-3
reuse_test.go
reuse_test.go
+21
-2
No files found.
addr.go
0 → 100644
View file @
eb450c7b
package
reuseport
import
(
"net"
)
func
ResolveAddr
(
network
,
address
string
)
(
net
.
Addr
,
error
)
{
switch
network
{
default
:
return
nil
,
net
.
UnknownNetworkError
(
network
)
case
"ip"
,
"ip4"
,
"ip6"
:
return
net
.
ResolveIPAddr
(
network
,
address
)
case
"tcp"
,
"tcp4"
,
"tcp6"
:
return
net
.
ResolveTCPAddr
(
network
,
address
)
case
"udp"
,
"udp4"
,
"udp6"
:
return
net
.
ResolveUDPAddr
(
network
,
address
)
case
"unix"
,
"unixgram"
,
"unixpacket"
:
return
net
.
ResolveUnixAddr
(
network
,
address
)
}
}
impl_unix.go
View file @
eb450c7b
...
...
@@ -8,7 +8,6 @@ import (
"strconv"
"syscall"
resolve
"github.com/jbenet/go-net-resolve-addr"
sockaddrnet
"github.com/jbenet/go-sockaddr/net"
)
...
...
@@ -26,7 +25,7 @@ func dial(dialer net.Dialer, netw, addr string) (c net.Conn, err error) {
localSockaddr
syscall
.
Sockaddr
)
netAddr
,
err
:=
resolve
.
ResolveAddr
(
"dial"
,
netw
,
addr
)
netAddr
,
err
:=
ResolveAddr
(
netw
,
addr
)
if
err
!=
nil
{
// fmt.Println("resolve addr failed")
return
nil
,
err
...
...
@@ -96,7 +95,7 @@ func listen(netw, addr string) (l net.Listener, err error) {
sockaddr
syscall
.
Sockaddr
)
netAddr
,
err
:=
resolve
.
ResolveAddr
(
"listen"
,
netw
,
addr
)
netAddr
,
err
:=
ResolveAddr
(
netw
,
addr
)
if
err
!=
nil
{
// fmt.Println("resolve addr failed")
return
nil
,
err
...
...
interface.go
View file @
eb450c7b
...
...
@@ -20,8 +20,6 @@ package reuseport
import
(
"errors"
"net"
resolve
"github.com/jbenet/go-net-resolve-addr"
)
// ErrUnsuportedProtocol signals that the protocol is not currently
...
...
@@ -45,7 +43,7 @@ func Dial(network, laddr, raddr string) (net.Conn, error) {
var
d
Dialer
if
laddr
!=
""
{
netladdr
,
err
:=
resolve
.
ResolveAddr
(
"dial"
,
network
,
laddr
)
netladdr
,
err
:=
ResolveAddr
(
network
,
laddr
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
reuse_test.go
View file @
eb450c7b
...
...
@@ -5,6 +5,7 @@ import (
"io"
"net"
"os"
"strings"
"testing"
)
...
...
@@ -31,6 +32,13 @@ func TestListenSamePort(t *testing.T) {
// any ports
any
:=
[][]
string
{
[]
string
{
"tcp"
,
"0.0.0.0:0"
,
"0.0.0.0:0"
},
[]
string
{
"tcp4"
,
"0.0.0.0:0"
,
"0.0.0.0:0"
},
[]
string
{
"tcp6"
,
"[::]:0"
,
"[::]:0"
},
[]
string
{
"udp"
,
"0.0.0.0:0"
,
"0.0.0.0:0"
},
[]
string
{
"udp4"
,
"0.0.0.0:0"
,
"0.0.0.0:0"
},
[]
string
{
"udp6"
,
"[::]:0"
,
"[::]:0"
},
[]
string
{
"tcp"
,
"127.0.0.1:0"
},
[]
string
{
"tcp"
,
"[::1]:0"
},
[]
string
{
"tcp4"
,
"127.0.0.1:0"
},
...
...
@@ -100,6 +108,13 @@ func TestListenSamePort(t *testing.T) {
func
TestListenDialSamePort
(
t
*
testing
.
T
)
{
any
:=
[][]
string
{
[]
string
{
"tcp"
,
"0.0.0.0:0"
,
"0.0.0.0:0"
},
[]
string
{
"tcp4"
,
"0.0.0.0:0"
,
"0.0.0.0:0"
},
[]
string
{
"tcp6"
,
"[::]:0"
,
"[::]:0"
},
[]
string
{
"udp"
,
"0.0.0.0:0"
,
"0.0.0.0:0"
},
[]
string
{
"udp4"
,
"0.0.0.0:0"
,
"0.0.0.0:0"
},
[]
string
{
"udp6"
,
"[::]:0"
,
"[::]:0"
},
[]
string
{
"tcp"
,
"127.0.0.1:0"
,
"127.0.0.1:0"
},
[]
string
{
"tcp4"
,
"127.0.0.1:0"
,
"127.0.0.1:0"
},
[]
string
{
"tcp6"
,
"[::1]:0"
,
"[::1]:0"
},
...
...
@@ -155,11 +170,11 @@ func TestListenDialSamePort(t *testing.T) {
defer
c1
.
Close
()
t
.
Log
(
"dialed"
,
c1
.
LocalAddr
(),
c1
.
RemoteAddr
())
if
l1
.
Addr
()
.
String
()
!=
c1
.
LocalAddr
()
.
String
(
)
{
if
getPort
(
l1
.
Addr
()
)
!=
getPort
(
c1
.
LocalAddr
())
{
t
.
Fatal
(
"addrs should match"
,
l1
.
Addr
(),
c1
.
LocalAddr
())
}
if
l2
.
Addr
()
.
String
()
!=
c1
.
RemoteAddr
()
.
String
(
)
{
if
getPort
(
l2
.
Addr
()
)
!=
getPort
(
c1
.
RemoteAddr
())
{
t
.
Fatal
(
"addrs should match"
,
l2
.
Addr
(),
c1
.
RemoteAddr
())
}
...
...
@@ -200,3 +215,7 @@ func TestUnixNotSupported(t *testing.T) {
}
}
}
func
getPort
(
a
net
.
Addr
)
string
{
return
strings
.
Split
(
a
.
String
(),
":"
)[
1
]
}
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