This reverts commit 15a4cc7d0a84870ba04307154f394f9bdc98fd31.
This allows making use of the keepalive-{probes,interval} settings.
Signed-off-by: kt programs <ktprograms@gmail.com>
---
I have tested and it builds without error on macOS 11.6 with Go 1.17.5
doc/aerc-imap.5.scd | 6 ------lib/keepalive_dummy.go | 12 ------------lib/keepalive_linux.go | 18 ------------------worker/imap/worker.go | 9 +++++++--
4 files changed, 7 insertions(+), 38 deletions(-)
delete mode 100644 lib/keepalive_dummy.go
delete mode 100644 lib/keepalive_linux.go
diff --git a/doc/aerc-imap.5.scd b/doc/aerc-imap.5.scd
index 478dbae..e6a4460 100644
--- a/doc/aerc-imap.5.scd+++ b/doc/aerc-imap.5.scd
@@ -82,9 +82,6 @@ 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
@@ -93,9 +90,6 @@ 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
deleted file mode 100644
index d455a42..0000000
--- a/lib/keepalive_dummy.go
@@ -1,12 +0,0 @@
-//go:build !linux-// +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
deleted file mode 100644
index 4811338..0000000
--- a/lib/keepalive_linux.go
@@ -1,18 +0,0 @@
-//go:build linux-// +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 ba53df2..07d9dde 100644
--- a/worker/imap/worker.go+++ b/worker/imap/worker.go
@@ -7,6 +7,7 @@ import (
"net/url"
"strconv"
"strings"
+ "syscall" "time"
"github.com/emersion/go-imap"
@@ -425,13 +426,17 @@ func (w *IMAPWorker) setKeepaliveParameters(conn *net.TCPConn) error {
err = rawConn.Control(func(fdPtr uintptr) {
fd := int(fdPtr)
// Max number of probes before failure
- err := lib.SetTcpKeepaliveProbes(fd, w.config.keepalive_probes)+ err := syscall.SetsockoptInt(+ fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPCNT,+ 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 = lib.SetTcpKeepaliveInterval(fd, w.config.keepalive_interval)+ err = syscall.SetsockoptInt(+ fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL,+ w.config.keepalive_interval) if err != nil {
w.worker.Logger.Printf(
"cannot set tcp keepalive interval: %v\n", err)
--
2.34.1
I was going to make a v2 patch that, instead of reverting the commit,
would use the non-dummy version of the keepalive functions on darwin,
but in testing, I found that Go 1.13 (the minimum supported by aerc)
only has TCP_KEEP{CNT,INTVL} defined for arm64, and not for x86_64.
Since keepalive-period is all that is needed in order to have keepalive
messages sent, and the other keepalive settings are just for fine
tuning, I am not bothering to enable this functionality on macOS.