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

Telemetry data about a single UDP datagram receive operation. More...

#include <DatagramSocket.hpp>

Public Attributes

std::size_t bytes = 0
 Number of bytes successfully copied into the destination buffer.
std::size_t datagramSize = 0
 Full size of the original datagram when it can be determined.
bool truncated = false
 Indicates whether datagram truncation occurred.
sockaddr_storage src {}
 Raw storage for the sender's address information.
socklen_t srcLen = 0
 Length in bytes of the valid address data in src.

Detailed Description

Telemetry data about a single UDP datagram receive operation.

The DatagramReadResult structure encapsulates comprehensive details about the result of a UDP datagram receive operation, including payload size, truncation status, and sender information. It enables monitoring and control of datagram handling behavior.

Key features:

  • Tracks actual bytes received and copied to the destination buffer
  • Reports full size of the original datagram when available via preflight
  • Indicates truncation status for datagrams exceeding buffer capacity
  • Captures raw sender address information for unconnected sockets in a platform-independent format

Use Cases:

  • Monitoring datagram sizes and truncation
  • Tracking sender information without DNS resolution
  • Implementing custom routing or filtering logic
  • Performance profiling and diagnostics
See also
DatagramSocket::read()
DatagramReceiveMode
DatagramReadOptions
Since
1.0

Member Data Documentation

◆ bytes

std::size_t jsocketpp::DatagramReadResult::bytes = 0

Number of bytes successfully copied into the destination buffer.

This field indicates how many bytes were actually stored in the caller's buffer during the receive operation. If the datagram was larger than the provided buffer capacity and truncation occurred, this value will be less than datagramSize.

Note
For zero-length datagrams, this will be 0 even though the receive was successful.

◆ datagramSize

std::size_t jsocketpp::DatagramReadResult::datagramSize = 0

Full size of the original datagram when it can be determined.

This field represents the complete size of the received datagram before any truncation, when it can be determined through:

Note
A value of 0 indicates the size could not be determined (no preflight or platform support).

◆ src

sockaddr_storage jsocketpp::DatagramReadResult::src {}

Raw storage for the sender's address information.

This field contains the platform-independent sockaddr_storage structure holding the complete address information of the datagram sender. This is only valid for:

  • Unconnected sockets accepting datagrams from any source
  • When srcLen > 0 indicates valid sender info was captured
Note
For connected sockets or when sender info isn't needed, this may be empty.

◆ srcLen

socklen_t jsocketpp::DatagramReadResult::srcLen = 0

Length in bytes of the valid address data in src.

This field indicates how many bytes in the src structure contain valid sender address information. A value of 0 means either:

  • The socket is in connected mode (sender info not captured)
  • The receive operation didn't capture sender details
  • No sender information was available

◆ truncated

bool jsocketpp::DatagramReadResult::truncated = false

Indicates whether datagram truncation occurred.

Set to true if the incoming datagram was larger than the provided destination buffer's capacity, causing the excess bytes to be discarded. This is a common occurrence in UDP when:

  • The sender's message exceeds the receiver's buffer size
  • Buffer sizing policy (DatagramReceiveMode) doesn't match actual datagram sizes
  • Platform MTU or fragmentation limits are exceeded

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