![]() |
OnSocketReceive() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
| Protected Function |
Declared in: DNSTCPSocket.h |
Declaration
virtual BOOL OnSocketReceive(
int iErrorCode);
Function Body
try
{
//Check if there's no error
if (!iErrorCode)
{
//Receive the data
char* pBuffer;
pBuffer=new char[BUFFER_SIZE];
//Do we have fragmentation ?
if (m_iBufferPosition)
//Copy to the buffer
memcpy(pBuffer,
m_pBuffer,
m_iBufferPosition);
//How much data did we receive
int iReceived=0;
//Receive
iReceived=Receive(pBuffer+m_iBufferPosition,
BUFFER_SIZE-m_iBufferPosition);
//If every thing was OK
if (iReceived==CSpoofBase::GetErrorCode())
{
//Inform of an error
m_pDNSSocket->SocketError(GetSystemLastError());
//Delete the data
delete [] pBuffer;
//No frags
m_iBufferPosition=0;
//Done
return TRUE;
}
//Fix the frags
iReceived+=m_iBufferPosition;
m_iBufferPosition=0;
//Check for frags
int iPosition;
iPosition=0;
BOOL bQuit;
bQuit=FALSE;
//Start
while (!bQuit)
{
//Get the frags
unsigned short usFragSize;
usFragSize=(((unsigned short)pBuffer[iPosition]) << 8) +
(unsigned char)pBuffer[iPosition+1]+2;
//Do we have enough ?
if (iPosition+usFragSize>iReceived)
bQuit=TRUE;
else if ((iPosition+usFragSize)==iReceived)
{
//Set the new size
iPosition+=usFragSize;
//Quit
bQuit=TRUE;
}
else
iPosition+=usFragSize;
}
//Do we have a frag
if (iPosition<iReceived)
{
//Calculate the frag size
m_iBufferPosition=iReceived-iPosition;
//Copy the frag
memcpy(m_pBuffer,
pBuffer+iPosition,
m_iBufferPosition);
//Fix the receive size
iReceived-=m_iBufferPosition;
}
//Do we have the data
if (iReceived)
//Inform our father
m_pDNSSocket->SocketReceive(pBuffer,
iReceived,
TRUE);
}
else
//Inform about the error
m_pDNSSocket->SocketError(iErrorCode);
//Always return true
return TRUE;
}
ERROR_HANDLER_RETURN("OnSocketReceive",TRUE)
See Also
This web site was generated
using Surveyor V4.50.811.1. Click
here
for more information. |
Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003. |