so here’s my situation. I’m working with winsock, learning some things about networking and protocol devlopment, and i’ve reached an impasse. I’m right now doing a server that blocks at an accept call, but has another thread in the background waiting for user input and handling user input. this user input is used for commands like send,ping, and say, etc. but now i would like a command called exit that will shut down winsock, release all open connections, and then end the program. problem is, this accept thread is still blocking.
so here’s the questions. 1) is there anyway to stop a winsock function from blocking while it’s called, and 2) is something like this in non-blocking mode:
while(m_continue)
{
Sleep(1);
tempsock = accept(m_listenSock, NULL, NULL);
if(tempsock != INVALID_SOCKET)
{
if(WSAGetLastError() == WSAEWOULDBLOCK)
continue;
else
return 1;
}
break;
{
superfluous or just too inneficient to use?
From the user command thread, when you handle the “exit” command, close the
m_listenSocksocket. The blockingaccept()call will immediately drop out withINVALID_SOCKET.Be sure not to close the
m_listenSockhandle twice.