Home > Software engineering >  [for] the socket -> close () when thrown exception!
[for] the socket -> close () when thrown exception!

Time:10-11

Hello, everyone, for the first time to Windows programming, run into a tricky problem recently, make uncertain, online etc. Your kind help!
[background] a member of the socket is a thread, the thread of the destructor, close the socket, delete the socket
[the original code logic]
1. The thread received killThread SetEvent (m_killevent) events, then enter the InitInstance - & gt; ExitInstance, thus the end of the thread,
2. And then other call, will call the delete pthread threads to the destructor, then close the socket, delete the socket,
[now code logic]
1. The thread to read message processing mode, and received killThread KILL_THREAD news is now sent PreTranslateMessage, after it received, will invoke the API: ExitThread.
2. The other call, will call the delete pthread threads to the destructor, then close the socket, delete the socket, these haven't changed, or the original logic,
[question] code instead of logic, now close socket, throw exceptions, closed to determine whether a socket is NULL, not NULL, just shut down, after the delete socket, socket - & gt; Close () when abnormal,
[for]
1. The socket - & gt; Throw exceptions, close with CException class didn't catch exceptions, which interface to capture anomalies can call? See the specific error types,
2. The socket - & gt; The close commented out, also not line, can be in the delete the socket exceptions,
3. ExitThread this API interface is wrong? What can call interface? Then other call point or invoke delete pthread unchanged,
4. According to the logic of the code, now ExitThread - & gt; Delete the pthread wrong?
5. What is the positioning means?

CodePudding user response:

PS:
In the code to invoke the delete two pthread place, only a place to delete the inside of the pthread socket - & gt; There is something wrong with the close, another problem,

CodePudding user response:

PS:
InitInstance PreTranslateMessage instead:
1. Because there is a thread, I want to post a message to the thread, the thread in order to receives the message, so I changed the interface to PreTranslateMessage

CodePudding user response:

Multiple Threads in the User Interface of http://msdn.microsoft.com/zh-cn/library/ms810439.aspx

"Windows core programming"

CodePudding user response:

Message received, but haven't execute close the Socket - & gt; Close(); The main thread to exit, then the child thread also dropped out, cause a memory leak, so need Waitforsigleobject function waiting Socket were closed, and then the child thread exit.

CodePudding user response:

The socket - & gt; Debugging and running, the close setting a breakpoint, the suspicions of the delete many times

CodePudding user response:

reference 5 floor lishunihaoa reply:
message received, but haven't perform closed Socket - & gt; Close(); The main thread to exit, then the child thread is pulled out, causing a memory leak, so need Waitforsigleobject function waiting Socket were closed, and then the child thread exits,


The elder brothers, can say detailed point? The main thread can't quit? The main thread should not have been running?

CodePudding user response:

refer to 6th floor zgl7903 response:
socket - & gt; Debugging and running, the close setting a breakpoint, doubts exist multiple delete

Have set a breakpoint, ran to the place of VC directly abnormalities, error: unhandled exception in the Exchange. Exe (MFCN42D. DLL) : 0 xc00000005: Access Violation.

CodePudding user response:

In addition:
WAIT_OBJECT_0==WaitForSingleObject (m_hThread, 0)

This is said I have any signal thread?

CodePudding user response:

references 9 f wan198809 response:
also:
WAIT_OBJECT_0==WaitForSingleObject (m_hThread, 0)

This is said I have any signal thread?



WAIT_OBJECT_0 0 x00000000: the specified object is signaled state
WAIT_TIMEOUT 0 x00000102: wait for timeout
WAIT_FAILED 0 XFFFFFFFF: there is an error, the error code can be obtained through the GetLastError
  • Related