From 15a4cc7d0a84870ba04307154f394f9bdc98fd31 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Sat, 11 Dec 2021 20:53:10 +0100 Subject: [PATCH] imap: fix build on macos Fix the following build error on mac os: worker/imap/worker.go:368:29: undefined: syscall.TCP_KEEPCNT worker/imap/worker.go:376:29: undefined: syscall.TCP_KEEPINTVL These symbols are not defined on darwin. Fixes: 5dfeff75f368 ("imap: add tcp connection options") Signed-off-by: Robin Jarry --- doc/aerc-imap.5.scd | 6 ++++++ lib/keepalive_dummy.go | 11 +++++++++++ lib/keepalive_linux.go | 17 +++++++++++++++++ worker/imap/worker.go | 9 ++------- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 lib/keepalive_dummy.go create mode 100644 lib/keepalive_linux.go diff --git a/doc/aerc-imap.5.scd b/doc/aerc-imap.5.scd index e6a4460..478dbae 100644 --- a/doc/aerc-imap.5.scd +++ b/doc/aerc-imap.5.scd @@ -82,6 +82,9 @@ available: By default, the system tcp socket settings are used. If keepalive-period is specified, this option defaults to 3 probes. + This option is only supported on linux. On other platforms, it will be + ignored. + *keepalive-interval* The interval between subsequential keepalive probes, regardless of what the connection has exchanged in the meantime. Fractional seconds are @@ -90,6 +93,9 @@ available: By default, the system tcp socket settings are used. If keepalive-period is specified, this option defaults to 3s. + This option is only supported on linux. On other platforms, it will be + ignored. + # SEE ALSO *aerc*(1) *aerc-config*(5) diff --git a/lib/keepalive_dummy.go b/lib/keepalive_dummy.go new file mode 100644 index 0000000..205b577 --- /dev/null +++ b/lib/keepalive_dummy.go @@ -0,0 +1,11 @@ +//+build !linux + +package lib + +func SetTcpKeepaliveProbes(fd, count int) error { + return nil +} + +func SetTcpKeepaliveInterval(fd, interval int) error { + return nil +} diff --git a/lib/keepalive_linux.go b/lib/keepalive_linux.go new file mode 100644 index 0000000..0dc3285 --- /dev/null +++ b/lib/keepalive_linux.go @@ -0,0 +1,17 @@ +//+build linux + +package lib + +import ( + "syscall" +) + +func SetTcpKeepaliveProbes(fd, count int) error { + return syscall.SetsockoptInt( + fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPCNT, count) +} + +func SetTcpKeepaliveInterval(fd, interval int) error { + return syscall.SetsockoptInt( + fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, interval) +} diff --git a/worker/imap/worker.go b/worker/imap/worker.go index 239b1cc..0f1c38d 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -7,7 +7,6 @@ import ( "net/url" "strconv" "strings" - "syscall" "time" "github.com/emersion/go-imap" @@ -364,17 +363,13 @@ func (w *IMAPWorker) setKeepaliveParameters(conn *net.TCPConn) error { err = rawConn.Control(func(fdPtr uintptr) { fd := int(fdPtr) // Max number of probes before failure - err := syscall.SetsockoptInt( - fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPCNT, - w.config.keepalive_probes) + err := lib.SetTcpKeepaliveProbes(fd, w.config.keepalive_probes) if err != nil { w.worker.Logger.Printf( "cannot set tcp keepalive probes: %v\n", err) } // Wait time after an unsuccessful probe - err = syscall.SetsockoptInt( - fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, - w.config.keepalive_interval) + err = lib.SetTcpKeepaliveInterval(fd, w.config.keepalive_interval) if err != nil { w.worker.Logger.Printf( "cannot set tcp keepalive interval: %v\n", err)