Пример #1
0
void CClientProxy::RouteMessage()
{
	try{
		double tmLastTick = GetMilliTime();
		while( true ){
			TIMEVAL tmout;
			tmout.tv_sec = TMMS_KEEPALIVE/1000;
			tmout.tv_usec = 0;

			fd_set rfds;
			FD_ZERO( &rfds );
			FD_SET( m_sock, &rfds );
			int nRet = Select( m_sock+1, &rfds, NULL, NULL, &tmout );

			double tmNow = GetMilliTime();
			if( nRet==0 || tmNow-tmLastTick>TMMS_KEEPALIVE ){	//time out, send the keep alive message
				KeepAlive();
				tmLastTick = tmNow;
			}
			if( nRet!=0 && FD_ISSET(m_sock, &rfds) ){
				CMessageBase* pMsg = RecvMessage<CMessageBase>( m_sock );
				if( pMsg==NULL )break;	//sock shutdown.
				CClientSession* pSession = GetSession( pMsg->GetDstAddr() );
				if( pSession ){
					pSession->PostMessage( pMsg );
				}else{
					CMessageTrash trash(pMsg);
				}
			}
		}
	}catch( CSockException* e ){
		cout<<"Client Proxy Sock:"<<e->what()<<endl;
		e->Delete();
	}

	ShutdownSessions();
	closesocket( m_sock );
}
Пример #2
0
error_obj::error_obj() {
	millitimestamp = GetMilliTime();
	timestamp = time(nullptr);
	msg << gr_strftime(string_format("[%%F %%T.%03d %%z] Error: ", millitimestamp).c_str(), localtime(&timestamp), timestamp, true);
}