summaryrefslogtreecommitdiffstats
path: root/src/tcp.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-09-01 22:14:26 -0700
committerAlex Crichton <alex@alexcrichton.com>2016-09-01 22:14:26 -0700
commit3282b3ec0d0da1237c11e59ea0ac46407dd3edd5 (patch)
tree75aa5cb7c6ea7e932ccde918553f071291132157 /src/tcp.rs
parent2081bcc4308c767ec66c0b55c3edb949718c331f (diff)
Update to mio 0.6
Diffstat (limited to 'src/tcp.rs')
-rw-r--r--src/tcp.rs99
1 files changed, 92 insertions, 7 deletions
diff --git a/src/tcp.rs b/src/tcp.rs
index ce50e70c..4aa6683b 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<u32> {
+ 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<bool> {
+ 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<u32>) -> 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<bool> {
+ 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<u32>) -> 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<Option<u32>> {
+ 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<u32> {
+ 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),
}
}