1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
//! Linux 和 Android 特定的 tcp 扩展 [`std::net`] 模块中的原语。
//!
//! [`std::net`]: crate::net
use crate::io;
use crate::net;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;
/// [`TcpStream`] 的特定于操作系统的扩展
///
/// [`TcpStream`]: net::TcpStream
#[unstable(feature = "tcp_quickack", issue = "96256")]
pub trait TcpStreamExt: Sealed {
/// 启用或禁用 `TCP_QUICKACK`。
///
/// 该标志使 Linux 急切地发送 ACK 而不是延迟它们。
/// Linux 可能会在对套接字进行进一步操作后重置此标志。
///
/// See [`man 7 tcp`](https://man7.org/linux/man-pages/man7/tcp.7.html) 和
/// [TCP delayed acknowledgement](https://en.wikipedia.org/wiki/TCP_delayed_acknowledgment)
/// 了解更多信息。
///
/// # Examples
///
/// ```no_run
/// #![feature(tcp_quickack)]
/// use std::net::TcpStream;
/// use std::os::linux::net::TcpStreamExt;
///
/// let stream = TcpStream::connect("127.0.0.1:8080")
/// .expect("Couldn't connect to the server...");
/// stream.set_quickack(true).expect("set_quickack call failed");
/// ```
#[unstable(feature = "tcp_quickack", issue = "96256")]
fn set_quickack(&self, quickack: bool) -> io::Result<()>;
/// 获取此套接字上 `TCP_QUICKACK` 选项的值。
///
/// 有关此选项的详细信息,请参见 [`TcpStreamExt::set_quickack`]。
///
/// # Examples
///
/// ```no_run
/// #![feature(tcp_quickack)]
/// use std::net::TcpStream;
/// use std::os::linux::net::TcpStreamExt;
///
/// let stream = TcpStream::connect("127.0.0.1:8080")
/// .expect("Couldn't connect to the server...");
/// stream.set_quickack(true).expect("set_quickack call failed");
/// assert_eq!(stream.quickack().unwrap_or(false), true);
/// ```
#[unstable(feature = "tcp_quickack", issue = "96256")]
fn quickack(&self) -> io::Result<bool>;
}
#[unstable(feature = "tcp_quickack", issue = "96256")]
impl Sealed for net::TcpStream {}
#[unstable(feature = "tcp_quickack", issue = "96256")]
impl TcpStreamExt for net::TcpStream {
fn set_quickack(&self, quickack: bool) -> io::Result<()> {
self.as_inner().as_inner().set_quickack(quickack)
}
fn quickack(&self) -> io::Result<bool> {
self.as_inner().as_inner().quickack()
}
}