Skip to content

Commit

Permalink
Extract send free function for fallback implementation
Browse files Browse the repository at this point in the history
This allows us to have it follow the exact same implementation as the
unix and windows one.
  • Loading branch information
thomaseizinger committed Oct 21, 2024
1 parent e617ab9 commit e515a27
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions quinn-udp/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,25 @@ impl UdpSocketState {
}

pub fn send(&self, socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> io::Result<()> {
let Err(e) = socket.0.send_to(
transmit.contents,
&socket2::SockAddr::from(transmit.destination),
) else {
return Ok(());
};
if e.kind() == io::ErrorKind::WouldBlock {
return Err(e);
}
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);

// 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(())
Ok(())
}
}
}

pub fn try_send(&self, socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> io::Result<()> {
socket.0.send_to(
transmit.contents,
&socket2::SockAddr::from(transmit.destination),
)
send(socket, transmit)
}

pub fn recv(
Expand Down Expand Up @@ -92,4 +86,11 @@ impl UdpSocketState {
}
}

fn send(socket: UdpSockRef<'_>, transmit: &Transmit<'_>) -> io::Result<()> {
socket.0.send_to(
transmit.contents,
&socket2::SockAddr::from(transmit.destination),
)
}

pub(crate) const BATCH_SIZE: usize = 1;

0 comments on commit e515a27

Please sign in to comment.