]> git.lizzy.rs Git - rust.git/blob - library/std/src/os/net/linux_ext/tcp.rs
Rollup merge of #104378 - compiler-errors:chalk-up, r=jackh726
[rust.git] / library / std / src / os / net / linux_ext / tcp.rs
1 //! Linux and Android-specific tcp extensions to primitives in the [`std::net`] module.
2 //!
3 //! [`std::net`]: crate::net
4
5 use crate::io;
6 use crate::net;
7 use crate::sealed::Sealed;
8 use crate::sys_common::AsInner;
9
10 /// Os-specific extensions for [`TcpStream`]
11 ///
12 /// [`TcpStream`]: net::TcpStream
13 #[unstable(feature = "tcp_quickack", issue = "96256")]
14 pub trait TcpStreamExt: Sealed {
15     /// Enable or disable `TCP_QUICKACK`.
16     ///
17     /// This flag causes Linux to eagerly send ACKs rather than delaying them.
18     /// Linux may reset this flag after further operations on the socket.
19     ///
20     /// See [`man 7 tcp`](https://man7.org/linux/man-pages/man7/tcp.7.html) and
21     /// [TCP delayed acknowledgement](https://en.wikipedia.org/wiki/TCP_delayed_acknowledgment)
22     /// for more information.
23     ///
24     /// # Examples
25     ///
26     /// ```no_run
27     /// #![feature(tcp_quickack)]
28     /// use std::net::TcpStream;
29     /// use std::os::linux::net::TcpStreamExt;
30     ///
31     /// let stream = TcpStream::connect("127.0.0.1:8080")
32     ///         .expect("Couldn't connect to the server...");
33     /// stream.set_quickack(true).expect("set_quickack call failed");
34     /// ```
35     #[unstable(feature = "tcp_quickack", issue = "96256")]
36     fn set_quickack(&self, quickack: bool) -> io::Result<()>;
37
38     /// Gets the value of the `TCP_QUICKACK` option on this socket.
39     ///
40     /// For more information about this option, see [`TcpStreamExt::set_quickack`].
41     ///
42     /// # Examples
43     ///
44     /// ```no_run
45     /// #![feature(tcp_quickack)]
46     /// use std::net::TcpStream;
47     /// use std::os::linux::net::TcpStreamExt;
48     ///
49     /// let stream = TcpStream::connect("127.0.0.1:8080")
50     ///         .expect("Couldn't connect to the server...");
51     /// stream.set_quickack(true).expect("set_quickack call failed");
52     /// assert_eq!(stream.quickack().unwrap_or(false), true);
53     /// ```
54     #[unstable(feature = "tcp_quickack", issue = "96256")]
55     fn quickack(&self) -> io::Result<bool>;
56 }
57
58 #[unstable(feature = "tcp_quickack", issue = "96256")]
59 impl Sealed for net::TcpStream {}
60
61 #[unstable(feature = "tcp_quickack", issue = "96256")]
62 impl TcpStreamExt for net::TcpStream {
63     fn set_quickack(&self, quickack: bool) -> io::Result<()> {
64         self.as_inner().as_inner().set_quickack(quickack)
65     }
66
67     fn quickack(&self) -> io::Result<bool> {
68         self.as_inner().as_inner().quickack()
69     }
70 }