I'm looking to find a way to receive a UDP packet via interrupts vs. some form of polling in C. I am trying to minimize CPU resources as much as possible. Thanks!

I'm looking to find a way to receive a UDP packet via interrupts vs. some form of polling in C.  I am trying to minimize CPU resources as much as possible.  Thanks!
rounders1086Asked:
Who is Participating?
 
mrjoltcolaConnect With a Mentor Commented:
1) select() with reasonable timeout value is a great, simple way to poll while not blocking indefinitely. select() for 100 milliseconds at a time lets your loop process 10 times a second if needed. If a packet arrives, the select will return immediately without waiting for 100ms.

2) A thread that just issues a blocking read()/recvfrom() is probably as cpu minimal as you can get.

Are you only interested in processes the packet, or are there other tasks that must be carried out in parallel? If so, either option above will work, but if you want to completely decouple the tasking so a long-running background task does not block the network messaging, go with a thread.

There are a few other ways, like async io receiving SIGIO to your process, then you still have to call select() to find which descriptor is ready. I prefer alternatives above to that.

If these aren't satisfactory there are other ways, including Linux non-portable ways.
0
All Courses

From novice to tech pro — start learning today.