Skip to content

Commit 46ee86f

Browse files
committed
wip: function example of the problem
* Related #20 [ci skip]
1 parent c916e3d commit 46ee86f

File tree

2 files changed

+53
-39
lines changed

2 files changed

+53
-39
lines changed

src/bin/clientTest.rs

+37-17
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ const MAX_DATAGRAM_SIZE: usize = 1350;
3636
const HTTP_REQ_STREAM_ID: u64 = 4;
3737

3838
struct TestData {
39-
num_messages: u8,
39+
num_messages: i64,
4040
}
4141

42+
const STREAMS: u64 = 10000;
43+
const MESSAGES: i64 = 400;
44+
4245
fn main() {
4346
let mut buf = [0; 65535];
4447
let mut out = [0; MAX_DATAGRAM_SIZE];
@@ -204,50 +207,67 @@ fn main() {
204207
if conn.is_established() && !req_sent {
205208
println!("Init data");
206209
// init application data
207-
match conn.stream_send(0, b"", false) {
210+
for n in 0..STREAMS {
211+
let stream_id = n * 4;
212+
match conn.stream_send(stream_id, b"", false) {
208213
Ok(_) => {},
209214
Err(quiche::Error::Done) => {},
210215
Err(e) => {
211216
error!("{} stream send failed {:?}", conn.trace_id(), e);
212217
return;
213218
},
214219
};
215-
match conn.stream_init_application_data(0, TestData {num_messages: 0}) {
220+
match conn.stream_init_application_data(stream_id, TestData {num_messages: MESSAGES}) {
216221
Ok(_) => {},
217222
Err(quiche::Error::Done) => {},
218223
Err(e) => {
219224
error!("{} stream init failed {:?}", conn.trace_id(), e);
220225
return;
221226
},
222227
};
223-
228+
}
224229
req_sent = true;
225230
}
226231

227232
// Process all readable streams.
228233
for s in conn.readable() {
229234
while let Ok((read, fin)) = conn.stream_recv(s, &mut buf) {
230-
println!("received {} bytes", read);
235+
// println!("received {} bytes", read);
231236

232237
let stream_buf = &buf[..read];
233238

234-
println!(
235-
"stream {} has {} bytes (fin? {})",
236-
s,
237-
stream_buf.len(),
238-
fin
239-
);
239+
// println!(
240+
// "stream {} has {} bytes (fin? {})",
241+
// s,
242+
// stream_buf.len(),
243+
// fin
244+
// );
240245

241-
println!("{}", unsafe {
242-
std::str::from_utf8_unchecked(stream_buf)
243-
});
246+
// println!("{}", unsafe {
247+
// std::str::from_utf8_unchecked(stream_buf)
248+
// });
244249

245250
}
246251
}
247252

248253
for s in conn.writable() {
249-
println!("Writing stream {}", s);
250-
let written = match conn.stream_send(s, b"Hello!", true) {
254+
// println!("Writing stream {}", s);
255+
// get the application data
256+
let app_data = conn.stream_application_data(s)
257+
.unwrap()
258+
.downcast_mut::<TestData>()
259+
.unwrap();
260+
261+
// println!("numruns {}", app_data.num_messages);
262+
// dec the number of messages
263+
app_data.num_messages = app_data.num_messages - 1;
264+
265+
let fin = app_data.num_messages <= 1;
266+
if (fin) {
267+
println!{"finishing {}", s};
268+
}
269+
if (app_data.num_messages > 0) {
270+
let written = match conn.stream_send(s, b"Hello!", fin) {
251271
Ok(v) => v,
252272

253273
Err(quiche::Error::Done) => 0,
@@ -257,7 +277,7 @@ fn main() {
257277
return;
258278
},
259279
};
260-
println!("Written {} bytes", written);
280+
}
261281
}
262282

263283
// Generate outgoing QUIC packets and send them on the UDP socket, until

src/bin/serverTest.rs

+16-22
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern crate log;
3030
use std::net;
3131

3232
use std::collections::HashMap;
33+
use std::collections::BTreeSet;
3334

3435
use ring::rand::*;
3536

@@ -52,6 +53,7 @@ type ClientMap = HashMap<quiche::ConnectionId<'static>, Client>;
5253
fn main() {
5354
let mut buf = [0; 65535];
5455
let mut out = [0; MAX_DATAGRAM_SIZE];
56+
let mut active_count: BTreeSet<u64> = BTreeSet::new();
5557

5658
let mut args = std::env::args();
5759

@@ -101,8 +103,8 @@ fn main() {
101103
config.set_initial_max_stream_data_bidi_local(1_000_000);
102104
config.set_initial_max_stream_data_bidi_remote(1_000_000);
103105
config.set_initial_max_stream_data_uni(1_000_000);
104-
config.set_initial_max_streams_bidi(100);
105-
config.set_initial_max_streams_uni(100);
106+
config.set_initial_max_streams_bidi(10000);
107+
config.set_initial_max_streams_uni(10000);
106108
config.set_disable_active_migration(true);
107109
config.enable_early_data();
108110

@@ -311,26 +313,18 @@ fn main() {
311313

312314
// Process all readable streams.
313315
for s in client.conn.readable() {
314-
println!("reading stream {}", s);
315-
while let Ok((read, fin)) =
316-
client.conn.stream_recv(s, &mut buf)
317-
{
318-
println!(
319-
"{} received {} bytes",
320-
client.conn.trace_id(),
321-
read
322-
);
323-
324-
let stream_buf = &buf[..read];
325-
326-
debug!(
327-
"{} stream {} has {} bytes (fin? {})",
328-
client.conn.trace_id(),
329-
s,
330-
stream_buf.len(),
331-
fin
332-
);
333-
}
316+
active_count.insert(s);
317+
// println!("reading stream {}", s);
318+
while let Ok((read, fin)) =
319+
client.conn.stream_recv(s, &mut buf)
320+
{
321+
let stream_buf = &buf[..read];
322+
323+
if (fin) {
324+
active_count.remove(&s);
325+
println!("stream finished! {}, left {}", s, active_count.len());
326+
}
327+
}
334328
}
335329
}
336330
}

0 commit comments

Comments
 (0)