本文整理汇总了C++中CSession::GetSocket方法的典型用法代码示例。如果您正苦于以下问题:C++ CSession::GetSocket方法的具体用法?C++ CSession::GetSocket怎么用?C++ CSession::GetSocket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSession
的用法示例。
在下文中一共展示了CSession::GetSocket方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: int
void Dispatch( double timeout ){
m_endTime = (timeout < 0.0) ? -1.0 : (GetTime() + timeout);
m_doClear = false;
m_inWork = true;
while( SESSIONS::Size() > 0 )
{
fd_set inFd, outFd, excFd;
FD_ZERO(&inFd);
FD_ZERO(&outFd);
FD_ZERO(&excFd);
int maxFd = -1;
CSession* pSession = NULL;
pSession = SESSIONS::Begin();
while( SESSIONS::hasNext() )
{
int fd = int(pSession->GetSocket().GetHandle());
if( pSession->Mask() & ReadableEvent )
FD_SET(fd, &inFd);
if( pSession->Mask() & WritableEvent )
FD_SET(fd, &outFd);
if( pSession->Mask() & Exception )
FD_SET(fd, &excFd);
if( pSession->Mask() && (fd > maxFd) )
maxFd = fd;
pSession = SESSIONS::Next();
}
int nEvents;
if( timeout < 0.0 )
{
nEvents = select(maxFd+1, &inFd, &outFd, &excFd, NULL);
}
else
{
struct timeval tv;
tv.tv_sec = (int)floor( timeout );
tv.tv_usec = (int)floor( 1000000.0 * (timeout - floor(timeout)) ) % 1000000;
nEvents = select(maxFd+1, &inFd, &outFd, &excFd, &tv);
}
if( 0 > nEvents )
{
m_inWork = false;
return;
}
pSession = SESSIONS::Begin();
while( SESSIONS::hasNext() )
{
int fd = int(pSession->GetSocket().GetHandle());
DWORD dwMask = (DWORD)(-1);
if( fd <= maxFd )
{
if( FD_ISSET(fd, &inFd) )
dwMask &= pSession->HandleEvent( ReadableEvent );
if( FD_ISSET(fd, &outFd) )
dwMask &= pSession->HandleEvent( WritableEvent );
if( FD_ISSET(fd, &excFd) )
dwMask &= pSession->HandleEvent( Exception );
if( !dwMask )
{
SESSIONS::Delete( *pSession );
}
else
{
pSession->Mask( dwMask );
}
}
pSession = SESSIONS::Next();
}
//
if( m_doClear )
{
/*
SessionList closeList = m_SessionList;
m_SessionList.clear();
SessionList::iterator it = closeList.begin();
for( ; it!=closeList.end(); it++ ){
it->GetSocket().Close();
}
*/
SESSIONS::DeleteAll();
//.........这里部分代码省略.........