aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJonathan Davies <[email protected]>2023-05-23 17:56:00 +0100
committerGitHub <[email protected]>2023-05-23 10:56:00 -0600
commit942fbb37ec46f1907e57a04c44ca790bd47ed52c (patch)
tree6211f3c8af32b58d5b6717aac52436f3548ed222
parentcee4441cb1d485b38d728168a315cda5641d84fb (diff)
downloadcaddy-942fbb37ec46f1907e57a04c44ca790bd47ed52c.tar.gz
caddy-942fbb37ec46f1907e57a04c44ca790bd47ed52c.zip
core: Use SO_REUSEPORT_LB on FreeBSD (#5554)
to balance load between threads.
-rw-r--r--listen_unix.go2
-rw-r--r--listen_unix_setopt.go7
-rw-r--r--listen_unix_setopt_freebsd.go7
3 files changed, 15 insertions, 1 deletions
diff --git a/listen_unix.go b/listen_unix.go
index 50d9a66df..7011a1e62 100644
--- a/listen_unix.go
+++ b/listen_unix.go
@@ -119,7 +119,7 @@ func reusePort(network, address string, conn syscall.RawConn) error {
return nil
}
return conn.Control(func(descriptor uintptr) {
- if err := unix.SetsockoptInt(int(descriptor), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
+ if err := unix.SetsockoptInt(int(descriptor), unix.SOL_SOCKET, unixSOREUSEPORT, 1); err != nil {
Log().Error("setting SO_REUSEPORT",
zap.String("network", network),
zap.String("address", address),
diff --git a/listen_unix_setopt.go b/listen_unix_setopt.go
new file mode 100644
index 000000000..c9675f928
--- /dev/null
+++ b/listen_unix_setopt.go
@@ -0,0 +1,7 @@
+//go:build unix && !freebsd
+
+package caddy
+
+import "golang.org/x/sys/unix"
+
+const unixSOREUSEPORT = unix.SO_REUSEPORT
diff --git a/listen_unix_setopt_freebsd.go b/listen_unix_setopt_freebsd.go
new file mode 100644
index 000000000..065205408
--- /dev/null
+++ b/listen_unix_setopt_freebsd.go
@@ -0,0 +1,7 @@
+//go:build freebsd
+
+package caddy
+
+import "golang.org/x/sys/unix"
+
+const unixSOREUSEPORT = unix.SO_REUSEPORT_LB