net/ktimeout: add a package to set TCP user timeout

Setting a user timeout will be a more practical tuning knob for a number
of endpoints, this provides a way to set it.

Updates tailscale/corp#17587

Signed-off-by: James Tucker <james@tailscale.com>
This commit is contained in:
James Tucker
2024-02-18 18:56:43 -08:00
committed by James Tucker
parent a4a909a20b
commit 8fe504241d
5 changed files with 136 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package ktimeout
import (
"time"
"golang.org/x/sys/unix"
)
// SetUserTimeout sets the TCP_USER_TIMEOUT option on the given file descriptor.
func SetUserTimeout(fd uintptr, timeout time.Duration) error {
return unix.SetsockoptInt(int(fd), unix.SOL_TCP, unix.TCP_USER_TIMEOUT, int(timeout/time.Millisecond))
}