c - For how long do the recv() functions buffer in UDP? -


my program contains thread waits udp messages , when message received runs functions before goes listening. worried missing message, question along line of, how long possible read message after has been sent? example, if message sent when thread running functions, still possible read if functions short enough? looking guidelines here, answer in microseconds appreciated.

when computer receives udp packet (and there @ least 1 program listening on udp port specified in packet), tcp stack add packet's data fixed-size buffer associated socket , kept in kernel's memory space. packet's data stay in buffer until program calls recv() retrieve it.

the gotcha if computer receives udp packet , there isn't enough free space left inside buffer fit new udp packet's data, computer throw udp packet away -- it's allowed that, since udp doesn't make guarantees packet arrive.

so amount of time program has call recv() before packets start getting thrown away depend on size of socket's in-kernel packet buffer, size of packets, , rate @ packets being received.

note can ask kernel make receive-buffer size larger calling this:

size_t bufsize = 64*1024;   // dear kernel:  i'd buffer 64kb please! setsockopt(mysock, sol_socket, so_rcvbuf, &bufsize, sizeof(bufsize));   

… , might avoid dropped packets. if that's not sufficient, you'll need either make sure program goes recv() quickly, or possibly network i/o in separate thread doesn't held off processing.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -