小编Flo*_*low的帖子

为什么更改SO_RCVBUF的值不起作用?

我正在创建一个程序来创建一个RAW套接字,以便读取所有流量.在socket()和recvfrom()的调用之间(最后一个是循环以从缓冲区中取出所有数据包)我等待5s.

当我运行程序时,我用"快速模式"(快速填充缓冲区)中的hping3命令向我的程序发送大约200个数据包.一旦经过5秒,我的程序就会从缓冲区中提取大约150个数据包.

我尝试更改接收缓冲区的大小以获得更好的结果:

int a = 65535;
if ( (setsockopt(sockfd, 0, SO_RCVBUF, &a ,sizeof(int)) ) < 0 )
{
    fprintf(stderr, "Error setting sock opts..\n");
}
Run Code Online (Sandbox Code Playgroud)

但是,无论是"a",1还是10000000的值,它似乎都没有变化,我仍然可以从缓冲区获得~150个数据包.

有什么问题?

编辑:通过getsockopt呼叫验证«a»的值.

c sockets buffer setsockopt

7
推荐指数
2
解决办法
3万
查看次数

GCC警告与std = c11 arg

这是一个使用pthread_kill()调用的小C源代码:

#include <stdlib.h>
#include <pthread.h>
#include <signal.h>

int main(int argc, char *argv[])
{
        pthread_t th = NULL;

        pthread_kill(th, 0);

        return 0;
}
Run Code Online (Sandbox Code Playgroud)

Gcc编译根据-std参数值产生各种结果(见下文).我不明白这些不同的行为.除了pthread_kill()符合POSIX.1-2008之外,我没有在手册页中获得有趣的信息.

环境:Linux 3.2 64位.GCC 4.7.2.

使用-std = c11

gcc main.c -std=c11 -pthread
Run Code Online (Sandbox Code Playgroud)

我得到一个隐含的声明:

main.c:9:2: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]
Run Code Online (Sandbox Code Playgroud)

使用-std = c99

gcc main.c -std=c99 -pthread
Run Code Online (Sandbox Code Playgroud)

与-std = c11相同的结果:

main.c:9:2: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]
Run Code Online (Sandbox Code Playgroud)

使用-std = c90

gcc main.c -std=c90 -pthread
Run Code Online (Sandbox Code Playgroud)

它只是没有任何错误/警告.

感谢您的反馈.

c gcc pthreads c11

5
推荐指数
1
解决办法
1979
查看次数

标签 统计

c ×2

buffer ×1

c11 ×1

gcc ×1

pthreads ×1

setsockopt ×1

sockets ×1