}
}
-#[derive(Debug, Clone)]
+#[derive(Clone)]
pub struct TcpStream {
inner: Socket,
peer_addr: Option<String>,
}
+impl fmt::Debug for TcpStream {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let mut res = f.debug_struct("TcpStream");
+
+ if let Some(ref addr) = self.inner.local_addr {
+ res.field("addr", addr);
+ }
+
+ if let Some(ref peer) = self.peer_addr {
+ res.field("peer", peer);
+ }
+
+ res.field("fd", &self.inner.inner.as_inner())
+ .finish()
+ }
+}
+
fn io_err_to_addr(result: io::Result<&SocketAddr>) -> io::Result<String> {
match result {
Ok(saddr) => Ok(saddr.to_string()),
Ok(TcpStream { inner: Socket::new(fd, local_addr), peer_addr: Some(peer_addr) })
}
- pub fn connect_timeout(addr: &SocketAddr, _: Duration) -> io::Result<TcpStream> {
+ pub fn connect_timeout(addr: &SocketAddr, dur: Duration) -> io::Result<TcpStream> {
+ if dur == Duration::default() {
+ return Err(io::Error::new(io::ErrorKind::InvalidInput,
+ "cannot set a 0 duration timeout"));
+ }
Self::connect(Ok(addr)) // FIXME: ignoring timeout
}
- pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
- sgx_ineffective(())
+ pub fn set_read_timeout(&self, dur: Option<Duration>) -> io::Result<()> {
+ match dur {
+ Some(dur) if dur == Duration::default() => {
+ return Err(io::Error::new(io::ErrorKind::InvalidInput,
+ "cannot set a 0 duration timeout"));
+ }
+ _ => sgx_ineffective(())
+ }
}
- pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
- sgx_ineffective(())
+ pub fn set_write_timeout(&self, dur: Option<Duration>) -> io::Result<()> {
+ match dur {
+ Some(dur) if dur == Duration::default() => {
+ return Err(io::Error::new(io::ErrorKind::InvalidInput,
+ "cannot set a 0 duration timeout"));
+ }
+ _ => sgx_ineffective(())
+ }
}
pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
self.inner.inner.read(buf)
}
- pub fn read_vectored(&self, buf: &mut [IoVecMut<'_>]) -> io::Result<usize> {
- let buf = match buf.get_mut(0) {
- Some(buf) => buf,
- None => return Ok(0),
- };
- self.read(buf)
+ pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result<usize> {
+ io::default_read_vectored(|b| self.read(b), bufs)
}
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
self.inner.inner.write(buf)
}
- pub fn write_vectored(&self, buf: &[IoVec<'_>]) -> io::Result<usize> {
- let buf = match buf.get(0) {
- Some(buf) => buf,
- None => return Ok(0),
- };
- self.write(buf)
+ pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
+ io::default_write_vectored(|b| self.write(b), bufs)
}
pub fn peer_addr(&self) -> io::Result<SocketAddr> {
}
}
-#[derive(Debug, Clone)]
+#[derive(Clone)]
pub struct TcpListener {
inner: Socket,
}
+impl fmt::Debug for TcpListener {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let mut res = f.debug_struct("TcpListener");
+
+ if let Some(ref addr) = self.inner.local_addr {
+ res.field("addr", addr);
+ }
+
+ res.field("fd", &self.inner.inner.as_inner())
+ .finish()
+ }
+}
+
impl TcpListener {
pub fn bind(addr: io::Result<&SocketAddr>) -> io::Result<TcpListener> {
let addr = io_err_to_addr(addr)?;
}
}
-impl<'a> TryFrom<&'a str> for LookupHost {
+impl TryFrom<&str> for LookupHost {
type Error = io::Error;
- fn try_from(v: &'a str) -> io::Result<LookupHost> {
+ fn try_from(v: &str) -> io::Result<LookupHost> {
LookupHost::new(v.to_owned())
}
}