简体   繁体   English

UDP一口气读取整个套接字缓冲区

[英]UDP Read entire socket buffer in one shot

I have 3 components client-proxy-server, at times when the proxy gets heavily loaded the socket buffers configure to say 1 MB gets filled. 我有3个组件client-proxy-server,有时代理负载很重时,套接字缓冲区配置为说1 MB被填充。 Is there a way to read Entire buffer 1 MB in one shot and then process? 有没有一种方法可以一次性读取1 MB的整个缓冲区,然后进行处理?

FYI: 供参考:

  1. all the data grams never goes beyond MTU size are in per-defined structural format, where in length of each packet is also added. 永不超过MTU大小的所有数据报都是按照定义的结构格式,其中每个数据包的长度也被添加。

  2. Proxy routes data in between client & server, so tried having Producer & consumer thread but problem is NOT solved 代理在客户端和服务器之间路由数据,因此尝试使用Producer和Consumer线程,但问题未解决

Short answer : no. 简短的回答 :不。

Long answer : The Berkeley style socket implementation allows to receive or send only one packet per call. 长答案 :伯克利风格的套接字实现每次调用仅接收或发送一个数据包。 Therefore it is not possible to read a complete network stream and replay it at the other side. 因此,不可能读取完整的网络流并在另一端重播它。

One reason is that your UDP socket can receive data from several sources. 原因之一是您的UDP套接字可以从多个来源接收数据。 The interface should be able to pass the meta information like sender socket address, and at least the packet size to the caller. 接口应该能够将元信息(例如发送方套接字地址)以及至少数据包大小传递给调用方。 This is bunch of data should be parsed and you would pick the packets that meet a criteria. 这是应该解析的数据堆,您将选择符合条件的数据包。 Finally you could build the bunch of packets to send. 最终,您可以构建一堆要发送的数据包。

Since you have to have the possibility to check each packet, if the packet is really expected you need a function to read a packet from the bunch. 由于必须检查每个数据包,因此,如果确实需要该数据包,则需要一个函数以从束中读取数据包。 This is the function recvfrom . 这是功能recvfrom

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM