I have a server running fine. This servers is a multi-client and it's working fine, but I don't think I'm using the best approach for this and the main point for this assumption is the way I 'exit' application. I'm handling signals and just exiting, but it's not right, I can't even debug using valgrind.
In my other apps, I use a global variable to hold app state, for example, pexit
and in every thread that runs 'forever', the condition is:
while (!pexit) ....
And in the signal handle I just set 'pexit' to 'true' and everything works fine. But my problem is in listening function, which is 'blocking', therefore I can't use my global variable. Is a better way to do this without blocking?
while ((client_sock = accept(socket_desc, (struct sockaddr *) &client, (socklen_t*) & c))) {
....