Ok, now that the thread hijack is over, let's return to:
Quote:
Originally Posted by PinoyAko
Plan 1: The program would open both tcp and udp sockets and then use select() on both.
Plan 2: The program would create 2 threads. one thread is for the TCP and the second one is for the UDP. I would still use select().
Plan 3: Make the program check for an argument that would signal the program to either start as udp or tcp server. So this would mean two instance of this program would be running one would be listening on tcp and the other on udp.
|
There might be factors of which I'm unaware in your situation, but just with what I know of your question, I vote for 3, then 1, then 2.
1 is superior to 2 because at any given time you're responding to one event, so you don't need to worry about synchronizing access to data.
But assuming that the TCP server and the UDP server don't share any data, 3 is superior to 1, because you don't have two otherwise independent chunks of code sharing the same heap. This makes the code easier to debug in case of buffer overrun. Otherwise, for example, the UDP server code might trash the heap but still be smiling with glistening teeth as the TCP server code dies because of the heap corruption.