mirror of
https://github.com/tailscale/tailscale.git
synced 2025-09-21 05:31:36 +02:00
For eventual use by net/udprelay.Server Updates tailscale/corp#31164 Signed-off-by: Jordan Whited <jordan@tailscale.com>
38 lines
826 B
Go
38 lines
826 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Package sockopts contains logic for applying socket options.
|
|
package sockopts
|
|
|
|
import (
|
|
"net"
|
|
"runtime"
|
|
|
|
"tailscale.com/types/nettype"
|
|
)
|
|
|
|
// BufferDirection represents either the read/receive or write/send direction
|
|
// of a socket buffer.
|
|
type BufferDirection string
|
|
|
|
const (
|
|
ReadDirection BufferDirection = "read"
|
|
WriteDirection BufferDirection = "write"
|
|
)
|
|
|
|
func portableSetBufferSize(pconn nettype.PacketConn, direction BufferDirection, size int) error {
|
|
if runtime.GOOS == "plan9" {
|
|
// Not supported. Don't try. Avoid logspam.
|
|
return nil
|
|
}
|
|
var err error
|
|
if c, ok := pconn.(*net.UDPConn); ok {
|
|
if direction == WriteDirection {
|
|
err = c.SetWriteBuffer(size)
|
|
} else {
|
|
err = c.SetReadBuffer(size)
|
|
}
|
|
}
|
|
return err
|
|
}
|