BOOL CTcpServer::IsConnected(CONNID dwConnID) { TSocketObj* pSocketObj = FindSocketObj(dwConnID); if(TSocketObj::IsValid(pSocketObj)) return pSocketObj->HasConnected(); return FALSE; }
BOOL CTcpAgent::GetPendingDataLength(CONNID dwConnID, int& iPending) { TSocketObj* pSocketObj = FindSocketObj(dwConnID); if(TSocketObj::IsValid(pSocketObj)) { iPending = pSocketObj->Pending(); return TRUE; } return FALSE; }
TSocketObj* CTcpServer::GetFreeSocketObj(CONNID dwConnID, SOCKET soClient) { DWORD dwIndex; TSocketObj* pSocketObj = nullptr; if(m_lsFreeSocket.TryLock(&pSocketObj, dwIndex)) { if(::GetTimeGap32(pSocketObj->freeTime) >= m_dwFreeSocketObjLockTime) m_lsFreeSocket.ReleaseLock(nullptr, dwIndex); else { m_lsFreeSocket.ReleaseLock(pSocketObj, dwIndex); pSocketObj = nullptr; } } if(!pSocketObj) pSocketObj = CreateSocketObj(); pSocketObj->Reset(dwConnID, soClient); return pSocketObj; }
TSocketObj* CTcpAgent::GetFreeSocketObj(CONNID dwConnID, SOCKET soClient) { TSocketObj* pSocketObj = nullptr; if(m_lsFreeSocket.size() > 0) { CCriSecLock locallock(m_csFreeSocket); if(m_lsFreeSocket.size() > 0) { pSocketObj = m_lsFreeSocket.front(); if(::GetTimeGap32(pSocketObj->freeTime) >= m_dwFreeSocketObjLockTime) m_lsFreeSocket.pop_front(); else pSocketObj = nullptr; } } if(!pSocketObj) pSocketObj = CreateSocketObj(); pSocketObj->Reset(dwConnID, soClient); return pSocketObj; }