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
4db30cca
Commit
4db30cca
authored
Jan 18, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed logs
parent
9897e733
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
15 deletions
+12
-15
impl_unix.go
impl_unix.go
+12
-15
No files found.
impl_unix.go
View file @
4db30cca
...
...
@@ -3,7 +3,6 @@
package
reuseport
import
(
"fmt"
"net"
"os"
"strconv"
...
...
@@ -29,10 +28,9 @@ func dial(dialer net.Dialer, netw, addr string) (c net.Conn, err error) {
netAddr
,
err
:=
resolve
.
ResolveAddr
(
"dial"
,
netw
,
addr
)
if
err
!=
nil
{
fmt
.
Println
(
"resolve addr failed"
)
//
fmt.Println("resolve addr failed")
return
nil
,
err
}
fmt
.
Println
(
"resolve addr ok"
)
switch
netAddr
.
(
type
)
{
case
*
net
.
TCPAddr
,
*
net
.
UDPAddr
:
...
...
@@ -51,30 +49,30 @@ func dial(dialer net.Dialer, netw, addr string) (c net.Conn, err error) {
remoteSockaddr
=
sockaddrnet
.
NetAddrToSockaddr
(
netAddr
)
if
fd
,
err
=
syscall
.
Socket
(
family
,
syscall
.
SOCK_STREAM
,
syscall
.
IPPROTO_TCP
);
err
!=
nil
{
fmt
.
Println
(
"tcp socket failed"
)
//
fmt.Println("tcp socket failed")
return
nil
,
err
}
if
err
=
syscall
.
SetsockoptInt
(
fd
,
syscall
.
SOL_SOCKET
,
soReuseAddr
,
1
);
err
!=
nil
{
fmt
.
Println
(
"reuse addr failed"
)
//
fmt.Println("reuse addr failed")
return
nil
,
err
}
if
err
=
syscall
.
SetsockoptInt
(
fd
,
syscall
.
SOL_SOCKET
,
soReusePort
,
1
);
err
!=
nil
{
fmt
.
Println
(
"reuse port failed"
)
//
fmt.Println("reuse port failed")
return
nil
,
err
}
if
localSockaddr
!=
nil
{
if
err
=
syscall
.
Bind
(
fd
,
localSockaddr
);
err
!=
nil
{
fmt
.
Println
(
"bind failed"
)
//
fmt.Println("bind failed")
return
nil
,
err
}
}
// Set backlog size to the maximum
if
err
=
syscall
.
Connect
(
fd
,
remoteSockaddr
);
err
!=
nil
{
fmt
.
Println
(
"connect failed"
)
//
fmt.Println("connect failed")
return
nil
,
err
}
...
...
@@ -100,10 +98,9 @@ func listen(netw, addr string) (l net.Listener, err error) {
netAddr
,
err
:=
resolve
.
ResolveAddr
(
"listen"
,
netw
,
addr
)
if
err
!=
nil
{
fmt
.
Println
(
"resolve addr failed"
)
//
fmt.Println("resolve addr failed")
return
nil
,
err
}
fmt
.
Println
(
"resolve addr ok"
)
switch
netAddr
.
(
type
)
{
case
*
net
.
TCPAddr
,
*
net
.
UDPAddr
:
...
...
@@ -115,28 +112,28 @@ func listen(netw, addr string) (l net.Listener, err error) {
sockaddr
=
sockaddrnet
.
NetAddrToSockaddr
(
netAddr
)
if
fd
,
err
=
syscall
.
Socket
(
family
,
syscall
.
SOCK_STREAM
,
syscall
.
IPPROTO_TCP
);
err
!=
nil
{
fmt
.
Println
(
"socket failed"
)
//
fmt.Println("socket failed")
return
nil
,
err
}
if
err
=
syscall
.
SetsockoptInt
(
fd
,
syscall
.
SOL_SOCKET
,
soReusePort
,
1
);
err
!=
nil
{
fmt
.
Println
(
"setsockopt reuseport failed"
)
//
fmt.Println("setsockopt reuseport failed")
return
nil
,
err
}
if
err
=
syscall
.
SetsockoptInt
(
fd
,
syscall
.
SOL_SOCKET
,
soReuseAddr
,
1
);
err
!=
nil
{
fmt
.
Println
(
"setsockopt reuseaddr failed"
)
//
fmt.Println("setsockopt reuseaddr failed")
return
nil
,
err
}
if
err
=
syscall
.
Bind
(
fd
,
sockaddr
);
err
!=
nil
{
fmt
.
Println
(
"bind failed"
)
//
fmt.Println("bind failed")
return
nil
,
err
}
// Set backlog size to the maximum
if
err
=
syscall
.
Listen
(
fd
,
syscall
.
SOMAXCONN
);
err
!=
nil
{
fmt
.
Println
(
"listen failed"
)
//
fmt.Println("listen failed")
return
nil
,
err
}
...
...
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