|
-
October 17th, 2005, 01:27 AM
#1
Why my server lost data
Can you pls help me why I my server lost data , What should i do in case of Error
Here is my server Code
DWORD WINAPI ServerWorkerThread(LPVOID CompletionPortID)
{
/*-- Notify Starting of server -- */
printf("\nHello Server Started, I am in worker thread! \n");
HANDLE hIocp = (HANDLE) CompletionPortID;
ULONG_PTR *PerHandleKey;
OVERLAPPED *Overlap;
OVERLAPPEDPLUS *OverlapPlus,*newolp;
DWORD dwBytesXfered;
int ret;
char *strData ;
while (1)
{
ret = GetQueuedCompletionStatus(hIocp,&dwBytesXfered,(PULONG_PTR)&PerHandleKey,&Overlap,INFINITE);
if (ret == 0){
continue;
}
OverlapPlus = CONTAINING_RECORD(Overlap, OVERLAPPEDPLUS, Overlapped);
/*--- Process Data According to Operation Code ---*/
switch (OverlapPlus->nOperationCode )
{
case OP_READ:
// Process the data read Repost the read if necessary, reusing the same receive buffer as before
ZeroMemory(&(OverlapPlus->Overlapped),sizeof(OVERLAPPED));
ret = WSARecv(OverlapPlus->sClient,&OverlapPlus->wbuf,1,&OverlapPlus->dwBytes,&OverlapPlus->dwFlags,&OverlapPlus->Overlapped, NULL);
if(0 == OverlapPlus->dwBytes)
continue;
strData = (char*) calloc(OverlapPlus->dwBytes+1,sizeof(char));
strcpy(strData,&OverlapPlus->wbuf.buf[0]);
appendLog(strData);
memset(&OverlapPlus->Overlapped, 0, sizeof(OVERLAPPED));
free(strData);
if (ret == SOCKET_ERROR)
{
ret = WSAGetLastError();
if ( ret != WSA_IO_PENDING)
{
// What should i do in case of Error???
printf("Error occur at WSARecv() : %d", ret);
break;
}
}
break;
case OP_WRITE:
appendLog("WRITE");
// Process the data sent, etc.
break;//…
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|