Skip to content

Commit

Permalink
Fix processing timeout events (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaofei0800 authored May 15, 2024
1 parent e356821 commit be7b2f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
16 changes: 6 additions & 10 deletions src/bin/simple_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

use std::cell::RefCell;
use std::cmp;
use std::net::SocketAddr;
use std::rc::Rc;
use std::time::Instant;
Expand All @@ -30,7 +29,6 @@ use tquic::Error;
use tquic::PacketInfo;
use tquic::TlsConfig;
use tquic::TransportHandler;
use tquic::TIMER_GRANULARITY;

use tquic_example_rust::QuicSocket;
use tquic_example_rust::Result;
Expand Down Expand Up @@ -324,21 +322,19 @@ fn main() -> Result<()> {
break;
}

let timeout = cmp::min(client.endpoint.timeout(), Some(TIMER_GRANULARITY));
client.poll.poll(&mut events, timeout)?;

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

// Process IO events
for event in events.iter() {
if event.is_readable() {
client.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.
client.endpoint.on_timeout(Instant::now());
}
Ok(())
}
19 changes: 6 additions & 13 deletions src/bin/simple_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::cmp;
use std::fs::File;
use std::net::SocketAddr;
use std::rc::Rc;
Expand All @@ -30,7 +29,6 @@ use tquic::Error;
use tquic::PacketInfo;
use tquic::TlsConfig;
use tquic::TransportHandler;
use tquic::TIMER_GRANULARITY;

use tquic_example_rust::QuicSocket;
use tquic_example_rust::Result;
Expand Down Expand Up @@ -277,23 +275,18 @@ fn main() -> Result<()> {
error!("process connections error: {:?}", e);
}

let timeout = server
.endpoint
.timeout()
.map(|v| cmp::max(v, TIMER_GRANULARITY));
server.poll.poll(&mut events, timeout)?;

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

// 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 be7b2f7

Please sign in to comment.