From e7d76a1f8e5c1b1e1aa978b54fa428c6496de920 Mon Sep 17 00:00:00 2001 From: Kershaw Chang Date: Fri, 22 Dec 2023 20:05:02 +0800 Subject: [PATCH] allow to pass Vec to neqo --- neqo-client/src/main.rs | 6 ++++-- neqo-http3/src/connection_client.rs | 6 ++++++ neqo-transport/src/connection/mod.rs | 13 +++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/neqo-client/src/main.rs b/neqo-client/src/main.rs index e7af2a3779..fa46069513 100644 --- a/neqo-client/src/main.rs +++ b/neqo-client/src/main.rs @@ -411,6 +411,7 @@ fn process_loop( )?; 'read: loop { + let mut datagrams: Vec = Vec::new(); match socket.recv_from(&mut buf[..]) { Err(ref err) => { if err.kind() == ErrorKind::WouldBlock || err.kind() == ErrorKind::Interrupted { @@ -427,11 +428,12 @@ fn process_loop( } if sz > 0 { let d = Datagram::new(remote, *local_addr, &buf[..sz]); - client.process_input(d, Instant::now()); - handler.maybe_key_update(client)?; + datagrams.push(d); } } }; + client.process_multiple_input(datagrams, Instant::now()); + handler.maybe_key_update(client)?; } if let Http3State::Closed(..) = client.state() { diff --git a/neqo-http3/src/connection_client.rs b/neqo-http3/src/connection_client.rs index 51cd8e2935..b2b68977d5 100644 --- a/neqo-http3/src/connection_client.rs +++ b/neqo-http3/src/connection_client.rs @@ -828,6 +828,12 @@ impl Http3Client { self.process_http3(now); } + pub fn process_multiple_input(&mut self, dgrams: Vec, now: Instant) { + qtrace!([self], "Process multiple datagrams, len={}", dgrams.len()); + self.conn.process_multiple_input(dgrams, now); + self.process_http3(now); + } + /// This should not be used because it gives access to functionalities that may disrupt the /// proper functioning of the HTTP/3 session. /// Only used by `neqo-interop`. diff --git a/neqo-transport/src/connection/mod.rs b/neqo-transport/src/connection/mod.rs index abb7e590ad..5325eaa922 100644 --- a/neqo-transport/src/connection/mod.rs +++ b/neqo-transport/src/connection/mod.rs @@ -921,6 +921,13 @@ impl Connection { self.streams.cleanup_closed_streams(); } + /// Process new input datagrams on the connection. + pub fn process_multiple_input(&mut self, dgrams: Vec, now: Instant) { + self.multiple_input(dgrams, now, now); + self.process_saved(now); + self.streams.cleanup_closed_streams(); + } + /// Get the time that we next need to be called back, relative to `now`. fn next_delay(&mut self, now: Instant, paced: bool) -> Duration { qtrace!([self], "Get callback delay {:?}", now); @@ -1369,6 +1376,12 @@ impl Connection { self.capture_error(Some(path), now, 0, res).ok(); } + fn multiple_input(&mut self, datagrams: Vec, received: Instant, now: Instant) { + for d in datagrams { + self.input(d, received, now); + } + } + fn input_path(&mut self, path: &PathRef, d: Datagram, now: Instant) -> Res<()> { let mut slc = &d[..]; let mut dcid = None;