I am writing a program in C, using socket UDP. My program receives an input message from a socket and then do some calculations before reading an other message from the socket. But, in the meantime, more messages arrive. If I'm right in my tests, they go in a sort of buffer (kind of FIFO, stored directly in the OS ? - more explanation would be appreciated), and everytime I read from the socket, I read the oldest one, right?
Is there a proper way to clear that buffer (FIFO) ? Or i need to make a specific function that reads everything until there nothing more to read so i can ignore all the "in-between" messages ? Or maybe "close" the socket and "re-open" after my prediction calculus ?
And of course, is my understanding of the FIFO right or i'm missing something ?
Context if you want to understand more : I have a real-time program that receives every seconds a monitoring message via UDP socket from an external equipment. I read the first one, make some predictions during multiples seconds and then i need to read each seconds the newest messages, and not having everything shifted by reading the older's one. So during this "prediction" i want to ignore those messages.
Thanks