Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Commit

Permalink
Restore receive timeout sensitivity.
Browse files Browse the repository at this point in the history
  • Loading branch information
meqif committed Jun 22, 2015
1 parent 97ed76b commit bbdc85c
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,15 @@ impl UtpSocket {
// debug!("setting read timeout of {} ms", self.congestion_timeout);
// self.socket.set_read_timeout(Some(self.congestion_timeout));
// }
let (read, src) = match self.socket.recv_from(&mut b) {
// Err(ref e) if e.kind == TimedOut => {
// debug!("recv_from timed out");
// self.congestion_timeout = self.congestion_timeout * 2;
// self.cwnd = MSS;
// self.send_fast_resend_request();
// return Ok((0, self.connected_to));
// },
let (read, src) = match self.socket.recv_timeout(&mut b, self.congestion_timeout as i64) {
Err(ref e) if (e.kind() == ErrorKind::WouldBlock ||
e.kind() == ErrorKind::TimedOut) => {
debug!("recv_from timed out");
self.congestion_timeout = self.congestion_timeout * 2;
self.cwnd = MSS;
self.send_fast_resend_request();
return Ok((0, self.connected_to));
},
Ok(x) => x,
Err(e) => return Err(e),
};
Expand Down Expand Up @@ -633,6 +634,25 @@ impl UtpSocket {
return sack;
}

/// Sends a fast resend request to the remote peer.
///
/// A fast resend request consists of sending three STATE packets (acknowledging the last
/// received packet) in quick succession.
fn send_fast_resend_request(&self) {
for _ in 0..3 {
let mut packet = Packet::new();
packet.set_type(PacketType::State);
let self_t_micro: u32 = now_microseconds();
let other_t_micro: u32 = 0;
packet.set_timestamp_microseconds(self_t_micro);
packet.set_timestamp_difference_microseconds((self_t_micro - other_t_micro));
packet.set_connection_id(self.sender_connection_id);
packet.set_seq_nr(self.seq_nr);
packet.set_ack_nr(self.ack_nr);
let _ = self.socket.send_to(&packet.to_bytes()[..], self.connected_to);
}
}

fn resend_lost_packet(&mut self, lost_packet_nr: u16) {
debug!("---> resend_lost_packet({}) <---", lost_packet_nr);
match self.send_window.iter().position(|pkt| pkt.seq_nr() == lost_packet_nr) {
Expand Down

0 comments on commit bbdc85c

Please sign in to comment.