@@ -53,6 +53,51 @@ pub trait TcpStreamExt: Sealed {
5353 /// ```
5454 #[ unstable( feature = "tcp_quickack" , issue = "96256" ) ]
5555 fn quickack ( & self ) -> io:: Result < bool > ;
56+
57+ /// A socket listener will be awakened solely when data arrives.
58+ ///
59+ /// The `accept` argument set the delay in seconds until the
60+ /// data is available to read, reducing the number of short lived
61+ /// connections without data to process.
62+ /// Contrary to other platforms `SO_ACCEPTFILTER` feature equivalent, there is
63+ /// no necessity to set it after the `listen` call.
64+ ///
65+ /// See [`man 7 tcp`](https://man7.org/linux/man-pages/man7/tcp.7.html)
66+ ///
67+ /// # Examples
68+ ///
69+ /// ```no run
70+ /// #![feature(tcp_deferaccept)]
71+ /// use std::net::TcpStream;
72+ /// use std::os::linux::net::TcpStreamExt;
73+ ///
74+ /// let stream = TcpStream::connect("127.0.0.1:8080")
75+ /// .expect("Couldn't connect to the server...");
76+ /// stream.set_deferaccept(1).expect("set_deferaccept call failed");
77+ /// ```
78+ #[ unstable( feature = "tcp_deferaccept" , issue = "119639" ) ]
79+ #[ cfg( target_os = "linux" ) ]
80+ fn set_deferaccept ( & self , accept : u32 ) -> io:: Result < ( ) > ;
81+
82+ /// Gets the accept delay value (in seconds) of the `TCP_DEFER_ACCEPT` option.
83+ ///
84+ /// For more information about this option, see [`TcpStreamExt::set_deferaccept`].
85+ ///
86+ /// # Examples
87+ ///
88+ /// ```no_run
89+ /// #![feature(tcp_deferaccept)]
90+ /// use std::net::TcpStream;
91+ /// use std::os::linux::net::TcpStreamExt;
92+ ///
93+ /// let stream = TcpStream::connect("127.0.0.1:8080")
94+ /// .expect("Couldn't connect to the server...");
95+ /// stream.set_deferaccept(1).expect("set_deferaccept call failed");
96+ /// assert_eq!(stream.deferaccept().unwrap_or(0), 1);
97+ /// ```
98+ #[ unstable( feature = "tcp_deferaccept" , issue = "119639" ) ]
99+ #[ cfg( target_os = "linux" ) ]
100+ fn deferaccept ( & self ) -> io:: Result < u32 > ;
56101}
57102
58103#[ unstable( feature = "tcp_quickack" , issue = "96256" ) ]
@@ -67,4 +112,14 @@ impl TcpStreamExt for net::TcpStream {
67112 fn quickack ( & self ) -> io:: Result < bool > {
68113 self . as_inner ( ) . as_inner ( ) . quickack ( )
69114 }
115+
116+ #[ cfg( target_os = "linux" ) ]
117+ fn set_deferaccept ( & self , accept : u32 ) -> io:: Result < ( ) > {
118+ self . as_inner ( ) . as_inner ( ) . set_deferaccept ( accept)
119+ }
120+
121+ #[ cfg( target_os = "linux" ) ]
122+ fn deferaccept ( & self ) -> io:: Result < u32 > {
123+ self . as_inner ( ) . as_inner ( ) . deferaccept ( )
124+ }
70125}
0 commit comments