diff --git a/bittorrent/src/event_loop.rs b/bittorrent/src/event_loop.rs index a249d9c..f39ac6f 100644 --- a/bittorrent/src/event_loop.rs +++ b/bittorrent/src/event_loop.rs @@ -454,7 +454,6 @@ impl<'scope, 'state: 'scope> EventLoop { break Err(Error::Io(err)); } } - cq.sync(); if cq.overflow() > 0 { log::error!("CQ overflow"); } @@ -508,9 +507,10 @@ impl<'scope, 'state: 'scope> EventLoop { &mut state_ref, &mut event_tx, ); - io.sq.sync(); } - + // Update right before reading the events to ensure we + // get as many as possible + cq.sync(); for cqe in &mut cq { let io_event = RawIoEvent::from(cqe); if let Some(event) = io.events.get_mut(io_event.event_data_idx) { @@ -554,6 +554,8 @@ impl<'scope, 'state: 'scope> EventLoop { io.read_ring.return_bid(bid); } } + // Update the kernel about how many we've consumed + cq.sync(); if let Some(torrent_state) = state_ref.state() { torrent_state.handle_completed_pieces( diff --git a/bittorrent/src/io.rs b/bittorrent/src/io.rs index 71e8e81..01fe59a 100644 --- a/bittorrent/src/io.rs +++ b/bittorrent/src/io.rs @@ -230,8 +230,6 @@ impl Io { if self.sq.remaining() >= 2 { self.sq.push(read_op); self.sq.push(timeout_op); - // Need to sync so timeout isn't dropped prematurely? - self.sq.sync(); } else { self.sq.push_backlog(read_op); self.sq.push_backlog(timeout_op);