about summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/keepalive_dummy.go11
-rw-r--r--lib/keepalive_linux.go17
2 files changed, 28 insertions, 0 deletions
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)
+}