| 409 | |
| 410 | |
| 411 | unsigned __stdcall CGenericServer::ClientThread(LPVOID pParam) |
| 412 | { |
| 413 | NewConnectionTag *pNewConn = (NewConnectionTag*)pParam; |
| 414 | CGenericServer *pGenericServer = pNewConn->pGenericServer; |
| 415 | SOCKET s = pNewConn->s; |
| 416 | |
| 417 | int result; |
| 418 | WSAEVENT EventArray[2]; |
| 419 | WSANETWORKEVENTS NetworkEvents; |
| 420 | |
| 421 | BOOL bResend = FALSE; |
| 422 | WSABUF Buffer; |
| 423 | DWORD NumberOfBytesSent; |
| 424 | DWORD dwBytesSent; |
| 425 | BOOL bKeepAlive = FALSE; |
| 426 | string szRequest; |
| 427 | string szResponse; |
| 428 | |
| 429 | WSAEVENT Event = WSACreateEvent(); |
| 430 | |
| 431 | if(Event == WSA_INVALID_EVENT) |
| 432 | { |
| 433 | pGenericServer->LogMessage(LOGFILENAME, _T("WSACreateEvent(...) failure"), _T("ClientThread"), WSAGetLastError()); |
| 434 | pGenericServer->CleanupThread(NULL, s, pNewConn, GetCurrentThreadId()); |
| 435 | return THREADEXIT_SUCCESS; |
| 436 | } |
| 437 | |
| 438 | result = WSAEventSelect(s, Event, FD_READ | FD_WRITE | FD_CLOSE); |
| 439 | if(result == SOCKET_ERROR) |
| 440 | { |
| 441 | pGenericServer->LogMessage(LOGFILENAME, _T("WSAEventSelect(...) failure"), _T("ClientThread"), WSAGetLastError()); |
| 442 | pGenericServer->CleanupThread(Event, s, pNewConn, GetCurrentThreadId()); |
| 443 | return THREADEXIT_SUCCESS; |
| 444 | } |
| 445 | |
| 446 | EventArray[0] = Event; |
| 447 | EventArray[1] = pGenericServer->ShutdownEvent; |
| 448 | |
| 449 | for(;;) |
| 450 | { |
| 451 | DWORD EventCaused = WSAWaitForMultipleEvents( |
| 452 | 2, |
| 453 | EventArray, |
| 454 | FALSE, |
| 455 | pGenericServer->PersistenceTO ? pGenericServer->PersistenceTO : WSA_INFINITE, |
| 456 | FALSE); |
| 457 | |
| 458 | if(WSA_WAIT_FAILED == EventCaused) |
| 459 | { |
| 460 | pGenericServer->LogMessage(LOGFILENAME, _T("WSAWaitForMultipleEvents(...) failure"), _T("ClientThread"), WSAGetLastError()); |
| 461 | pGenericServer->CleanupThread(Event, s, pNewConn, GetCurrentThreadId()); |
| 462 | return THREADEXIT_SUCCESS; |
| 463 | } |
| 464 | |
| 465 | // |
| 466 | // Check if our Server mission is over or Client established connection, but no request so far |
| 467 | // |
| 468 | if(EventCaused == 1 || EventCaused == WSA_WAIT_TIMEOUT) |
nothing calls this directly
no test coverage detected