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.
Entry points accept a raw file descriptor ([SetRecvBuffer], [SetSendBuffer]), a syscall.RawConn ([SetRecvBufferRawConn], [SetSendBufferRawConn]), or any syscall.Conn such as *net.UDPConn and *net.TCPConn ([SetRecvBufferConn], [SetSendBufferConn]).
Performance note: existing throughput measurements pairing this package with x/udpbatch are loopback-only. Loopback buffer-sizing gains reflect local kernel queue headroom rather than wire pacing, NIC rings, or network loss; validate buffer sizing on the target interface and peer.
This package uses only public APIs and works on any Darwin version.