Skip to content

Commit

Permalink
re-introduce find_socket
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Oct 28, 2024
1 parent d23aa74 commit 786c616
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions neqo-bin/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,7 @@ impl ServerRunner {
// Have server process in- and output datagrams.
match self.server.process(input_dgram, (self.now)()) {
Output::Datagram(dgram) => {
let ((_host, first_socket), rest) = self.sockets.split_first_mut().unwrap();
let socket = rest
.iter_mut()
.map(|(_host, socket)| socket)
.find(|socket| {
socket
.local_addr()
.ok()
.map_or(false, |socket_addr| socket_addr == dgram.source())
})
.unwrap_or(first_socket);
let socket = find_socket(&mut self.sockets, dgram.source());
socket.writable().await?;
socket.send(&dgram)?;
continue;
Expand Down Expand Up @@ -323,6 +313,23 @@ enum Ready {
Timeout,
}

/// Tries to find a socket, but then just falls back to sending from the first.
fn find_socket(
sockets: &mut [(SocketAddr, crate::udp::Socket)],
addr: SocketAddr,
) -> &mut crate::udp::Socket {
let ((_host, first_socket), rest) = sockets.split_first_mut().unwrap();
rest.iter_mut()
.map(|(_host, socket)| socket)
.find(|socket| {
socket
.local_addr()
.ok()
.map_or(false, |socket_addr| socket_addr == addr)
})
.unwrap_or(first_socket)
}

pub async fn server(mut args: Args) -> Res<()> {
const HQ_INTEROP: &str = "hq-interop";

Expand Down

0 comments on commit 786c616

Please sign in to comment.