sockbuf

package
v0.6.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package sockbuf reports and sets socket buffer sizes on Darwin, making the kernel's silent clamping visible to the caller.

macOS clamps SO_SNDBUF and SO_RCVBUF requests to the kern.ipc.maxsockbuf sysctl ceiling without returning an error: a request for 8 MiB may install 2 MiB and report success. Code that sizes buffers with setsockopt alone cannot tell that it was truncated.

The functions here read the value back after setting it and return what the kernel actually installed. A returned size smaller than the requested size is not an error; it is the kernel's answer, and comparing the two is the only reliable way to detect the clamp.

actual, err := sockbuf.SetRecvBuffer(fd, 8<<20)
if err != nil {
	return err
}
if actual < 8<<20 {
	log.Printf("kernel clamped receive buffer to %d bytes", actual)
}

This package uses only public APIs and works on any Darwin version.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaxSockBuf

func MaxSockBuf() (int, error)

MaxSockBuf reports the kern.ipc.maxsockbuf sysctl, the ceiling the kernel applies to SO_SNDBUF and SO_RCVBUF requests.

A request larger than this value is silently truncated rather than rejected, so callers that need to distinguish "asked for too much" from "got what I asked for" should consult it before sizing.

func SetRecvBuffer

func SetRecvBuffer(fd, bytes int) (actual int, err error)

SetRecvBuffer requests bytes for the socket's receive buffer and reports the size the kernel installed, which may be smaller than requested.

func SetSendBuffer

func SetSendBuffer(fd, bytes int) (actual int, err error)

SetSendBuffer requests bytes for the socket's send buffer and reports the size the kernel installed, which may be smaller than requested.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL