multithreading - Safely close an indefinitely running thread -
so first off, realize if code in loop use do while
loop check variable set when want thread close, in case not possible (so seems):
dword winapi recv thread (lpvoid random) { recv(clientsocket, recvbuffer, recvbuflen, 0); return 1; }
in above, recv() blocking function. (please pardon me if formatting isn't correct. it's best can on phone.)
how go terminating thread since never closes never loops?
thanks, ~p
amongst other solutions can
a) set timeout socket , handle timeouts correctly checking return values and/or errors in appropriate loop:
setsockopt(clientsocket,sol_socket,so_rcvtimeo,(char *)&timeout,sizeof(timeout))
b) close socket recv(..)
returning blocked state error.
Comments
Post a Comment