|
|
@@ -3,8 +3,6 @@ package network
|
|
3
|
3
|
import (
|
|
4
|
4
|
"fmt"
|
|
5
|
5
|
"net"
|
|
6
|
|
-
|
|
7
|
|
- "golang.org/x/sys/unix"
|
|
8
|
6
|
)
|
|
9
|
7
|
|
|
10
|
8
|
// SetClientSocketOptions tunes a TCP socket that represents a connection to
|
|
|
@@ -53,19 +51,9 @@ func setCommonSocketOptions(conn *net.TCPConn, bufferSize int) error {
|
|
53
|
51
|
return fmt.Errorf("cannot get underlying raw connection: %w", err)
|
|
54
|
52
|
}
|
|
55
|
53
|
|
|
56
|
|
- rawConn.Control(func(fd uintptr) { // nolint: errcheck
|
|
57
|
|
- err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1)
|
|
58
|
|
- if err != nil {
|
|
59
|
|
- err = fmt.Errorf("cannot set SO_REUSEADDR: %w", err)
|
|
60
|
|
-
|
|
61
|
|
- return
|
|
62
|
|
- }
|
|
63
|
|
-
|
|
64
|
|
- err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
|
|
65
|
|
- if err != nil {
|
|
66
|
|
- err = fmt.Errorf("cannot set SO_REUSEPORT: %w", err)
|
|
67
|
|
- }
|
|
68
|
|
- })
|
|
|
54
|
+ if err := setSocketReuseAddrPort(rawConn, bufferSize); err != nil {
|
|
|
55
|
+ return fmt.Errorf("cannot setup SO_REUSEADDR/PORT: %w", err)
|
|
|
56
|
+ }
|
|
69
|
57
|
|
|
70
|
58
|
return nil
|
|
71
|
59
|
}
|