Original Post
Right now I'm polling non-blocking sockets, but I'd like to move to an event-based model to reduce lag. select() seems to be what's recommended, but I have a few problems with it...
Let's say you have ten clients, and you've used select with their file descriptors in readfds. (You're waiting for one or more of them to send data). Now another client connects, and you'd like to add it to readfds. So, I guess you would send an interrupt signal to select's thread and add him in?
Now what if you need to write data to the clients? Again - interrupt select, add the file descriptors to writefds. It seems to me that you'd be continually interrupting select to add new sockets to the fds. If you were sending and receiving to 100 clients, you'd be interupting select thousands of times per second.
Or you could call select with a timeout, which is an awful lot like polling, which I already have. :P
So what's the proper way to use select? I'm looking for low latency and scalability here.
Let's say you have ten clients, and you've used select with their file descriptors in readfds. (You're waiting for one or more of them to send data). Now another client connects, and you'd like to add it to readfds. So, I guess you would send an interrupt signal to select's thread and add him in?
Now what if you need to write data to the clients? Again - interrupt select, add the file descriptors to writefds. It seems to me that you'd be continually interrupting select to add new sockets to the fds. If you were sending and receiving to 100 clients, you'd be interupting select thousands of times per second.
Or you could call select with a timeout, which is an awful lot like polling, which I already have. :P
So what's the proper way to use select? I'm looking for low latency and scalability here.