I have an object that reads from a socket continuously like below:
void CSocketReader::ReadComplete ( )
{
messageProcessor->ResponseReceived ( response );
read ();
}
void CSocketReader::read()
{
socket.read(response);
}
My problem is, depending on the response and on the protocol that I am executing the ResponseReceived method could lead to deletion of the CSocketReader object. When the ResponseReceived method returns the object the this pointer points to would have been deleted ( but for some reason not known to me the this pointer is not NULL even after its deleted!! ). Next the read method executes and the program crashes within read. How can I reliably detect that the method that's been executing on an object has been deleted.
Please help.