I am trying to create a CAsyncSocket class like to work on linux, iphone and win32 as well. It is almost finish but I have one problem that I don't know how to solve.
My concern is about the client (not the server).
To make simple, I have a main thread and a socket event thread. The socket event thread have an infinite loop that contains a "select" function. I have a timeout for the select function, let say 10 seconds here. This socket event thread will monitor the events for ALL the sockets that will be created on the main thread.
At the beginning, there are no socket, so the select function always time out.
Then here we go. I create a new socket on the main thread. I try to connect to a server, using mySocket->Connect("192.168.1.4", 108) for example. I need to monitor the events in the socket event thread. But if the select function is actually running, I may have to wait up to 10 seconds before having the chance to add my socket to the file descriptors for the next "select" call. I could obviously reduce the timeout value but the best would be able to interrupt the "select" call immediately, when I want.
I also have this problem for writing. My main thread could do nothing on the client socket, the user would be writing some text in a text box. Then after a coffee, he will click on the send button. I need only at that time to monitor the write event if the socket couldn't send the whole text (don't forget that I am in asynchronous mode).
Also, I have to find a solution that works on Linux AND windows.