开发者

caching data packets

开发者 https://www.devze.com 2023-01-03 08:06 出处:网络
Not sure if this is the right place to ask, but here goes.... I implemented a UDP client/server using normal sockets in linux.

Not sure if this is the right place to ask, but here goes....

I implemented a UDP client/server using normal sockets in linux.

(Assuming there is nothing on the network side between these 2 hosts that interferes with the packet in any way, but just pass it on as is)

Does the kernel do any kind of caching/optimization of these UDP packets (it is the exact same data packet I send each time)

I'm doing some testing whi开发者_Go百科ch "ping pongs" different size packets between client/server and want to know if I need to pad the packet with random data every time or can I just send this "fixed content" packet all the time? (packet size stays the same for each test).


Unless a BPF (Berkeley Packet Filter) or equivalent (i.e. firewall) has been set up to examine traffic and possibly alter it, the stack should be blissfully unaware of the payloads in your datagrams. You should be able to use the same packets over again.


As armardeep said, the stack is unaware of the payload. Firewalls don't usually modify datagrams, they let them though or block them completely.

The kernel doesn't 'cache' packages but will buffer them. There will be at least an output buffer where the packages end up until the network line is free, and an input buffer where received packages are stored until your code calls the recv method.

In practice there might be some more buffers in the pipeline, but from the applications point of view the kernel will behave as if it only has those two buffers. Both can overflow by the way.


There is a kernel buffer associated with the socket where the packets are stored until you call recv. If the kernel receives data faster than you remove data from the socket buffer, then an overflow will occur and the kernel will silently discard your packets. You can increase the size of the receive buffer for that particular socket using a call to setsockopt.

int rcvbuflen = 0x20000; // 128kb
setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &rcvbuflen, sizeof(rcvbuflen));

You can use getsockopt to check the current size of the buffer.

0

精彩评论

暂无评论...
验证码 换一张
取 消