Skip to content

Commit

Permalink
fix access to extern crates through prelude is experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhoLiu committed Aug 3, 2018
1 parent a973f7a commit 4ebfb53
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,40 +118,52 @@ impl ProxyStream {
}

impl Read for ProxyStream {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let r = (&mut (&*self.0)).read(buf);

if cfg!(any(
#[cfg(
any(
target_os = "bitrig",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
)) {
match r {
Ok(n) => Ok(n),
Err(e) => {
// FIXME: https://github.com/tokio-rs/tokio/issues/449
// maybe tokio bug, maybe my bug...
if e.kind() == io::ErrorKind::WouldBlock {
if let Async::Ready(ready) =
self.0.poll_read_ready(mio::Ready::readable())?
{
if mio::unix::UnixReady::from(ready).is_hup() {
warn!("kqueue get EV_EOF, but read get WouldBlock, maybe a bug");
return Ok(0);
}
)
)]
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
match (&mut (&*self.0)).read(buf) {
Ok(n) => return Ok(n),
Err(e) => {
// FIXME: https://github.com/tokio-rs/tokio/issues/449
// maybe tokio bug, maybe my bug...
if e.kind() == io::ErrorKind::WouldBlock {
if let Async::Ready(ready) = self.0.poll_read_ready(mio::Ready::readable())? {
if mio::unix::UnixReady::from(ready).is_hup() {
warn!("kqueue get EV_EOF, but read get WouldBlock, maybe a bug");
return Ok(0);
}
}
Err(e)
}
return Err(e);
}
} else {
r
}
}

#[cfg(
not(
any(
target_os = "bitrig",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
)
)
)]
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
(&mut (&*self.0)).read(buf)
}
}

impl Write for ProxyStream {
Expand Down

0 comments on commit 4ebfb53

Please sign in to comment.