1
0

SocketThreads fixes for crashes reported in FS #272

http://www.mc-server.org/support/index.php?do=details&task_id=272&project=2

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1061 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-11-22 14:10:21 +00:00
parent 51553b9306
commit 8eab4f83b9
3 changed files with 15 additions and 11 deletions

View File

@ -51,12 +51,12 @@ cSocket::xSocket cSocket::GetSocket() const
bool cSocket::IsValid(void) const
bool cSocket::IsValidSocket(cSocket::xSocket a_Socket)
{
#ifdef _WIN32
return (m_Socket != INVALID_SOCKET);
return (a_Socket != INVALID_SOCKET);
#else // _WIN32
return (m_Socket >= 0);
return (a_Socket >= 0);
#endif // else _WIN32
}

View File

@ -19,7 +19,7 @@ public:
cSocket(xSocket a_Socket);
~cSocket();
bool IsValid(void) const;
bool IsValid(void) const { return IsValidSocket(m_Socket); }
void CloseSocket();
operator xSocket() const;
@ -43,12 +43,14 @@ public:
inline static bool IsSocketError( int a_ReturnedValue )
{
#ifdef _WIN32
return (a_ReturnedValue == SOCKET_ERROR || a_ReturnedValue == 0);
#else
return (a_ReturnedValue <= 0);
#endif
#ifdef _WIN32
return (a_ReturnedValue == SOCKET_ERROR || a_ReturnedValue == 0);
#else
return (a_ReturnedValue <= 0);
#endif
}
static bool IsValidSocket(xSocket a_Socket);
struct SockAddr_In
{

View File

@ -577,7 +577,8 @@ void cSocketThreads::cSocketThread::ReadFromSockets(fd_set * a_Read)
cCSLock Lock(m_Parent->m_CS);
for (int i = m_NumSlots - 1; i >= 0; --i)
{
if (!FD_ISSET(m_Slots[i].m_Socket.GetSocket(), a_Read))
cSocket::xSocket Socket = m_Slots[i].m_Socket.GetSocket();
if (!cSocket::IsValidSocket(Socket) || !FD_ISSET(Socket, a_Read))
{
continue;
}
@ -621,7 +622,8 @@ void cSocketThreads::cSocketThread::WriteToSockets(fd_set * a_Write)
cCSLock Lock(m_Parent->m_CS);
for (int i = m_NumSlots - 1; i >= 0; --i)
{
if (!m_Slots[i].m_Socket.IsValid() || !FD_ISSET(m_Slots[i].m_Socket.GetSocket(), a_Write))
cSocket::xSocket Socket = m_Slots[i].m_Socket.GetSocket();
if (!cSocket::IsValidSocket(Socket) || !FD_ISSET(Socket, a_Write))
{
continue;
}