Winsock的UDP数据包被丢弃? [英] Winsock UDP packets being dropped?

查看:245
本文介绍了Winsock的UDP数据包被丢弃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们必须在UDP上安装Windows中的客户机/服务器通信系统。我们所面临的问题是,当吞吐量的增长,数据包被越来越下降。我们怀疑这是由于它不断轮询造成堵塞缓冲区,并丢弃任何传入数据包的UDP接收缓冲区。是否有可能在读这个缓冲区会导致进入的数据包被丢弃?如果是这样,有什么办法解决这个选项?该系统是在写C.请让我知道这是太含糊,我可以尝试提供更多的信息。谢谢!

We have a client/server communication system over UDP setup in windows. The problem we are facing is that when the throughput grows, packets are getting dropped. We suspect that this is due to the UDP receive buffer which is continuously being polled causing the buffer to be blocked and dropping any incoming packets. Is it possible that reading this buffer will cause incoming packets to be dropped? If so, what are the options to correct this? The system is written in C. Please let me know if this is too vague and I can try to provide more info. Thanks!

推荐答案

在Windows套接字的缺省套接字缓冲区大小为8K或8192字节。使用 setsockopt的的Windows功能,增加缓冲区的大小(请参考到SO_RCVBUF选项)。

The default socket buffer size in Windows sockets is 8k, or 8192 bytes. Use the setsockopt Windows function to increase the size of the buffer (refer to the SO_RCVBUF option).

但除此之外,增加你的接收缓冲区的大小,只会拖延时间,直到数据包得到再度回落,如果你不读包不够快。

But beyond that, increasing the size of your receive buffer will only delay the time until packets get dropped again if you are not reading the packets fast enough.

通常情况下,你希望两个线程这种情况。

Typically, you want two threads for this kind of situation.

第一个线程只存在服务插座。换句话说,线程的唯一目的是从套接字读一个数据包时,把它添加到某种适当同步的共享数据结构,信号,即一个数据包已经收到,然后读取下一个包

The first thread exists solely to service the socket. In other words, the thread's sole purpose is to read a packet from the socket, add it to some kind of properly-synchronized shared data structure, signal that a packet has been received, and then read the next packet.

第二个线程的存在是为了处理接收到的报文。它处于闲置状态,直到第一个线程信号数据包已经收到。然后,从正确同步共享数据结构拉动的分组,并且处理它。然后等待再次发出信号。

The second thread exists to process the received packets. It sits idle until the first thread signals a packet has been received. It then pulls the packet from the properly-synchronized shared data structure and processes it. It then waits to be signaled again.

作为试验,尝试短路的分组的完整的处理和只写每一个数据包已经收到的时间信息到控制台(或文件)。如果你能成功地做到这一点不丢失数据包,再破你的功能集成到一个接收线程和一个处理线程会有所帮助。

As a test, try short-circuiting the full processing of your packets and just write a message to the console (or a file) each time a packet has been received. If you can successfully do this without dropping packets, then breaking your functionality into a "receiving" thread and a "processing" thread will help.

这篇关于Winsock的UDP数据包被丢弃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆