From 3282b3ec0d0da1237c11e59ea0ac46407dd3edd5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 1 Sep 2016 22:14:26 -0700 Subject: [PATCH] Update to mio 0.6 --- Cargo.toml | 4 +-- src/tcp.rs | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 94 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 39cfe58d8..72588d886 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,9 @@ the rest of the tokio crates. [dependencies] futures = { git = "https://github.com/alexcrichton/futures-rs" } log = "0.3" -mio = { git = "https://github.com/carllerche/mio" } +mio = "0.6" scoped-tls = "0.1.0" -slab = { git = "https://github.com/carllerche/slab" } +slab = "0.3" [dev-dependencies] env_logger = "0.3" diff --git a/src/tcp.rs b/src/tcp.rs index ce50e70c6..4aa6683b8 100644 --- a/src/tcp.rs +++ b/src/tcp.rs @@ -1,5 +1,5 @@ use std::fmt; -use std::io::{self, ErrorKind, Read, Write}; +use std::io::{self, Read, Write}; use std::mem; use std::net::{self, SocketAddr, Shutdown}; @@ -115,6 +115,44 @@ impl TcpListener { }) }).boxed() } + + /// Sets the value for the `IP_TTL` option on this socket. + /// + /// This value sets the time-to-live field that is used in every packet sent + /// from this socket. + pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { + self.io.get_ref().set_ttl(ttl) + } + + /// Gets the value of the `IP_TTL` option for this socket. + /// + /// For more information about this option, see [`set_ttl`][link]. + /// + /// [link]: #method.set_ttl + pub fn ttl(&self) -> io::Result { + self.io.get_ref().ttl() + } + + /// Sets the value for the `IPV6_V6ONLY` option on this socket. + /// + /// If this is set to `true` then the socket is restricted to sending and + /// receiving IPv6 packets only. In this case two IPv4 and IPv6 applications + /// can bind the same port at the same time. + /// + /// If this is set to `false` then the socket can be used to send and + /// receive packets from an IPv4-mapped IPv6 address. + pub fn set_only_v6(&self, only_v6: bool) -> io::Result<()> { + self.io.get_ref().set_only_v6(only_v6) + } + + /// Gets the value of the `IPV6_V6ONLY` option for this socket. + /// + /// For more information about this option, see [`set_only_v6`][link]. + /// + /// [link]: #method.set_only_v6 + pub fn only_v6(&self) -> io::Result { + self.io.get_ref().only_v6() + } } impl fmt::Debug for TcpListener { @@ -252,9 +290,56 @@ impl TcpStream { self.io.get_ref().set_nodelay(nodelay) } - /// Sets the keepalive time in seconds for this socket. - pub fn set_keepalive_s(&self, seconds: Option) -> io::Result<()> { - self.io.get_ref().set_keepalive(seconds) + /// Gets the value of the `TCP_NODELAY` option on this socket. + /// + /// For more information about this option, see [`set_nodelay`][link]. + /// + /// [link]: #method.set_nodelay + pub fn nodelay(&self) -> io::Result { + self.io.get_ref().nodelay() + } + + /// Sets whether keepalive messages are enabled to be sent on this socket. + /// + /// On Unix, this option will set the `SO_KEEPALIVE` as well as the + /// `TCP_KEEPALIVE` or `TCP_KEEPIDLE` option (depending on your platform). + /// On Windows, this will set the `SIO_KEEPALIVE_VALS` option. + /// + /// If `None` is specified then keepalive messages are disabled, otherwise + /// the number of milliseconds specified will be the time to remain idle + /// before sending a TCP keepalive probe. + /// + /// Some platforms specify this value in seconds, so sub-second millisecond + /// specifications may be omitted. + pub fn set_keepalive_ms(&self, keepalive: Option) -> io::Result<()> { + self.io.get_ref().set_keepalive_ms(keepalive) + } + + /// Returns whether keepalive messages are enabled on this socket, and if so + /// the amount of milliseconds between them. + /// + /// For more information about this option, see [`set_keepalive_ms`][link]. + /// + /// [link]: #method.set_keepalive_ms + pub fn keepalive_ms(&self) -> io::Result> { + self.io.get_ref().keepalive_ms() + } + + /// Sets the value for the `IP_TTL` option on this socket. + /// + /// This value sets the time-to-live field that is used in every packet sent + /// from this socket. + pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { + self.io.get_ref().set_ttl(ttl) + } + + /// Gets the value of the `IP_TTL` option for this socket. + /// + /// For more information about this option, see [`set_ttl`][link]. + /// + /// [link]: #method.set_ttl + pub fn ttl(&self) -> io::Result { + self.io.get_ref().ttl() } } @@ -276,9 +361,9 @@ impl Future for TcpStreamNew { // If all that succeeded then we ship everything on up. match stream.io.poll_write() { Poll::Ok(()) => { - match stream.io.get_ref().take_socket_error() { - Ok(()) => return Poll::Ok(stream), - Err(ref e) if e.kind() == ErrorKind::WouldBlock => {} + match stream.io.get_ref().take_error() { + Ok(Some(e)) => return Poll::Err(e), + Ok(None) => return Poll::Ok(stream), Err(e) => return Poll::Err(e), } }