Re: CAsyncSocket Close()
On Oct 13, 10:37 pm, mfc <mfcp...@googlemail.com> wrote:
On 13 Okt., 20:39, Joseph M. Newcomer <newco...@flounder.com> wrote:
It has been such a long time since I wrote the code, I no longer recall=
, but killing the
thread is not going to close the socket unless the handler for UWM_TERM=
explicit code to close the socket. So see if it does. If it doesn=
't, you will have to
I`ve installed the handler for the UWM_TERM_THREAD message - and the
socket will be closed. But if I allocate some heap space in the socket
class, this space won`t be deleted if the UWM_TERM_THREAD message
I`m not sure if I really need to install CSingleLock.... Maybe it`s
quite simple to check the return value of the PostThreadMessage to
this socket class, and if the socket is no longer available the return
value is not zero -> so I can delete the heap space...
typedef std::auto_ptr< std::map<CString, CString> > PData;
PData pdata(new (std::map<CString, CString>));
------ socket thread will be deleted -----
if(PostThreadMessage(threadid, UWM_SEND_TO_SOC, data, 0))
I am now not sure what is your actual problem. I think what you are
* allocate X (doesn't matter what X is) on the heap (thread 1)
* post message to a thread 2 (or, better, to a window
residing in thread 2) with a pointer to X
* handle said message
* delete X.
As Joe said, in this scenario, up until PostMessage, owner of X on the
heap is thread 1. Once PostMessage "received" X, owner of X is thread
2 (consequence: code running in thread 2 must delete X).
I see two possible issues (both resulting in memory leaks):
1. PostMessage fails; this is easy to solve: if (!PostMessage(...))
2. messages have been posted, but not delivered to thread 2 (and
thread 2 knows that thread 1 is gone, and will not treat any more of
messages from thread 1); this is a bit tricky, but still easy: either
you make sure to flush^^^ all messages that contain X on heap before
cleaning all up, either you use shared space and synchronization to
put/get data in^^^^^^.
^^^ here, you could try GetMessage with wMsgFilterMin and
of your choosing.
^^^^^^ you need e.g. some container and a critical section for that.