--- innwebd/base.cpp 2004/07/03 15:10:23 1.3 +++ innwebd/base.cpp 2004/08/10 19:54:16 1.8 @@ -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 */ @@ -22,6 +22,8 @@ using namespace std; base::base(void) : p_ParentThread(NULL) +, p_ThreadPool(NULL) +, ulMainThreadId(0) , innd_uid(0) , isConnected(false) , running(false) @@ -30,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) @@ -272,15 +276,15 @@ int base::bbs_post(const CString& head, this->Db.ExecuteSQL(sql); rid = this->last_insert_id(); - //Send notification message + //Send notication message - msg_content.Format("[hi]SYS_R_Reply_Article[/hide]" + msg_content.Format("[hide]SYS_R_Reply_Article[/hide]" "有人回复了您所发表的文章,快来[url recommend_view.php?id=%ld" "]看看[/url]《%s》吧!\n",rid,addslashes(subject)); 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')", + sql.Format("insert into bbs_msg(fromUID,toUID,content,send_dt,send_ip)" + " values(%ld,%ld,'%s',now(),'%s')", this->innd_uid,dbVar.m_lVal,addslashes(msg_content),this->hostaddr); this->Db.ExecuteSQL(sql); } @@ -288,7 +292,7 @@ int base::bbs_post(const CString& head, RS.Close(); } - sql.Format("insert delayed into innd_logfile(AID,art_id,msg_id,op) values" + sql.Format("insert delayed into innd_log(AID,art_id,msg_id,op) values" "(%ld,%ld,'%s','I')", aid,art_id,addslashes(msg_id)); this->Db.ExecuteSQL(sql); @@ -300,7 +304,9 @@ int base::bbs_post(const CString& head, } catch(CException* e) { - syslog << logfile::log_head << "Error in bbs_post()" << endl; + char strErrMsg[1024]; + e->GetErrorMessage(strErrMsg,1024); + syslog << logfile::log_head << "Error in bbs_post() [" << strErrMsg << "]" << endl; e->Delete(); return -1; } @@ -385,14 +391,16 @@ int base::bbs_delete(long id) this->Db.ExecuteSQL(sql); } - sql.Format("update innd_logfile set cancel=1 where AID=%ld",id); + sql.Format("update innd_log set cancel=1 where AID=%ld",id); this->Db.ExecuteSQL(sql); } RS.Close(); } catch(CException* e) { - syslog << logfile::log_head << "Getting article error in bbs_delete()" << endl; + char strErrMsg[1024]; + e->GetErrorMessage(strErrMsg,1024); + syslog << logfile::log_head << "Getting article error in bbs_delete() [" << strErrMsg << "]" << endl; e->Delete(); return -1; } @@ -455,14 +463,16 @@ int base::s_receive(CString& out_str, co int base::begin(void) { + HANDLE hThread; ULONG ulThreadId; unsigned int time_wait = 0; if (!this->IsShutdown()) return 1; - if (this->hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base::Thread,(LPVOID)this,0,&ulThreadId)) + if (hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base::Thread,(LPVOID)this,0,&ulThreadId)) { + CloseHandle(hThread); syslog << logfile::log_head << "Create thread ... OK" << endl; } else @@ -489,23 +499,23 @@ int base::begin(void) DWORD base::Thread(LPVOID pParam) { - HANDLE hThreadCurrent; base* p; syslog << logfile::log_head << "Thread started." << endl; p = (base*)pParam; - hThreadCurrent = GetCurrentThread(); - if (p->GetParentThread()->GetThreadPool()->AddThread(hThreadCurrent, CLOCKS_PER_SEC * 30) != 0) + 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(hThreadCurrent,thread_pool::S_WORKING); + p->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); p->w_call(); - if (p->GetParentThread()->GetThreadPool()->RemoveThread(hThreadCurrent) != 0) + if (p->GetParentThread()->GetThreadPool()->RemoveThread(GetCurrentThreadId()) != 0) { syslog << logfile::log_head << "Unregister thread ... Failed" << endl; } @@ -549,3 +559,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; +}