Is there a way to have 'select' waiting for reads and writes, while also being able to add new file descriptors? Preferrably on one thread?
Now that I know what your scenario is (a socket-based server that may want to accept new incoming connections), did you know that you can append the file-descriptor for your listening socket to the list for select? See e.g. http://www.lowtek.com/sockets/select.html.
(Paraphrased example:)
fd_set socks;
FD_ZERO(&socks);
// Add listener socket
listen(sock, n);
FD_SET(&socks, sock);
// Add existing socket connections
for (i = 0; i < num_existing_connections; i++)
{
FD_SET(&socks, connection[i]);
}
// Will break if any of the existing connections are active,
// or if a new connection appears.
select(..., &socks, ...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With