--- innwebd/base.cpp 2004/07/02 11:22:07 1.1 +++ innwebd/base.cpp 2004/07/04 06:45:23 1.4 @@ -1,10 +1,10 @@ /*******************************************************/ /* */ -/* LeafOK Innd */ +/* LeafOK Innbbsd */ /* Copyright (C) LeafOK.com, 2003-2004 */ /* */ /* Programmed by Leaf */ -/* E-mail:leaf@leafok.com QQ:6049044 */ +/* E-mail:leaflet@leafok.com QQ:6049044 */ /* */ /* http://bbs.leafok.com */ /* http://bbs.leafok.net */ @@ -21,7 +21,10 @@ using namespace std; base::base(void) -: innd_uid(0) +: p_ParentThread(NULL) +, p_ThreadPool(NULL) +, ulMainThreadId(0) +, innd_uid(0) , isConnected(false) , running(false) { @@ -29,6 +32,8 @@ base::base(void) base::~base(void) { + if (this->GetThreadPool() != NULL) + delete (this->GetThreadPool()); } int base::s_exec(const char* in_str, CString& out_str, const char* end_str) @@ -280,7 +285,7 @@ int base::bbs_post(const CString& head, RS.GetFieldValue("UID",dbVar,SQL_C_SLONG); sql.Format("insert into bbs_msg(fromUID,toUID,ntent,send_dt,send_ip)" " valulues(%ld,%ld,'%s',now(),'%s')", - this->innd_uid,dbVar.m_lVal,addslashes(msg_connt),ththis->hostaddr); + this->innd_uid,dbVar.m_lVal,addslashes(msg_content),this->hostaddr); this->Db.ExecuteSQL(sql); } } @@ -452,11 +457,6 @@ int base::s_receive(CString& out_str, co return total_read; } -bool base::IsRunning(void) -{ - return this->running; -} - int base::begin(void) { ULONG ulThreadId; @@ -496,8 +496,24 @@ DWORD base::Thread(LPVOID pParam) base* p; syslog << logfile::log_head << "Thread started." << endl; + p = (base*)pParam; + + p->ulMainThreadId = GetCurrentThreadId(); + + if (p->GetParentThread()->GetThreadPool()->AddThread(GetCurrentThreadId(), CLOCKS_PER_SEC * 30) != 0) + { + syslog << logfile::log_head << "Register thread ... Failed" << endl; + } + p->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); + p->w_call(); + + if (p->GetParentThread()->GetThreadPool()->RemoveThread(GetCurrentThreadId()) != 0) + { + syslog << logfile::log_head << "Unregister thread ... Failed" << endl; + } + syslog << logfile::log_head << "Thread stopped." << endl; return 0; @@ -537,3 +553,20 @@ int base::Startup(void) { return 0; } + +bool base::IsThreadActive(void) +{ + bool bIsActive = false; + + switch (this->GetParentThread()->GetThreadPool()->GetThreadStatus(this->ulMainThreadId)) + { + case thread_pool::S_WAITING: + case thread_pool::S_WORKING: + bIsActive = true; + break; + default: + bIsActive = false; + } + + return bIsActive; +}