Skip to content

Commit

Permalink
tquic_tools: fix processing timeout events (Tencent#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaofei0800 authored May 15, 2024
1 parent f6c11ac commit 7cf54a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
20 changes: 6 additions & 14 deletions tools/src/bin/tquic_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use std::cell::RefCell;
use std::cell::RefMut;
use std::cmp;
use std::cmp::max;
use std::fs::create_dir_all;
use std::fs::File;
Expand Down Expand Up @@ -66,7 +65,6 @@ use tquic::MultipathAlgorithm;
use tquic::PacketInfo;
use tquic::TlsConfig;
use tquic::TransportHandler;
use tquic::TIMER_GRANULARITY;
use tquic_tools::ApplicationProto;
use tquic_tools::QuicSocket;
use tquic_tools::Result;
Expand Down Expand Up @@ -611,25 +609,19 @@ impl Worker {
break;
}

let timeout = self
.endpoint
.timeout()
.map(|v| cmp::max(v, TIMER_GRANULARITY));

self.poll.poll(&mut events, timeout)?;

// Process timeout events
if events.is_empty() {
self.endpoint.on_timeout(Instant::now());
continue;
}
self.poll.poll(&mut events, self.endpoint.timeout())?;

// Process IO events
for event in events.iter() {
if event.is_readable() {
self.process_read_event(event)?;
}
}

// Process timeout events.
// Note: Since `poll()` doesn't clearly tell if there was a timeout when it returns,
// it is up to the endpoint to check for a timeout and deal with it.
self.endpoint.on_timeout(Instant::now());
}

self.finish();
Expand Down
18 changes: 6 additions & 12 deletions tools/src/bin/tquic_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

//! An QUIC server based on the high level endpoint API.
use std::cmp;
use std::collections::HashMap;
use std::fs::create_dir_all;
use std::fs::File;
Expand Down Expand Up @@ -43,7 +42,6 @@ use tquic::MultipathAlgorithm;
use tquic::PacketInfo;
use tquic::TlsConfig;
use tquic::TransportHandler;
use tquic::TIMER_GRANULARITY;
use tquic_tools::ApplicationProto;
use tquic_tools::QuicSocket;
use tquic_tools::Result;
Expand Down Expand Up @@ -891,28 +889,24 @@ fn main() -> Result<()> {
error!("process connections error: {:?}", e);
}

let timeout = server
.endpoint
.timeout()
.map(|v| cmp::max(v, TIMER_GRANULARITY));
let timeout = server.endpoint.timeout();
debug!(
"{} wait for io events, timeout: {:?}",
server.endpoint.trace_id(),
timeout
);
server.poll.poll(&mut events, timeout)?;

// Process timeout events
if events.is_empty() {
server.endpoint.on_timeout(Instant::now());
continue;
}

// Process IO events
for event in events.iter() {
if event.is_readable() {
server.process_read_event(event)?;
}
}

// Process timeout events.
// Note: Since `poll()` doesn't clearly tell if there was a timeout when it returns,
// it is up to the endpoint to check for a timeout and deal with it.
server.endpoint.on_timeout(Instant::now());
}
}

0 comments on commit 7cf54a5

Please sign in to comment.