From what I understood from all the documentations of select(), it seems that select()ing on a write fd_set could be used to check for socket (descriptor) availibility for send()ing so that could be used to detect a successful non-blocking connect() attempt, but what I don’t get is when does a socket ever become unavailable after a successful connect() or accept()?
And does that in theory mean that the socket is always available for send()ing?
As a last question, is it practical to keep select()ing connected sockets in for write operations for the whole session?
Thanks.
The most common case of a socket being unavailable for writing is when the connection goes through a relatively slow network link that your application can saturate. The operating system will buffer a limited amount of data, so your application will have to restrain itself by checking if the socket is available (indicating that some data has been sent and the buffer has free space) before sending more.
As for your other question, if you have multiple sockets of any kind in use by a single thread, as is the case with e.g. a web server, it certainly makes sense to use select() in order to manage them efficiently.