The default buffer capacity for UDP-oriented buffers is 1472, determined as the typical Ethernet MTU (1500 octets) less the typical UDP header length (28). Using buffers of this size, one avoids accidentally creating messages that will be dropped on send because they exceed the MTU, and can receive the largest corresponding UDP message.
While this number is merely typical and not guaranteed to work in all cases, defining
it in one place makes it easy to share and change. For example, another MTU in common
use is 9000 for Jumbo frames, so the value of default_capacity
might change to 8972
in the future.
Iobuf.flip_lo
before calling its callback to
prepare a packet buffer for reading by the callback and Iobuf.reset
afterward to
prepare for the next iteration.
bind address
creates a socket bound to address, and, if address
is a
multicast address, joins the multicast group.
recvfrom_loop_with_buffer_replacement callback
calls callback
synchronously on
each message received. callback
returns the packet buffer for subsequent
iterations, so it can replace the initial packet buffer when necessary. This enables
immediate buffer reuse in the common case and fallback to allocation if we want to
save the packet buffer for asynchronous processing.
recvfrom_loop_with_buffer_replacement callback
calls callback
synchronously on
each message received. callback
returns the packet buffer for subsequent
iterations, so it can replace the initial packet buffer when necessary. This enables
immediate buffer reuse in the common case and fallback to allocation if we want to
save the packet buffer for asynchronous processing.
recvmmsg_loop ~socket callback
iteratively receives up to max_count
packets at a
time on socket
and passes them to callback
. Each packet is up to Iobuf.capacity
bytes.
callback bufs ~count
processes count
packets synchronously.
Config.init config
is used as a prototype for bufs
and as one of the elements.