C 语言里不支持的 TCP 窗口大小调整吗

2020-10-05 01:27:48 +08:00
 holinhot

gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)编译的时候报错误。

*server2.c: In function ‘create_server_fd’: server2.c:81:42: error: ‘TCP_WINDOW_CLAMP’ undeclared (first use in this function) if (setsockopt(serverfd, SOL_SOCKET, TCP_WINDOW_CLAMP, (char )& WINDOW_CLAMP, sizeof(WINDOW_CLAMP)) < 0) ^ server2.c:81:42: note: each undeclared identifier is reported only once for each function it appears in

int serverfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
    int REUSEADDR = 1;
    int REUSEPORT = 1;
    int WINDOW_CLAMP = 1;
    if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&REUSEADDR, sizeof(REUSEADDR)) < 0)
        perror("setsockopt(SO_REUSEADDR) failed");
    if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&REUSEPORT, sizeof(REUSEPORT)) < 0)
        perror("setsockopt(SO_REUSEPORT) failed");
    if (setsockopt(serverfd, SOL_SOCKET, TCP_WINDOW_CLAMP, (char *)& WINDOW_CLAMP, sizeof(WINDOW_CLAMP)) < 0)
        perror("setsockopt(TCP_WINDOW_CLAMP) failed");


    if (serverfd == -1)
        EXIT("create socket fail");
1717 次点击
所在节点    问与答
6 条回复
jjshare
2020-10-05 01:33:43 +08:00
头文件没引?
holinhot
2020-10-05 01:41:25 +08:00
@jjshare 有引入,前面加的两个 SO_REUSEPORT 和 SO_REUSEADDR 没问题

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#include <ctype.h>
jedihy
2020-10-05 01:46:42 +08:00
#include <netinet/tcp.h>
holinhot
2020-10-05 02:42:18 +08:00
@jedihy 引入 include <netinet/tcp.h>是不报错误了,不过 TCP_WINDOW_CLAMP 参数不生效。用 python 测试 TCP_WINDOW_CLAMP 是可以生效的。
holinhot
2020-10-05 03:17:07 +08:00
@jedihy 可以了 TCP_WINDOW_CLAMP 是 IPPROTO_TCP 下的参数。c 新手
BrettD
2020-10-05 07:52:58 +08:00
这报的是语法错误啊

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/712555

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX