- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在编写一个使用 TCP Fast Open 的小型服务器通过 setsockopt()
选项。但是我从 gcc 得到这个错误:
$gcc server.c
server.c: In function 'main':
server.c:35:34: error: 'TCP_FASTOPEN' undeclared (first use in this function)
if (setsockopt(sock, IPPROTO_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen) == -1)
这是服务器的代码:
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int main(int argc, char *argv[])
{
short port = 45000;
int max_conn = 10;
int fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd == -1)
{
printf("Couldn't create socket: %s\n", strerror(errno));
return -1;
}
struct sockaddr_in ssi;
ssi.sin_family = AF_INET;
ssi.sin_port = htons(port);
ssi.sin_addr.s_addr = INADDR_ANY;
if (bind(fd, (struct sockaddr *)&ssi, sizeof(struct sockaddr_in)) != 0)
{
printf("Couldn't bind socket: %s\n", strerror(errno));
return -1;
}
// TFO
int qlen = 5;
if (setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)) == -1)
{
printf("Couldn't set TCP_FASTOPEN option: %s\n", strerror(errno));
return -1;
}
if (listen(fd, max_conn) != 0)
{
printf("Could'nt listen on socket: %s\n", strerror(errno));
return -1;
}
struct sockaddr_in csi;
int clen = sizeof(csi);
int cfd = accept(fd, (struct sockaddr *)&csi, &clen);
return 0;
}
为什么 gcc 报错?
宏TCP_FASTOPEN
位于内核中的include/uapi/linux/tcp.h
,它的值为23所以我试图在我的代码中重新定义它,然后它会编译并运行,但服务器不会发送该选项作为对 TFO 请求的答复(在 SYN-ACK 中)。
有人知道为什么吗?这与编译问题有关吗?
最佳答案
/proc/sys/net/ipv4/tcp_fastopen
needs to be set to 2启用服务器端使用 TCP 快速打开选项:
The tcp_fastopen file can be used to view or set a value that enables the operation of different parts of the TFO functionality. Setting bit 0 (i.e., the value 1) in this value enables client TFO functionality, so that applications can request TFO cookies. Setting bit 1 (i.e., the value 2) enables server TFO functionality, so that server TCPs can generate TFO cookies in response to requests from clients. (Thus, the value 3 would enable both client and server TFO functionality on the host.)
此外,TCP_FASTOPEN 宏需要包含在 #include <netinet/tcp.h>
中.
关于sockets - TCP_FASTOPEN 未声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36553384/
我正在编写一个使用 TCP Fast Open 的小型服务器通过 setsockopt() 选项。但是我从 gcc 得到这个错误: $gcc server.c server.c: In functio
我一直在阅读有关 Linux 中的 TCP_FASTOPEN 的信息,但我无法弄清楚保存的 cookie 是什么。 如果我的 Linux 服务器上的一个程序使用 tcp 快速打开连接,连接到同一服务器
有没有哪位stackoverflow成员(member)可以查看文件中的值 /proc/sys/net/ipv4/tcp_fastopen 在 Android 6 设备上? 谢谢! 最佳答案 这是我在
boost::asio::ip::tcp::acceptor 如何与 TCP_DEFER_ACCEPT 和 TCP_FASTOPEN 一起工作, 当我使用纯 C 时,我可以设置一些参数,如 TCP_D
我是一名优秀的程序员,十分优秀!