mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 10:34:01 +03:00
Merge pull request #459 from dolonet/fix/openbsd-keepalive
Fix TCP keepalive setup on OpenBSD
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@ func SetServerSocketOptions(conn net.Conn, bufferSize int) error {
|
||||
}
|
||||
|
||||
func setCommonSocketOptions(conn *net.TCPConn) error {
|
||||
if err := conn.SetKeepAliveConfig(net.KeepAliveConfig{
|
||||
if err := applyKeepAlive(conn, net.KeepAliveConfig{
|
||||
Enable: true,
|
||||
Idle: DefaultKeepAliveIdle,
|
||||
Interval: DefaultKeepAliveInterval,
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
//go:build !openbsd
|
||||
|
||||
package network
|
||||
|
||||
import "net"
|
||||
|
||||
// applyKeepAlive enables TCP keepalive on conn and applies the per-socket
|
||||
// idle/interval/count tuning from cfg.
|
||||
func applyKeepAlive(conn *net.TCPConn, cfg net.KeepAliveConfig) error {
|
||||
return conn.SetKeepAliveConfig(cfg) //nolint: wrapcheck
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package network
|
||||
|
||||
import "net"
|
||||
|
||||
// applyKeepAlive enables (or disables) TCP keepalive on conn.
|
||||
//
|
||||
// OpenBSD has no user-settable per-socket TCP keepalive options: TCP_KEEPIDLE,
|
||||
// TCP_KEEPINTVL and TCP_KEEPCNT do not exist on OpenBSD, and Go's
|
||||
// (*TCPConn).SetKeepAliveConfig therefore returns ENOPROTOOPT ("protocol not
|
||||
// available") for any non-negative Idle/Interval/Count value (see
|
||||
// src/net/tcpsockopt_openbsd.go in the Go source tree). Calling
|
||||
// SetKeepAliveConfig with mtg's defaults (zero values) breaks every accepted
|
||||
// listener connection and every outbound dial on OpenBSD.
|
||||
//
|
||||
// On OpenBSD we only flip SO_KEEPALIVE on or off; the keepalive timing is
|
||||
// controlled system-wide via the sysctl knobs net.inet.tcp.keepidle and
|
||||
// net.inet.tcp.keepintvl.
|
||||
func applyKeepAlive(conn *net.TCPConn, cfg net.KeepAliveConfig) error {
|
||||
return conn.SetKeepAlive(cfg.Enable) //nolint: wrapcheck
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func setCommonSocketOptions(conn *net.TCPConn, keepAliveConfig net.KeepAliveConfig) error {
|
||||
if err := conn.SetKeepAliveConfig(keepAliveConfig); err != nil {
|
||||
if err := applyKeepAlive(conn, keepAliveConfig); err != nil {
|
||||
return fmt.Errorf("cannot configure TCP keepalive: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
//go:build !openbsd
|
||||
|
||||
package network
|
||||
|
||||
import "net"
|
||||
|
||||
// applyKeepAlive enables TCP keepalive on conn and applies the per-socket
|
||||
// idle/interval/count tuning from cfg.
|
||||
func applyKeepAlive(conn *net.TCPConn, cfg net.KeepAliveConfig) error {
|
||||
return conn.SetKeepAliveConfig(cfg) //nolint: wrapcheck
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package network
|
||||
|
||||
import "net"
|
||||
|
||||
// applyKeepAlive enables (or disables) TCP keepalive on conn.
|
||||
//
|
||||
// OpenBSD has no user-settable per-socket TCP keepalive options: TCP_KEEPIDLE,
|
||||
// TCP_KEEPINTVL and TCP_KEEPCNT do not exist on OpenBSD, and Go's
|
||||
// (*TCPConn).SetKeepAliveConfig therefore returns ENOPROTOOPT ("protocol not
|
||||
// available") for any non-negative Idle/Interval/Count value (see
|
||||
// src/net/tcpsockopt_openbsd.go in the Go source tree). Calling
|
||||
// SetKeepAliveConfig with mtg's defaults (zero values) breaks every accepted
|
||||
// listener connection and every outbound dial on OpenBSD.
|
||||
//
|
||||
// On OpenBSD we only flip SO_KEEPALIVE on or off; the keepalive timing is
|
||||
// controlled system-wide via the sysctl knobs net.inet.tcp.keepidle and
|
||||
// net.inet.tcp.keepintvl.
|
||||
func applyKeepAlive(conn *net.TCPConn, cfg net.KeepAliveConfig) error {
|
||||
return conn.SetKeepAlive(cfg.Enable) //nolint: wrapcheck
|
||||
}
|
||||
Reference in New Issue
Block a user