Reputation: 125
my server uses non-blocking socket multiplexing. I want to use one thread for receiving incoming connections and handle input and another thread for sending data over sockets. It will look like that:
reader_worker(...)
{
...
select(fd_max+1, &read_set, NULL, NULL, NULL);
...
}
writer_worker(...)
{
...
select(fd_max+1, NULL, &write_set, NULL, NULL);
...
}
Since I don't want to miss incoming connections I can imagine it is better to receive and send in seperate threads. Do I have to lock the socket which might be in read_set as well as in write_set? Is this the correct approach or doesnt this method have any performance improvement?
Upvotes: 0
Views: 666
Reputation: 17415
You're not going to miss any incoming connection if you do it in one thread. Even if you have large amounts of data to send or receive, the latency of a send() or recv() call is determined by the size of local buffers in the network stack rather, so you will be back quickly to accept incoming connections.
Two thing though, where I'm not sure about your code samples:
Upvotes: 1