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");
1
jjshare 2020-10-05 01:33:43 +08:00
头文件没引?
|
2
holinhot OP @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> |
3
jedihy 2020-10-05 01:46:42 +08:00
#include <netinet/tcp.h>
|
4
holinhot OP @jedihy 引入 include <netinet/tcp.h>是不报错误了,不过 TCP_WINDOW_CLAMP 参数不生效。用 python 测试 TCP_WINDOW_CLAMP 是可以生效的。
|
6
BrettD 2020-10-05 07:52:58 +08:00 via iPhone
这报的是语法错误啊
|