-
Notifications
You must be signed in to change notification settings - Fork 98
/
control_unix.go
37 lines (29 loc) · 882 Bytes
/
control_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//go:build linux || freebsd || darwin || aix || dragonfly || netbsd || openbsd
// +build linux freebsd darwin aix dragonfly netbsd openbsd
package ftpserver
import (
"fmt"
"syscall"
"golang.org/x/sys/unix"
)
// Control defines the function to use as dialer Control to reuse the same port/address
func Control(_, _ string, c syscall.RawConn) error {
var errSetOpts error
err := c.Control(func(unixFd uintptr) {
errSetOpts = unix.SetsockoptInt(int(unixFd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1)
if errSetOpts != nil {
return
}
errSetOpts = unix.SetsockoptInt(int(unixFd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
if errSetOpts != nil {
return
}
})
if err != nil {
return fmt.Errorf("unable to set control options: %w", err)
}
if errSetOpts != nil {
errSetOpts = fmt.Errorf("unable to set control options: %w", errSetOpts)
}
return errSetOpts
}