From cdd26e764b4da9be491371acdb6f6d1a890e2214 Mon Sep 17 00:00:00 2001 From: Ricardo Martins Date: Mon, 22 Jun 2015 16:07:18 +0100 Subject: [PATCH] Set timeout only on non-`New` sockets. --- src/socket.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/socket.rs b/src/socket.rs index 514a070e6..f32a5c447 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -338,11 +338,11 @@ impl UtpSocket { fn recv(&mut self, buf: &mut[u8]) -> Result<(usize,SocketAddr)> { let mut b = [0; BUF_SIZE + HEADER_SIZE]; - // if self.state != SocketState::New { - // 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_timeout(&mut b, self.congestion_timeout as i64) { + let timeout = if self.state != SocketState::New { + debug!("setting read timeout of {} ms", self.congestion_timeout); + self.congestion_timeout as i64 + } else { 0 }; + let (read, src) = match self.socket.recv_timeout(&mut b, timeout) { Err(ref e) if (e.kind() == ErrorKind::WouldBlock || e.kind() == ErrorKind::TimedOut) => { debug!("recv_from timed out");