m_SocketID should avoid 0 or -1
Brought to you by:
lilyco
when udt alloc a socket handle:
CGuard::enterCS(m_IDLock);
ns->m_SocketID = -- m_SocketID;
CGuard::leaveCS(m_IDLock);
the "ns->m_SocketID" maybe 0 or -1, so "socket" or "accept" maybe return as an error.
I changed codes as fllowing:
CGuard::enterCS(m_IDLock);
if ( m_SocketID <= 8 )
{
srand((unsigned int)CTimer::getTime());
double dRand = double(rand()) / RAND_MAX;
if ( dRand <= 0.5 )
{
dRand += 0.5;
}
m_SocketID = 1 + (int)((1 << 30) * dRand);
}
ns->m_SocketID = -- m_SocketID;
CGuard::leaveCS(m_IDLock);