fix(net): ignore NotConnected error in NetworkStream.close
On OSX, calling shutdown a second time will return a NotConnected error. This commit will just ignore it, since we can agree that if a stream is "not connected", it is in fact "closed". Closes #508
This commit is contained in:
19
src/net.rs
19
src/net.rs
@@ -1,7 +1,7 @@
|
|||||||
//! A collection of traits abstracting over Listeners and Streams.
|
//! A collection of traits abstracting over Listeners and Streams.
|
||||||
use std::any::{Any, TypeId};
|
use std::any::{Any, TypeId};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, ErrorKind, Read, Write};
|
||||||
use std::net::{SocketAddr, ToSocketAddrs, TcpStream, TcpListener, Shutdown};
|
use std::net::{SocketAddr, ToSocketAddrs, TcpStream, TcpListener, Shutdown};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@@ -292,10 +292,21 @@ impl NetworkStream for HttpStream {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn close(&mut self, how: Shutdown) -> io::Result<()> {
|
fn close(&mut self, how: Shutdown) -> io::Result<()> {
|
||||||
match *self {
|
#[inline]
|
||||||
HttpStream::Http(ref mut inner) => inner.0.shutdown(how),
|
fn shutdown(tcp: &mut TcpStream, how: Shutdown) -> io::Result<()> {
|
||||||
HttpStream::Https(ref mut inner) => inner.get_mut().0.shutdown(how)
|
match tcp.shutdown(how) {
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
// see https://github.com/hyperium/hyper/issues/508
|
||||||
|
Err(ref e) if e.kind() == ErrorKind::NotConnected => Ok(()),
|
||||||
|
err => err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
HttpStream::Http(ref mut inner) => shutdown(&mut inner.0, how),
|
||||||
|
HttpStream::Https(ref mut inner) => shutdown(&mut inner.get_mut().0, how)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user