UDP socket send buffer size

Hi,

I've been experimenting with network socket options; in particular, effects when increasing socket send buffer size.

From what I understand, this system I'm testing with permits a max socket send buffer size of 2097152.

Code:
# sysctl kern.ipc.maxsockbuf
kern.ipc.maxsockbuf: 2097152

After I create a UDP socket, it has a default send buffer size of 9216 bytes, no problem.

When I try to increase the send buffer size like so:

Code:
Python 3.11.14 (main, Oct 24 2025, 09:04:34) [Clang 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd7080 on freebsd14
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> udp_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>>> udp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1864134)
>>> udp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1864135)
>>>
>>> udp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1864136)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 55] No buffer space available
>>>

I notice increasing the send buffer up to 1864135 bytes works fine, but errors when I try to go higher.

Sorry if I'm being a dope and missing something simple, but I'm confused as to why I can't set the buffer size larger than 1864135. If anyone can help me understand what's happening please, it would be appreciated. Thank you in advance for your time and consideration.
 
Back
Top