es=pRecv->pSocket->CAsyncSocket::Receive( pHdr, pRecv->hdrSz))==SOCKET_ERROR)
error=::GetLastError();
else
len=res;
// if closing down, exit thread
if (len==0 || error==WSAECONNRESET || error==WSAECONNABORTED) break;
// read the body???
if (!error && len && pRecv->bodyPos!=-1)
{
int bodyLen=*((short *)pHdr+pRecv->bodyPos);
pBody=new char[bodyLen];
if ((res=pRecv->pSocket->CAsyncSocket::Receive( pBody, bodyLen ))==SOCKET_ERROR)
error=::GetLastError();
else
len+=res;
// if closing down, exit thread
if (len==0 || error==WSAECONNRESET || error==WSAECONNABORTED) break;
}
// put message in queue
pRecv->pQueue->Add(new CWzdMsg(pRecv->id,pHdr,pBody,len,error));
// post message to window to process this new message
pRecv->pWnd->PostMessage(WM_NEW_MESSAGE);
}
// cleanup anything we started
delete []pHdr;
delete []pBody;
// tell somebody we stopped
pRecv->pWnd->SendMessage(WM_DONE_MESSAGE,(WPARAM)pRecv->id,(LPARAM)error);
return 0;
}