📄 timeoutthread.cpp
字号:
//--------------------------------// coder Cai jianyu,Yuan Zhijian,Meng Qing// begin 2002// v1 2003-01// v2 2003-08-10 move all multithread code to the same class//--------------------------------#include <TimeOutThread.h>#include <algorithm>#include <DataRecovery_impl.h>#ifdef HAS_DEBUG_LEVEL#include "LogClient.h"extern LogClient * g_pLogWriter;#endifCTimeOutThread::CTimeOutThread(long lTimeOut, long lInterval){ DRList.clear(); m_lTimeOut = lTimeOut; m_lInterval = lInterval;}CTimeOutThread::~CTimeOutThread(){ DRList.clear();}//如果有客户端调用,将调用对象加入到超时队列中void CTimeOutThread::addNode(const char * ipport, DataRecovery_impl* theDR){ MultiSync; Elem_T e; e.ipport = ipport; e.pDR = theDR; DRList.push_back(e);}//客户端异常退出时释放资源void CTimeOutThread::delNodebyIp(const char * ipport){ MultiSync; list<Elem_T>::iterator pos; for (pos = DRList.begin(); pos != DRList.end();) { if ( compareIPPORT(*pos, ipport) ) { list<Elem_T>::iterator old = pos++; //CORBA::String_var str = (*old).pDR->getUserID(); //RESULTDSTROY(str.in(),(*old).ipport.c_str(), "quit without invoke destroy") //(*old).pDR->destroyInner(); DRList.erase(old); cout<<"client quit abnormally"<<endl; } else ++pos; }}void CTimeOutThread::delNodebyPointer(DataRecovery_impl* theDR){ MultiSync; list<Elem_T>::iterator pos; for (pos = DRList.begin(); pos != DRList.end();) { if ( comparepDR(*pos, theDR) ) { list<Elem_T>::iterator old = pos++; //CORBA::String_var str = (*old).pDR->getUserID(); //RESULTDSTROY(str.in(),(*old).ipport.c_str(), "quit by invoke destroy") DRList.erase(old); } else ++pos; }}// 判断是否有超时的结果集bool CTimeOutThread::bTimeOut(DataRecovery_impl* theDR){ curr_int = time(0); return theDR->isTimeOut(curr_int);}//超时释放void CTimeOutThread::DelNodeInner(){ MultiSync; list<Elem_T>::iterator pos; for (pos = DRList.begin(); pos != DRList.end();) { DataRecovery_impl* theDR = (*pos).pDR; if (bTimeOut(theDR)) { list<Elem_T>::iterator old = pos++; //CORBA::String_var str = (*old).pDR->getUserID(); //RESULTDSTROY(str.in(),(*old).ipport.c_str(), "quit by timeout") //theDR->destroyInner(); DRList.erase(old); } else ++pos; }}//原来的时间判断函数有问题,在一个长时间的操作之后会判断错误,bTimeOut(),现已经修改//baixiaobo , 20040910// 循环检查结果集列表中是否有超时的结果集对象void CTimeOutThread::run(){// cout << "m_lInterval = " << m_lInterval << endl; for( ; ; ) { //thetime = time(0); //curr_time = localtime(&thetime); //curr_int = curr_time->tm_hour*3600 + curr_time->tm_min*60 + curr_time->tm_sec ; try { DelNodeInner(); } catch(CORBA::Exception& e) { cout << "error in delete timeout IResult" <<endl; cout << e <<endl; } //cout << "int timeout "<<m_lInterval<<endl;#ifdef __UNIX__ sleep(m_lInterval);#endif#ifdef _WIN32 Sleep(m_lInterval);#endif }}bool CTimeOutThread::IsNil(){// cout << "DRList.size() = " << DRList.size() << endl; return DRList.size() == 0;}void CTimeOutThread::ReleaseAll(){ MultiSync; //for (int i=0; i<DRList.size(); i++) //{// cout << "DRList.size() = " << DRList.size() << endl; // DRList[i]->destroyInner(); //} list<Elem_T>::iterator pos;// for (pos = DRList.begin(); pos != DRList.end(); ++pos)// {// //(*pos).pDR->destroyInner();// } DRList.clear();// cout << "out ReleaseAll" << endl;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -