jsocketpp 1.0
A cross-platform C++20 socket library.
Loading...
Searching...
No Matches
jsocketpp::ReadExactOptions Struct Reference

Policy for enforcing an exact-byte receive on a single UDP datagram. More...

#include <DatagramSocket.hpp>

Collaboration diagram for jsocketpp::ReadExactOptions:

Public Attributes

DatagramReadOptions base {}
 Base receive options for controlling preflight behavior, system flags, and side effects.
bool requireExact = true
 Controls whether the datagram size must match exactly.
bool padIfSmaller = false
 Controls zero-padding behavior for undersized datagrams.
bool errorOnTruncate = true
 Controls error handling for oversized datagrams.
bool autoResizeDynamic = true
 Controls automatic resizing of dynamic containers.

Detailed Description

Policy for enforcing an exact-byte receive on a single UDP datagram.

This structure defines the policy for reading a UDP datagram that must match a specific size requirement. It provides fine-grained control over the handling of datagrams that are larger or smaller than the expected size, including padding behavior and error handling.

Key Features

  • Enforces exact datagram size matching
  • Controls zero-padding behavior for undersized datagrams
  • Manages truncation vs error behavior for oversized datagrams
  • Supports automatic buffer resizing for dynamic containers
See also
DatagramSocket::readExact()
DatagramSocket::readIntoExact()
Since
1.0

Member Data Documentation

◆ autoResizeDynamic

bool jsocketpp::ReadExactOptions::autoResizeDynamic = true

Controls automatic resizing of dynamic containers.

When true and receiving into a dynamic container (e.g., std::string, std::vector), the container will be automatically resized to the exact size before the receive operation.

This ensures efficient memory use but may trigger reallocation.

Note
Has no effect on fixed-size containers or raw buffers.

◆ base

DatagramReadOptions jsocketpp::ReadExactOptions::base {}

Base receive options for controlling preflight behavior, system flags, and side effects.

This field inherits the core receive options from DatagramReadOptions, including:

  • Datagram sizing mode (DatagramReceiveMode)
  • Buffer growth/shrink policies
  • Additional receive flags (e.g., MSG_PEEK)
  • Remote peer tracking and address resolution
See also
DatagramReadOptions

◆ errorOnTruncate

bool jsocketpp::ReadExactOptions::errorOnTruncate = true

Controls error handling for oversized datagrams.

When true, receiving a datagram larger than the requested size will throw a SocketException. When false, the datagram is silently truncated to the requested size.

Note
Only meaningful when requireExact is false.

◆ padIfSmaller

bool jsocketpp::ReadExactOptions::padIfSmaller = false

Controls zero-padding behavior for undersized datagrams.

When true and the received datagram is smaller than the requested size:

  • For raw buffers: fill remaining bytes with zeros
  • For fixed-size containers: zero-initialize unused space
  • For dynamic containers: no effect (container is sized to actual data)
Note
Only meaningful when requireExact is false.

◆ requireExact

bool jsocketpp::ReadExactOptions::requireExact = true

Controls whether the datagram size must match exactly.

When true, the datagram's payload size must match the requested size exactly; otherwise, a SocketException is thrown. This enforces strict size matching for protocols that require fixed-size messages.

Note
This is independent of padIfSmaller and errorOnTruncate, which control how size mismatches are handled when this is false.

The documentation for this struct was generated from the following file: