Exxtra
BANNED
- Aug 9, 2009
- 447
- 426
For those who are experienced writing programs which uses the socket API, which of these methods do you consider to be superior and why:
1) Divide the main loop of the program into sections, where one section processes data to be sent and sends it in batches, then after the batch is complete it jumps to another section to check for responses, processing the responses if there are any, then repeating. The responses are checked for once per batch and not every time.
2) Do everything inline without batching, where the processed data is sent, then a response is checked for immediately, if no response yet restart loop to send more and check again for response. In this way you are running select(); each time (with zero timeout) you send data to see if there are any results from the previously sent data.
3) Some other way not mentioned - please tell us.
Lastly, when using select(); do you prefer to set a timeout above zero, or do you find that it is better to manage the looping cycles by calling sleep(); or usleep(); separately? I'll share my findings and opinions after we get a few responses.
1) Divide the main loop of the program into sections, where one section processes data to be sent and sends it in batches, then after the batch is complete it jumps to another section to check for responses, processing the responses if there are any, then repeating. The responses are checked for once per batch and not every time.
2) Do everything inline without batching, where the processed data is sent, then a response is checked for immediately, if no response yet restart loop to send more and check again for response. In this way you are running select(); each time (with zero timeout) you send data to see if there are any results from the previously sent data.
3) Some other way not mentioned - please tell us.
Lastly, when using select(); do you prefer to set a timeout above zero, or do you find that it is better to manage the looping cycles by calling sleep(); or usleep(); separately? I'll share my findings and opinions after we get a few responses.