【发布时间】:2016-11-23 00:57:51
【问题描述】:
我的 udp 接收器套接字的设置非常标准。我的发送器以 36Hz 发送数据,接收器以 72Hz 读取数据。每次发送 12072 字节。
当我执行 cat /proc/net/udp.我经常得到
sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode ref pointer drops
7017: 0101007F:0035 00000000:0000 07 00000000:00000000 00:00000000 00000000 0 0 10636 2 0000000000000000 0
7032: 00000000:0044 00000000:0000 07 00000000:00000000 00:00000000 00000000 0 0 14671 2 0000000000000000 0
7595: 00000000:0277 00000000:0000 07 00000000:00000000 00:00000000 00000000 0 0 11113 2 0000000000000000 0
7660: 00000000:22B8 00000000:0000 07 00000000:00004100 00:00000000 00000000 1000 0 251331 3 0000000000000000 352743
你可以看到 rx_queue 里面有一些值,读取速度不够快?
我的代码
int recv_len = recvfrom(s, buf, BUFLEN, MSG_TRUNC, (struct sockaddr *) &si_other, &slen);
// dont worry buflen is like 64000 no error here
std::cout <<" recv_len "<<recv_len<<std::endl;
即使队列很大,我总是得到输出为 recv_len 12072 ?为什么是这样 ?有没有办法加快我的阅读速度或阅读队列中的所有消息?即使我的阅读频率更高,我也不明白这是怎么回事。
【问题讨论】:
-
也许你的代码没有按照你的想法做? (例如,您认为您正在以 72HZ 的频率阅读,但事实并非如此。或者您还没有发现一个简单的错误……等等)