Skip to content

Commit

Permalink
Introduce UdpSocketState:try_send API for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Oct 21, 2024
1 parent 5b5f391 commit f547d5e
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions quinn-udp/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,25 @@ impl UdpSocketState {
}

pub fn send(&self, socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> io::Result<()> {
let rc = send(socket, transmit);
match send(socket, transmit) {
Ok(()) => Ok(()),
Err(e) if e.kind() == io::ErrorKind::WouldBlock => Err(e),
Err(e) => {
// Other errors are ignored, since they will usually be handled
// by higher level retransmits and timeouts.
// - PermissionDenied errors have been observed due to iptable rules.
// Those are not fatal errors, since the
// configuration can be dynamically changed.
// - Destination unreachable errors have been observed for other
log_sendmsg_error(&self.last_send_error, e, transmit);

if rc != 0 {
let e = io::Error::last_os_error();
if e.kind() == io::ErrorKind::WouldBlock {
return Err(e);
Ok(())
}

// Other errors are ignored, since they will usually be handled
// by higher level retransmits and timeouts.
// - PermissionDenied errors have been observed due to iptable rules.
// Those are not fatal errors, since the
// configuration can be dynamically changed.
// - Destination unreachable errors have been observed for other
log_sendmsg_error(&self.last_send_error, e, transmit);
}
Ok(())
}

pub fn try_send(&self, socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> io::Result<()> {
send(socket, transmit)
}

pub fn recv(
Expand Down Expand Up @@ -272,7 +274,7 @@ impl UdpSocketState {
}
}

fn send(socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> i32 {
fn send(socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> io::Result<()> {
// we cannot use [`socket2::sendmsg()`] and [`socket2::MsgHdr`] as we do not have access
// to the inner field which holds the WSAMSG
let mut ctrl_buf = cmsg::Aligned([0; CMSG_LEN]);
Expand Down Expand Up @@ -349,7 +351,7 @@ fn send(socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> i32 {
encoder.finish();

let mut len = 0;
unsafe {
let rc = unsafe {
WinSock::WSASendMsg(
socket.0.as_raw_socket() as usize,
&wsa_msg,
Expand All @@ -358,7 +360,13 @@ fn send(socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> i32 {
ptr::null_mut(),
None,
)
};

if rc != 0 {
return Err(io::Error::last_os_error());
}

Ok(())
}

fn set_socket_option(
Expand Down

0 comments on commit f547d5e

Please sign in to comment.