示例#1
0
void SyncHandler::ProcessAcceptedSessionList()
{
	SESSION_LIST_ITER 	it;
	Session 		*pSession;
	
	m_pAcceptedSessionList->Lock();
	m_pTemplateList->splice( *m_pAcceptedSessionList );
	m_pAcceptedSessionList->Unlock();

	SESSION_LIST		activeList;
	while( !m_pTemplateList->empty() ) 
	{
		pSession = m_pTemplateList->pop_front();
		if (m_numActiveSessions >= m_dwMaxAcceptSession) {
			printf("Connection full! no available accept socket! \n");
			FreeSession(pSession);
			continue;
		}
		
		if (!AddEpollEvent(pSession)) {
			FreeSession(pSession);
			continue;
		}
		
		NetworkObject * pNet = m_fnCreateAcceptedObject();
		assert(pNet);
		
		pSession->BindNetworkObject(pNet);
		pSession->OnAccept();
		
		++m_numActiveSessions;
		activeList.push_back(pSession);
	}
	
	if ( !activeList.empty() ) {
		m_pActiveSessionList->Lock();
		m_pActiveSessionList->splice( activeList );
		m_pActiveSessionList->Unlock();
	}
}