Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ lite-07; bitrate enforcement is not part of this release.
- [Certificate reload and qmux's tasks are supervised](/quest/m2/tls-reload-supervision.md) - a panic in either fails loudly instead of silently stopping
- [PUBLISH_DONE says why](/quest/m2/publish-done-codes.md) - GOING_AWAY, TOO_FAR_BEHIND, and EXPIRED round-trip as stream codes
- [moq repair refuses a live recording](/quest/m2/mp4-repair-lock.md) - the recorder's advisory lock keeps `moq repair mp4` off a file still being written
- [Windows receives notice truncated control data](/quest/m2/cmsg-windows-truncation.md) - Windows handles `MSG_CTRUNC` like the Unix paths
- [The error-queue reader decodes truncated control data](/quest/m2/errqueue-truncation.md) - `MSG_ERRQUEUE` keeps what fit on `MSG_CTRUNC`, like the receive paths
- [moq-quic's internal dev-dependencies are path-only](/quest/m2/quic-dev-dep-path.md) - moq-congestion is a path dev-dependency
- [moq-mux's AAC config reports SBR](/quest/m2/aac-sbr-config.md) - moq-audio reads backward-compatible SBR from the config
Expand Down
13 changes: 0 additions & 13 deletions quest/m2/cmsg-windows-truncation.md

This file was deleted.

34 changes: 27 additions & 7 deletions rs/moq-sock/src/udp/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use std::{
net::{IpAddr, Ipv4Addr},
os::windows::io::AsRawSocket,
ptr,
sync::atomic::{AtomicUsize, Ordering},
sync::{
Once,
atomic::{AtomicUsize, Ordering},
},
};

use libc::{c_int, c_uint};
Expand All @@ -13,7 +16,7 @@ use windows_sys::Win32::Networking::WinSock;
use crate::udp::{
EcnCodepoint, RecvMeta, Transmit, UdpSockRef,
cmsg::{self, CMsgHdr},
log::debug,
log::{debug, warn},
};

/// QUIC-friendly UDP socket for Windows
Expand Down Expand Up @@ -181,16 +184,24 @@ impl UdpSocketState {
};

let mut len = 0;
unsafe {
let rc = (self.wsa_recvmsg)(
let rc = unsafe {
(self.wsa_recvmsg)(
socket.0.as_raw_socket() as usize,
&mut wsa_msg,
&mut len,
ptr::null_mut(),
None,
);
if rc == -1 {
return Err(io::Error::last_os_error());
)
};
if rc == -1 {
let err = io::Error::last_os_error();
// Winsock fails the call with `WSAEMSGSIZE` when either the payload or the control data
// was truncated, and sets `MSG_TRUNC` / `MSG_CTRUNC` to say which. Only truncated
// control data is recoverable: the whole datagram arrived, so keep it below.
// https://learn.microsoft.com/en-us/windows/win32/api/ws2def/ns-ws2def-wsamsg#remarks
let truncated = wsa_msg.dwFlags & (WinSock::MSG_TRUNC | WinSock::MSG_CTRUNC);
if err.raw_os_error() != Some(WinSock::WSAEMSGSIZE) || truncated != WinSock::MSG_CTRUNC {
return Err(err);
}
}

Expand All @@ -203,6 +214,15 @@ impl UdpSocketState {
addr.as_socket()
};

// `MSG_CTRUNC` keeps the datagram with the metadata that fit: losing metadata beats losing
// the packet. The iterator below stays within the `Control.len` Winsock returned.
if wsa_msg.dwFlags & WinSock::MSG_CTRUNC != 0 {
static CTRUNC: Once = Once::new();
CTRUNC.call_once(|| {
warn!("control messages truncated to {CMSG_LEN} bytes; some receive metadata is lost");
});
}

// Decode control messages (PKTINFO and ECN)
let mut ecn_bits = 0;
let mut dst_ip = None;
Expand Down
Loading