Skip to content

Commit 59aad9e

Browse files
committed
wip: cleaned up example
* Related #20 [ci skip]
1 parent 63fcc19 commit 59aad9e

File tree

2 files changed

+32
-41
lines changed

2 files changed

+32
-41
lines changed

src/bin/clientTest.rs renamed to src/bin/client_test.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ use ring::rand::*;
3333

3434
const MAX_DATAGRAM_SIZE: usize = 1350;
3535

36-
const HTTP_REQ_STREAM_ID: u64 = 4;
37-
3836
struct TestData {
3937
num_messages: i64,
4038
}
4139

4240
const STREAMS: u64 = 10000;
4341
const MESSAGES: i64 = 400;
4442

43+
4544
fn main() {
4645
let mut buf = [0; 65535];
4746
let mut out = [0; MAX_DATAGRAM_SIZE];
@@ -141,7 +140,7 @@ fn main() {
141140

142141
debug!("written {}", write);
143142

144-
let req_start = std::time::Instant::now();
143+
// let req_start = std::time::Instant::now();
145144

146145
let mut req_sent = false;
147146

@@ -188,7 +187,7 @@ fn main() {
188187
Ok(v) => v,
189188

190189
Err(e) => {
191-
error!("recv failed: {:?}", e);
190+
println!("recv failed: {:?}", e);
192191
continue 'read;
193192
},
194193
};
@@ -231,21 +230,22 @@ fn main() {
231230

232231
// Process all readable streams.
233232
for s in conn.readable() {
234-
while let Ok((read, fin)) = conn.stream_recv(s, &mut buf) {
235-
// println!("received {} bytes", read);
233+
while let Ok((_read, _fin)) = conn.stream_recv(s, &mut buf) {
234+
// ignore messages, just consume.
235+
// println!("received {} bytes", read);
236236

237-
let stream_buf = &buf[..read];
237+
// let stream_buf = &buf[..read];
238238

239-
// println!(
240-
// "stream {} has {} bytes (fin? {})",
241-
// s,
242-
// stream_buf.len(),
243-
// fin
244-
// );
239+
// println!(
240+
// "stream {} has {} bytes (fin? {})",
241+
// s,
242+
// stream_buf.len(),
243+
// fin
244+
// );
245245

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

250250
}
251251
}
@@ -263,17 +263,17 @@ fn main() {
263263
app_data.num_messages = app_data.num_messages - 1;
264264

265265
let fin = app_data.num_messages <= 1;
266-
if (fin) {
266+
if fin {
267267
println!{"finishing {}", s};
268268
}
269-
if (app_data.num_messages > 0) {
270-
let written = match conn.stream_send(s, b"Hello!", fin) {
269+
if app_data.num_messages > 0 {
270+
let _written = match conn.stream_send(s, b"Hello!", fin) {
271271
Ok(v) => v,
272272

273273
Err(quiche::Error::Done) => 0,
274274

275275
Err(e) => {
276-
error!("{} stream send failed {:?}", conn.trace_id(), e);
276+
println!("{} stream send failed {:?}", conn.trace_id(), e);
277277
return;
278278
},
279279
};
@@ -292,7 +292,7 @@ fn main() {
292292
},
293293

294294
Err(e) => {
295-
error!("send failed: {:?}", e);
295+
println!("send failed: {:?}", e);
296296

297297
conn.close(false, 0x1, b"fail").ok();
298298
break;
@@ -312,7 +312,7 @@ fn main() {
312312
}
313313

314314
if conn.is_closed() {
315-
info!("connection closed, {:?}", conn.stats());
315+
println!("connection closed, {:?}", conn.stats());
316316
break;
317317
}
318318
}

src/bin/serverTest.rs renamed to src/bin/server_test.rs

+10-19
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,8 @@ use ring::rand::*;
3636

3737
const MAX_DATAGRAM_SIZE: usize = 1350;
3838

39-
struct PartialResponse {
40-
body: Vec<u8>,
41-
42-
written: usize,
43-
}
44-
4539
struct Client {
4640
conn: quiche::Connection,
47-
48-
partial_responses: HashMap<u64, PartialResponse>,
4941
}
5042

5143
type ClientMap = HashMap<quiche::ConnectionId<'static>, Client>;
@@ -165,7 +157,7 @@ fn main() {
165157
Ok(v) => v,
166158

167159
Err(e) => {
168-
error!("Parsing packet header failed: {:?}", e);
160+
println!("Parsing packet header failed: {:?}", e);
169161
continue 'read;
170162
},
171163
};
@@ -182,7 +174,7 @@ fn main() {
182174
!clients.contains_key(&conn_id)
183175
{
184176
if hdr.ty != quiche::Type::Initial {
185-
error!("Packet is not Initial");
177+
println!("Packet is not Initial");
186178
continue 'read;
187179
}
188180

@@ -248,12 +240,12 @@ fn main() {
248240
// The token was not valid, meaning the retry failed, so
249241
// drop the packet.
250242
if odcid.is_none() {
251-
error!("Invalid address validation token");
243+
println!("Invalid address validation token");
252244
continue 'read;
253245
}
254246

255247
if scid.len() != hdr.dcid.len() {
256-
error!("Invalid destination connection ID");
248+
println!("Invalid destination connection ID");
257249
continue 'read;
258250
}
259251

@@ -274,7 +266,6 @@ fn main() {
274266

275267
let client = Client {
276268
conn,
277-
partial_responses: HashMap::new(),
278269
};
279270

280271
clients.insert(scid.clone(), client);
@@ -298,7 +289,7 @@ fn main() {
298289
Ok(v) => v,
299290

300291
Err(e) => {
301-
error!("{} recv failed: {:?}", client.conn.trace_id(), e);
292+
println!("{} recv failed: {:?}", client.conn.trace_id(), e);
302293
continue 'read;
303294
},
304295
};
@@ -315,12 +306,12 @@ fn main() {
315306
for s in client.conn.readable() {
316307
active_count.insert(s);
317308
// println!("reading stream {}", s);
318-
while let Ok((read, fin)) =
309+
while let Ok((_read, fin)) =
319310
client.conn.stream_recv(s, &mut buf)
320311
{
321-
let stream_buf = &buf[..read];
312+
// let stream_buf = &buf[..read];
322313

323-
if (fin) {
314+
if fin {
324315
active_count.remove(&s);
325316
println!("stream finished! {}, left {}", s, active_count.len());
326317
}
@@ -343,7 +334,7 @@ fn main() {
343334
},
344335

345336
Err(e) => {
346-
error!("{} send failed: {:?}", client.conn.trace_id(), e);
337+
println!("{} send failed: {:?}", client.conn.trace_id(), e);
347338

348339
client.conn.close(false, 0x1, b"fail").ok();
349340
break;
@@ -446,7 +437,7 @@ fn handle_writable(client: &mut Client, stream_id: u64) {
446437
Err(quiche::Error::Done) => (),
447438

448439
Err(e) => {
449-
error!("{} stream send failed {:?}", conn.trace_id(), e);
440+
println!("{} stream send failed {:?}", conn.trace_id(), e);
450441

451442
},
452443
}

0 commit comments

Comments
 (0)