Can anyone tell me the use and application of select function in socket programming in c?
I like description at gnu.org:
Sometimes a program needs to accept input on multiple input channels whenever input arrives. For example, some workstations may have devices such as a digitizing tablet, function button box, or dial box that are connected via normal asynchronous serial interfaces; good user interface style requires responding immediately to input on any device. [...]
You cannot normally use
readfor this purpose, because this blocks the program until input is available on one particular file descriptor; input on other channels won’t wake it up. You could set nonblocking mode and poll each file descriptor in turn, but this is very inefficient.A better solution is to use the
selectfunction. This blocks the program until input or output is ready on a specified set of file descriptors, or until a timer expires, whichever comes first.