Skip to content

Commit

Permalink
starting the work on Zerocopy receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
frochet committed Apr 27, 2024
1 parent 6dfbdd2 commit e03ff8a
Show file tree
Hide file tree
Showing 31 changed files with 10,378 additions and 2,410 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ debug = true

[profile.release]
debug = true

[profile.performance]
inherits = "release"
lto = "fat"
codegen-units = 1
incremental = false

5 changes: 3 additions & 2 deletions apps/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ impl Args for CommonArgs {
let (alpns, dgrams_enabled) = match (http_version, dgram_proto) {
("HTTP/0.9", "none") => (alpns::HTTP_09.to_vec(), false),

("HTTP/0.9", _) =>
panic!("Unsupported HTTP version and DATAGRAM protocol."),
("HTTP/0.9", _) => {
panic!("Unsupported HTTP version and DATAGRAM protocol.")
},

("HTTP/3", "none") => (alpns::HTTP_3.to_vec(), false),

Expand Down
38 changes: 35 additions & 3 deletions apps/src/bin/quiche-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use quiche_apps::common::*;
use quiche_apps::sendto::*;

const MAX_BUF_SIZE: usize = 65507;
const MAX_FLUSH_SIZE: usize = 256_000;

const MAX_DATAGRAM_SIZE: usize = 1350;

Expand Down Expand Up @@ -377,7 +378,7 @@ fn main() {

let client_id = next_client_id;

let client = Client {
let mut client = Client {
conn,
http_conn: None,
client_id,
Expand All @@ -387,8 +388,19 @@ fn main() {
max_datagram_size,
loss_rate: 0.0,
max_send_burst: MAX_BUF_SIZE,
app_buffers: quiche::AppRecvBufMap::new(
3,
conn_args.max_stream_window,
conn_args.max_streams_bidi,
conn_args.max_streams_uni,
),
};

client
.app_buffers
.set_expected_chunklen_to_consume(MAX_FLUSH_SIZE as u64)
.unwrap();

clients.insert(client_id, client);
clients_ids.insert(scid.clone(), client_id);

Expand All @@ -411,7 +423,11 @@ fn main() {
};

// Process potentially coalesced packets.
let read = match client.conn.recv(pkt_buf, recv_info) {
let read = match client.conn.recv(
pkt_buf,
&mut client.app_buffers,
recv_info,
) {
Ok(v) => v,

Err(e) => {
Expand Down Expand Up @@ -487,14 +503,30 @@ fn main() {
http_conn.handle_writable(conn, partial_responses, stream_id);
}

if http_conn
if conn.version() == quiche::PROTOCOL_VERSION_V3 {
if http_conn
.handle_requests(
conn,
&mut client.partial_requests,
partial_responses,
&args.root,
&args.index,
&mut buf,
Some(&mut client.app_buffers),
)
.is_err()
{
continue 'read;
}
} else if http_conn
.handle_requests(
conn,
&mut client.partial_requests,
partial_responses,
&args.root,
&args.index,
&mut buf,
None,
)
.is_err()
{
Expand Down
38 changes: 30 additions & 8 deletions apps/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use crate::args::*;
use crate::common::*;
use quiche::AppRecvBufMap;

use std::net::ToSocketAddrs;

Expand All @@ -38,6 +39,7 @@ use std::cell::RefCell;
use ring::rand::*;

const MAX_DATAGRAM_SIZE: usize = 1350;
pub const MAX_FLUSH_SIZE: usize = 256_000;

#[derive(Debug)]
pub enum ClientError {
Expand Down Expand Up @@ -178,6 +180,16 @@ pub fn connect(

let local_addr = socket.local_addr().unwrap();

let mut app_buffers = AppRecvBufMap::new(
3,
conn_args.max_stream_window,
conn_args.max_streams_bidi,
conn_args.max_streams_uni,
);
app_buffers
.set_expected_chunklen_to_consume(MAX_FLUSH_SIZE as u64)
.unwrap();

// Create a QUIC connection and initiate handshake.
let mut conn = quiche::connect(
connect_url.domain(),
Expand Down Expand Up @@ -310,14 +322,16 @@ pub fn connect(
};

// Process potentially coalesced packets.
let read = match conn.recv(&mut buf[..len], recv_info) {
Ok(v) => v,
let read =
match conn.recv(&mut buf[..len], &mut app_buffers, recv_info)
{
Ok(v) => v,

Err(e) => {
error!("{}: recv failed: {:?}", local_addr, e);
continue 'read;
},
};
Err(e) => {
error!("{}: recv failed: {:?}", local_addr, e);
continue 'read;
},
};

trace!("{}: processed {} bytes", local_addr, read);
}
Expand Down Expand Up @@ -415,7 +429,15 @@ pub fn connect(
// process received data.
if let Some(h_conn) = http_conn.as_mut() {
h_conn.send_requests(&mut conn, &args.dump_response_path);
h_conn.handle_responses(&mut conn, &mut buf, &app_data_start);
if conn.version() == quiche::PROTOCOL_VERSION_V3 {
h_conn.handle_responses_on_quic_v3(
&mut conn,
&mut app_buffers,
&app_data_start,
);
} else {
h_conn.handle_responses(&mut conn, &mut buf, &app_data_start);
}
}

// Handle path events.
Expand Down
Loading

0 comments on commit e03ff8a

Please sign in to comment.