What to use the "fd_set * writefds" parameter in the select () clause for

This is a prototype of the select statement (in 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 you can see if the data has been written to one of your sockets. On the other hand, the writefds page I found says that it means "if any of the sockets is ready to send () data to." But what does this mean? Windows Sockets Network Programming by Quin and Shute says this detects either a connected or a writable state. What is the point? It is simple to check if the socket still has a connection to the connected client and checks if there is anything using something in this socket?

So: what are writefds commonly used for?

+1
source share
1 answer

If you continue to write to the socket TCP, and the other side does not receive as fast as you send, the time comes when it blocks . You want to avoid this, so you need to check that "you can write without blocking." Since this does not normally happen in test programs, this can be a shock, but it can also be blocked . write write(2)send(2)

So, if it select(2)says that a is fdset to writefds, then it means that anyone writeor sendon it will write at least one byte without blocking.

EDIT

From standard :

pselect() , readfds, writefds errorfds , , , .

+7

All Articles