Skip to content

Commit cfe37fa

Browse files
committed
Clean up race condition fix
1 parent 9303e4d commit cfe37fa

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ use openssl::crypto::hash::{HashType, Hasher};
7272
use openssl::ssl::{SslContext, MaybeSslStream};
7373
use serialize::hex::ToHex;
7474
use std::cell::{Cell, RefCell};
75+
use std::cmp::max;
7576
use std::collections::{RingBuf, HashMap};
76-
use std::io::{BufferedStream, IoResult, IoError, IoErrorKind, standard_error};
77+
use std::io::{BufferedStream, IoResult, IoError, IoErrorKind};
7778
use std::io::net::ip::Port;
7879
use std::iter::IteratorCloneExt;
7980
use std::time::Duration;
@@ -279,10 +280,8 @@ impl<'conn> Notifications<'conn> {
279280
let end = time::now().to_timespec() + timeout;
280281
loop {
281282
let now = time::now().to_timespec();
282-
if now > end {
283-
return Err(Error::IoError(standard_error(IoErrorKind::TimedOut)));
284-
}
285-
conn.stream.set_read_timeout(Some((end - now).num_milliseconds() as u64));
283+
let timeout = max(0, (end - now).num_milliseconds()) as u64;
284+
conn.stream.set_read_timeout(Some(timeout));
286285
match conn.read_one_message() {
287286
Ok(Some(NotificationResponse { pid, channel, payload })) => {
288287
return Ok(Notification {

0 commit comments

Comments
 (0)