Vojtěch Frič
unread,Aug 7, 2013, 3:36:32 AM8/7/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to lib...@googlegroups.com
Hi,
thanks to your explanation earlier I've managed to make server working. But I have stumbled upon another problem, with terminating the server.
ClientThread : Thread {
privateSocket;
waitSet(1);
ClientThread(TCPSocket &clientSocket) {
privateSocket = clientSocket
waitSet.Add(&privateSocket, waitable::READ);
}
void Run() {
while(true){
waitSet.Wait();
if(privateSocket.CanRead()){
// read data
if(bytesRead == 0)
break; // connection closed
} else {
break; //error
}
}
}
void Terminate(){
waitSet.Remove(&privateSocket);
privateSocket.Close();
}
}
The code above is rough sketch of my program, it's written in pseudo C++ (sorry about that).
The idea is that this thread is blocked on the socket, waiting for read. - green text
The ClientThread::Terminate method is called asynchronously, from signal handler. This handler responds to SIGINT. When I send SIGINT to my program, the Terminate method finishes, but the waitSet doesn't unblock.
I have idea of waiting on waitSet with timeout and then checking some variable, whether the thread should terminate, but that seems too close to active waiting, which I don't want.
The question is, is there any way to make my code work? And if not, how can I gracefully terminate thread blocked on waitSet.Wait()?
Thanks,
vf