user2144068
user2144068

Reputation: 13

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. Is there a way to read Entire buffer 1 MB in one shot and then process?

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.

  2. Proxy routes data in between client & server, so tried having Producer & consumer thread but problem is NOT solved

Upvotes: 1

Views: 601

Answers (1)

harper
harper

Reputation: 13690

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. 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.

Upvotes: 2

Related Questions