UINT MyThreadProc (LPVOID pParam)
{
Char buff [2000].
int n;
The SOCKET Client=((RECVPARAM *) pParam) - & gt; The sock.
HWND HWND=((RECVPARAM *) pParam) - & gt; The HWND;
SOCKADDR_IN Addr=((RECVPARAM *) pParam) - & gt; Addr.
If (SOCKET_ERROR==connect (Client, (SOCKADDR *) & amp; Addr, sizeof (SOCKADDR)))
{
Int nError=WSAGetLastError ();
Cstrings strErrorMsg;
SendMessage (hWnd WM_NETERROR, 0, 0);
return FALSE;
}
: : SendMessage (hWnd WM_NETCONNECTED, 0, 0);//network connection success
While (TRUE)
{
Memset (buff, 0, sizeof (buff));
N=recv (Client, buff, sizeof (buff), 0).//jam, n is number of bytes to copy
If (n==0)//network connection is disconnected, such as turning off the server
{
SendMessage (hWnd WM_NETERROR, 0, 0);
return 0;
}
If (n==SOCKET_ERROR)
{
SendMessage (hWnd WM_NETERROR, 0, 0);
return 0;
}
: : SendMessage (hWnd WM_RECVDATA, (WPARAM) n (LPARAM) buff);
}
return TRUE;
}
CodePudding user response:
Is the best way to the end of the cycle, exit the thread, have a logo, the child thread met mark would quit, all threads are out of the process and then exit the mainIf (theApp. M_mutexExit. IsLocked ())//is quit, interrupt
return;
Can also be forced to kill the thread
M_pThread - & gt; M_bAutoDelete=TRUE;
DWORD ExitCode;
GetExitCodeThread (m_pThread - & gt; M_hThread, & amp; ExitCode);
The TerminateThread (m_pThread - & gt; M_hThread ExitCode);
CodePudding user response:
Forced to kill the thread will cause memory leaksDetected the memory leaks!
Dumping objects - & gt;
F: \ dd \ vctools \ vc7libs \ ship \ atlmfc \ SRC \ MFC \ thrdcore CPP (306) : {369} client block at 0 x00d45dd8, subtype c0, 68 bytes long.
F: \ dd \ vctools \ vc7libs \ ship \ atlmfc \ SRC \ MFC \ dumpcont CPP (23) : atlTraceGeneral - a CWinThread object at $00 d45dd8, 68 bytes long
I set up a global symbol, will sign on to close the main window is set to true, in the while judging marks that we will return to true, but debugging flag bits set a success, but don't enter into the child thread go directly out of the program, is a memory leak
CodePudding user response:
Close the socket.
CodePudding user response: