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

View File

@ -240,9 +240,12 @@ bool Socket::Select(timeval* timeout)
{ {
/* prepare socket set for select() */ /* prepare socket set for select() */
if (!IsValid()) { if (!IsValid()) {
LOG_ERROR("Socket is invalid: " << std::dec << m_Socket);
return false; 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; fd_set readSockets;
FD_ZERO(&readSockets); FD_ZERO(&readSockets);
FD_SET(m_Socket, &readSockets); FD_SET(m_Socket, &readSockets);
@ -251,6 +254,7 @@ bool Socket::Select(timeval* timeout)
const int state = NATIVE_SELECT(m_Socket + 1, &readSockets, nullptr, nullptr, timeout); const int state = NATIVE_SELECT(m_Socket + 1, &readSockets, nullptr, nullptr, timeout);
if (0 == state) { if (0 == state) {
LOG_ERROR("Socket select() timeout."); LOG_ERROR("Socket select() timeout.");
return false;
//throw TimeoutEx("select() timeout"); //throw TimeoutEx("select() timeout");
} }
@ -258,6 +262,7 @@ bool Socket::Select(timeval* timeout)
if (m_LastError == WSAENOTSOCK) { if (m_LastError == WSAENOTSOCK) {
//throw std::runtime_error("connection closed"); //throw std::runtime_error("connection closed");
Shutdown(); Shutdown();
return false;
} }
/* and check if socket was correct */ /* and check if socket was correct */
@ -266,7 +271,11 @@ bool Socket::Select(timeval* timeout)
return false; return false;
} }
if(!FD_ISSET(m_Socket, &readSockets)) 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; return false;
} }