This commit is contained in:
zhouhuang 2024-12-30 12:44:42 +08:00
parent f1bf409981
commit 4630e0f642

View File

@ -240,7 +240,10 @@ bool Socket::Select(timeval* timeout)
{
/* prepare socket set for select() */
if (!IsValid()) {
LOG_ERROR("Socket is invalid: " << std::dec << m_Socket);
return false;
}
if (m_Socket < 0 || m_Socket >= FD_SETSIZE) {
LOG_ERROR("received a non valid socket (" << m_Socket << "), unable to add to the set");
return false;
}
fd_set readSockets;
@ -251,6 +254,7 @@ bool Socket::Select(timeval* timeout)
const int state = NATIVE_SELECT(m_Socket + 1, &readSockets, nullptr, nullptr, timeout);
if (0 == state) {
LOG_ERROR("Socket select() timeout.");
return false;
//throw TimeoutEx("select() timeout");
}
@ -258,6 +262,7 @@ bool Socket::Select(timeval* timeout)
if (m_LastError == WSAENOTSOCK) {
//throw std::runtime_error("connection closed");
Shutdown();
return false;
}
/* and check if socket was correct */
@ -266,6 +271,10 @@ bool Socket::Select(timeval* timeout)
return false;
}
if (m_Socket < 0 || m_Socket >= FD_SETSIZE) {
LOG_ERROR("received a non valid socket (" << m_Socket << "), unable to add to the set");
return false;
}
if (!FD_ISSET(m_Socket, &readSockets))
{
return false;