This is the prototype of the select statement (acc to man pages):
int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout);
I know what to use the readfds parameter for: with this one you can see if data was written to one of your sockets. On the other hand, the writefds page that I found, states that this is to see “if any of the sockets is ready to send() data to”. But what does this mean? In Windows Sockets Network Programming by Quin and Shute it says that this detects either the connected or the writable state. What is the point of this? Is it simply to check whether a socket still has a connection to a connected client and test whether is has any use writing something to that socket?
So: what does one normally use writefds for?
If you keep writing to a
TCPsocket and the other side doesn’t receive as fast as you send, there comes a time whenwriteblocks. You want to avoid that so you need to test that "you can write without blocking". Because this normally doesn’t happen in test programs, it could come as a shock, butwrite(2)andsend(2)can block.So if
select(2)says afdis set inwritefdsthen it means anywriteorsendon it will actually write at least one byte without blocking.EDIT
From the standard: