| 460 | |
| 461 | |
| 462 | void cSocketThreads::cSocketThread::ReadFromSockets(fd_set * a_Read) |
| 463 | { |
| 464 | // Read on available sockets: |
| 465 | |
| 466 | // Reset Control socket state: |
| 467 | if (FD_ISSET(m_ControlSocket1.GetSocket(), a_Read)) |
| 468 | { |
| 469 | char Dummy[128]; |
| 470 | m_ControlSocket1.Receive(Dummy, sizeof(Dummy), 0); |
| 471 | } |
| 472 | |
| 473 | // Read from clients: |
| 474 | cCSLock Lock(m_Parent->m_CS); |
| 475 | for (int i = m_NumSlots - 1; i >= 0; --i) |
| 476 | { |
| 477 | cSocket::xSocket Socket = m_Slots[i].m_Socket.GetSocket(); |
| 478 | if (!cSocket::IsValidSocket(Socket) || !FD_ISSET(Socket, a_Read)) |
| 479 | { |
| 480 | continue; |
| 481 | } |
| 482 | char Buffer[1024]; |
| 483 | int Received = m_Slots[i].m_Socket.Receive(Buffer, ARRAYCOUNT(Buffer), 0); |
| 484 | if (Received <= 0) |
| 485 | { |
| 486 | if (cSocket::GetLastError() != cSocket::ErrWouldBlock) |
| 487 | { |
| 488 | // The socket has been closed by the remote party |
| 489 | switch (m_Slots[i].m_State) |
| 490 | { |
| 491 | case sSlot::ssNormal: |
| 492 | { |
| 493 | // Notify the callback that the remote has closed the socket; keep the slot |
| 494 | m_Slots[i].m_Client->SocketClosed(); |
| 495 | m_Slots[i].m_State = sSlot::ssRemoteClosed; |
| 496 | m_Slots[i].m_Socket.CloseSocket(); |
| 497 | break; |
| 498 | } |
| 499 | case sSlot::ssWritingRestOut: |
| 500 | case sSlot::ssShuttingDown: |
| 501 | case sSlot::ssShuttingDown2: |
| 502 | { |
| 503 | // Force-close the socket and remove the slot: |
| 504 | m_Slots[i].m_Socket.CloseSocket(); |
| 505 | m_Slots[i] = m_Slots[--m_NumSlots]; |
| 506 | break; |
| 507 | } |
| 508 | default: |
| 509 | { |
| 510 | LOG("%s: Unexpected socket state: %d (%s)", |
| 511 | __FUNCTION__, m_Slots[i].m_Socket.GetSocket(), m_Slots[i].m_Socket.GetIPString().c_str() |
| 512 | ); |
| 513 | ASSERT(!"Unexpected socket state"); |
| 514 | break; |
| 515 | } |
| 516 | } // switch (m_Slots[i].m_State) |
| 517 | } |
| 518 | } |
| 519 | else |
nothing calls this directly
no test coverage detected