本文整理汇总了C++中SocketServer::getMonitor方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketServer::getMonitor方法的具体用法?C++ SocketServer::getMonitor怎么用?C++ SocketServer::getMonitor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketServer
的用法示例。
在下文中一共展示了SocketServer::getMonitor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
bool SocketConnection::read( SocketAcceptor& a, SocketServer& s )
{
std::string msg;
try
{
if ( !m_pSession )
{
struct timeval timeout = { 1, 0 };
fd_set readset = m_fds;
while( !readMessage( msg ) )
{
int result = select( 1 + m_socket, &readset, 0, 0, &timeout );
if( result > 0 )
readFromSocket();
else if( result == 0 )
return false;
else if( result < 0 )
return false;
}
m_pSession = Session::lookupSession( msg, true );
if( !isValidSession() )
{
m_pSession = 0;
if( a.getLog() )
{
a.getLog()->onEvent( "Session not found for incoming message: " + msg );
a.getLog()->onIncoming( msg );
}
}
if( m_pSession )
m_pSession = a.getSession( msg, *this );
if( m_pSession )
m_pSession->next( msg, UtcTimeStamp() );
if( !m_pSession )
{
s.getMonitor().drop( m_socket );
return false;
}
Session::registerSession( m_pSession->getSessionID() );
return true;
}
else
{
readFromSocket();
readMessages( s.getMonitor() );
return true;
}
}
catch ( SocketRecvFailed& e )
{
if( m_pSession )
m_pSession->getLog()->onEvent( e.what() );
s.getMonitor().drop( m_socket );
}
catch ( InvalidMessage& )
{
s.getMonitor().drop( m_socket );
}
return false;
}
示例2: read
bool SocketConnection::read( SocketAcceptor& a, SocketServer& s )
{
std::string msg;
try
{
if ( !m_pSession )
{
int timeout = 1000; // 1000ms = 1 second
struct pollfd pfd = { m_socket, POLLIN | POLLPRI, 0 };
while( !readMessage( msg ) )
{
int result = poll( &pfd, 1, timeout );
if( result > 0 )
readFromSocket();
else if( result == 0 )
return false;
else if( result < 0 )
return false;
}
m_pSession = Session::lookupSession( msg, true );
if( !isValidSession() )
{
m_pSession = 0;
if( a.getLog() )
{
a.getLog()->onEvent( "Session not found for incoming message: " + msg );
a.getLog()->onIncoming( msg );
}
}
if( m_pSession )
m_pSession = a.getSession( msg, *this );
if( m_pSession )
m_pSession->next( msg, UtcTimeStamp() );
if( !m_pSession )
{
s.getMonitor().drop( m_socket );
return false;
}
Session::registerSession( m_pSession->getSessionID() );
return true;
}
else
{
readFromSocket();
readMessages( s.getMonitor() );
return true;
}
}
catch ( SocketRecvFailed& e )
{
if( m_pSession )
m_pSession->getLog()->onEvent( e.what() );
s.getMonitor().drop( m_socket );
}
catch ( InvalidMessage& )
{
s.getMonitor().drop( m_socket );
}
return false;
}