From e080eac204aa77c3cdc55d3b4cfa45c26bc8a635 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Tue, 30 Apr 2024 01:49:01 +0300 Subject: [PATCH 1/2] refactor(mdns): consolidate platform-specific syscall files - Rename `syscall_linux.go` to `syscall.go` with build constraints for non-BSD and non-Windows platforms. - Merge `syscall_darwin.go` into `syscall_bsd.go` and adjust build constraints for BSD platforms (Darwin, FreeBSD, OpenBSD). - Remove redundant `syscall_freebsd.go`. - Add build constraints to `syscall_windows.go` for Windows platform. --- pkg/mdns/{syscall_linux.go => syscall.go} | 2 ++ .../{syscall_darwin.go => syscall_bsd.go} | 2 ++ pkg/mdns/syscall_freebsd.go | 24 ------------------- pkg/mdns/syscall_windows.go | 2 ++ 4 files changed, 6 insertions(+), 24 deletions(-) rename pkg/mdns/{syscall_linux.go => syscall.go} (78%) rename pkg/mdns/{syscall_darwin.go => syscall_bsd.go} (90%) delete mode 100644 pkg/mdns/syscall_freebsd.go diff --git a/pkg/mdns/syscall_linux.go b/pkg/mdns/syscall.go similarity index 78% rename from pkg/mdns/syscall_linux.go rename to pkg/mdns/syscall.go index fc0caeb05..0e50535ad 100644 --- a/pkg/mdns/syscall_linux.go +++ b/pkg/mdns/syscall.go @@ -1,3 +1,5 @@ +//go:build !(darwin || ios || freebsd || openbsd || netbsd || dragonfly || windows) + package mdns import ( diff --git a/pkg/mdns/syscall_darwin.go b/pkg/mdns/syscall_bsd.go similarity index 90% rename from pkg/mdns/syscall_darwin.go rename to pkg/mdns/syscall_bsd.go index c1f1225b3..6ebb0c93a 100644 --- a/pkg/mdns/syscall_darwin.go +++ b/pkg/mdns/syscall_bsd.go @@ -1,3 +1,5 @@ +//go:build darwin || ios || freebsd || openbsd || netbsd || dragonfly + package mdns import ( diff --git a/pkg/mdns/syscall_freebsd.go b/pkg/mdns/syscall_freebsd.go deleted file mode 100644 index c1f1225b3..000000000 --- a/pkg/mdns/syscall_freebsd.go +++ /dev/null @@ -1,24 +0,0 @@ -package mdns - -import ( - "syscall" -) - -func SetsockoptInt(fd uintptr, level, opt int, value int) (err error) { - // change SO_REUSEADDR and REUSEPORT flags simultaneously for BSD-like OS - // https://github.com/AlexxIT/go2rtc/issues/626 - // https://stackoverflow.com/questions/14388706/how-do-so-reuseaddr-and-so-reuseport-differ/14388707 - if opt == syscall.SO_REUSEADDR { - if err = syscall.SetsockoptInt(int(fd), level, opt, value); err != nil { - return - } - - opt = syscall.SO_REUSEPORT - } - - return syscall.SetsockoptInt(int(fd), level, opt, value) -} - -func SetsockoptIPMreq(fd uintptr, level, opt int, mreq *syscall.IPMreq) (err error) { - return syscall.SetsockoptIPMreq(int(fd), level, opt, mreq) -} diff --git a/pkg/mdns/syscall_windows.go b/pkg/mdns/syscall_windows.go index be283655b..770510cf7 100644 --- a/pkg/mdns/syscall_windows.go +++ b/pkg/mdns/syscall_windows.go @@ -1,3 +1,5 @@ +//go:build windows + package mdns import "syscall" From abe617a346ff22ebba063a9cb8befdea14f658ca Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Wed, 1 May 2024 09:04:04 +0300 Subject: [PATCH 2/2] refactor(ffmpeg): generalize device and hardware support for multiple OS - Rename `device_freebsd.go` to `device_bsd.go` and `hardware_freebsd.go` to `hardware_bsd.go` to reflect broader BSD support (FreeBSD, NetBSD, OpenBSD, Dragonfly). - Update build tags in `device_bsd.go` and `hardware_bsd.go` to include FreeBSD, NetBSD, OpenBSD, and Dragonfly. - Rename `device_linux.go` to `device_unix.go` and `hardware_linux.go` to `hardware_unix.go` to generalize Unix support excluding Darwin-based systems and BSDs. - Add specific build tags to `device_darwin.go`, `device_unix.go`, `hardware_darwin.go`, and `hardware_unix.go` to correctly target their respective operating systems. - Ensure Windows-specific files (`device_windows.go` and `hardware_windows.go`) are correctly tagged for building on Windows. --- internal/ffmpeg/device/{device_freebsd.go => device_bsd.go} | 2 ++ internal/ffmpeg/device/device_darwin.go | 2 ++ internal/ffmpeg/device/{device_linux.go => device_unix.go} | 2 ++ internal/ffmpeg/device/device_windows.go | 2 ++ .../ffmpeg/hardware/{hardware_freebsd.go => hardware_bsd.go} | 2 ++ internal/ffmpeg/hardware/hardware_darwin.go | 2 ++ .../ffmpeg/hardware/{hardware_linux.go => hardware_unix.go} | 2 ++ internal/ffmpeg/hardware/hardware_windows.go | 2 ++ 8 files changed, 16 insertions(+) rename internal/ffmpeg/device/{device_freebsd.go => device_bsd.go} (97%) rename internal/ffmpeg/device/{device_linux.go => device_unix.go} (96%) rename internal/ffmpeg/hardware/{hardware_freebsd.go => hardware_bsd.go} (96%) rename internal/ffmpeg/hardware/{hardware_linux.go => hardware_unix.go} (97%) diff --git a/internal/ffmpeg/device/device_freebsd.go b/internal/ffmpeg/device/device_bsd.go similarity index 97% rename from internal/ffmpeg/device/device_freebsd.go rename to internal/ffmpeg/device/device_bsd.go index f3a26a304..27d5b6154 100644 --- a/internal/ffmpeg/device/device_freebsd.go +++ b/internal/ffmpeg/device/device_bsd.go @@ -1,3 +1,5 @@ +//go:build freebsd || netbsd || openbsd || dragonfly + package device import ( diff --git a/internal/ffmpeg/device/device_darwin.go b/internal/ffmpeg/device/device_darwin.go index ac9b5e431..ba97c0aa9 100644 --- a/internal/ffmpeg/device/device_darwin.go +++ b/internal/ffmpeg/device/device_darwin.go @@ -1,3 +1,5 @@ +//go:build darwin || ios + package device import ( diff --git a/internal/ffmpeg/device/device_linux.go b/internal/ffmpeg/device/device_unix.go similarity index 96% rename from internal/ffmpeg/device/device_linux.go rename to internal/ffmpeg/device/device_unix.go index d1228b157..7b62187f3 100644 --- a/internal/ffmpeg/device/device_linux.go +++ b/internal/ffmpeg/device/device_unix.go @@ -1,3 +1,5 @@ +//go:build unix && !darwin && !freebsd && !netbsd && !openbsd && !dragonfly + package device import ( diff --git a/internal/ffmpeg/device/device_windows.go b/internal/ffmpeg/device/device_windows.go index c14630d35..ff3283117 100644 --- a/internal/ffmpeg/device/device_windows.go +++ b/internal/ffmpeg/device/device_windows.go @@ -1,3 +1,5 @@ +//go:build windows + package device import ( diff --git a/internal/ffmpeg/hardware/hardware_freebsd.go b/internal/ffmpeg/hardware/hardware_bsd.go similarity index 96% rename from internal/ffmpeg/hardware/hardware_freebsd.go rename to internal/ffmpeg/hardware/hardware_bsd.go index 6ef753acd..de24ac5c8 100644 --- a/internal/ffmpeg/hardware/hardware_freebsd.go +++ b/internal/ffmpeg/hardware/hardware_bsd.go @@ -1,3 +1,5 @@ +//go:build freebsd || netbsd || openbsd || dragonfly + package hardware import ( diff --git a/internal/ffmpeg/hardware/hardware_darwin.go b/internal/ffmpeg/hardware/hardware_darwin.go index 8392d2b11..b15055128 100644 --- a/internal/ffmpeg/hardware/hardware_darwin.go +++ b/internal/ffmpeg/hardware/hardware_darwin.go @@ -1,3 +1,5 @@ +//go:build darwin || ios + package hardware import ( diff --git a/internal/ffmpeg/hardware/hardware_linux.go b/internal/ffmpeg/hardware/hardware_unix.go similarity index 97% rename from internal/ffmpeg/hardware/hardware_linux.go rename to internal/ffmpeg/hardware/hardware_unix.go index f0d4858e1..4f688ce40 100644 --- a/internal/ffmpeg/hardware/hardware_linux.go +++ b/internal/ffmpeg/hardware/hardware_unix.go @@ -1,3 +1,5 @@ +//go:build unix && !darwin && !freebsd && !netbsd && !openbsd && !dragonfly + package hardware import ( diff --git a/internal/ffmpeg/hardware/hardware_windows.go b/internal/ffmpeg/hardware/hardware_windows.go index c22639f55..cdf0e12cc 100644 --- a/internal/ffmpeg/hardware/hardware_windows.go +++ b/internal/ffmpeg/hardware/hardware_windows.go @@ -1,3 +1,5 @@ +//go:build windows + package hardware import "github.com/AlexxIT/go2rtc/internal/api"