bash 如何在linux中激活TCP Fast Open

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30079248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:56:59  来源:igfitidea点击:

how to activate the TCP Fast Open in linux

linuxbashsocketstcp

提问by MOHAMED

I have 2 PCs linux (PC1: kernel 3.13.0-37 and PC2: kernel 3.11.0-12)

我有 2 台 linux 电脑(PC1:内核 3.13.0-37 和 PC2:内核 3.11.0-12)

PC1-------PC2(TCP server port 4410)

From PC1, I m sending a tcp packet with TCP Fast Open (Fast Open Cookie Request)

从 PC1,我发送一个 TCP 快速打开的 tcp 数据包(快速打开 Cookie 请求)

enter image description here

在此处输入图片说明

I m expecting to get an answer from the server with TCP option (Fast Open Cookie: xxxxxxx) something like this:

我期待从带有 TCP 选项(快速打开 Cookie:xxxxxxx)的服务器得到类似这样的答案:

enter image description here

在此处输入图片说明

But I got a tcp packet without the TCP option (Fast Open Cookie: xxxxxxx).

但是我得到了一个没有 TCP 选项的 tcp 数据包(快速打开 Cookie:xxxxxxx)。

I m wondering if there is something to configure on my PC2 (linux) in order to activate the TCP Fastt Open option.

我想知道我的 PC2 (linux) 上是否需要配置一些东西来激活 TCP Fastt Open 选项。

For the TCP server, I m running a php script:

对于 TCP 服务器,我正在运行一个 php 脚本:

$sock = socket_create(AF_INET, SOCK_STREAM, 0);

// Bind the socket to an address/port
socket_bind($sock, "0.0.0.0", 4410) or die('Could not bind to address');
for(;;) {
    // Start listening for connections
    socket_listen($sock);
    ...
}

回答by cpaasch

You have to enable TFO in the server's listening socket with:

您必须使用以下命令在服务器的侦听套接字中启用 TFO:

int qlen = 5;
setsockopt(fd, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen));

(https://lwn.net/Articles/508865/)

( https://lwn.net/Articles/508865/)