--- innwebd/controld.cpp 2004/07/02 11:41:07 1.2 +++ innwebd/controld.cpp 2004/07/04 08:04:08 1.7 @@ -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 */ @@ -14,7 +14,7 @@ #include "StdAfx.h" #include ".\controld.h" -#include ".\nntp_active.h" +#include ".\base_active.h" #include ".\App_common.h" using namespace std; @@ -42,10 +42,14 @@ int controld::Accept(void) this->s_send(out); while(!this->thread_terminate) { + this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WAITING); + if (this->s_receive(out) == 0) //Connection closed break; out.Trim(); + this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); + syslog << logfile::log_head << "Cmd: " << out << endl; if (sscanf(out,"%20s",temp) ==1) @@ -73,15 +77,15 @@ int controld::Accept(void) if (cmd == "BBSD") { - result = ((controld*)(this->p_ParentThread))->bbsd.begin(); + result = ((controld*)(this->GetParentThread()))->bbsd.begin(); } if (cmd == "INND") { - result = ((controld*)(this->p_ParentThread))->innd.begin(); + result = ((controld*)(this->GetParentThread()))->innd.begin(); } if (cmd == "OUTD") { - result = ((controld*)(this->p_ParentThread))->outd.begin(); + result = ((controld*)(this->GetParentThread()))->outd.begin(); } this->s_send(result == 0 ? "OK" : "Failed"); @@ -115,15 +119,15 @@ int controld::Accept(void) if (cmd == "BBSD") { - result = ((controld*)(this->p_ParentThread))->bbsd.end(); + result = ((controld*)(this->GetParentThread()))->bbsd.end(); } if (cmd == "INND") { - result = ((controld*)(this->p_ParentThread))->innd.end(); + result = ((controld*)(this->GetParentThread()))->innd.end(); } if (cmd == "OUTD") { - result = ((controld*)(this->p_ParentThread))->outd.end(); + result = ((controld*)(this->GetParentThread()))->outd.end(); } this->s_send(result == 0 ? "OK" : "Failed"); @@ -144,13 +148,13 @@ int controld::Accept(void) { if (this->access.control) { - this->_send("Shutting down ... ",falsse); + this->s_send("Shutting down ... ",false); - ((controld*)(this->p_ParentThread))->ShutdownChild(); + ((controld*)(this->GetParentThread()))->ShutdownChild(); this->s_send("OK"); - ((controld*)(this->p_ParentThread))->Shutdown(); + ((controld*)(this->GetParentThread()))->Shutdown(); break; } else @@ -164,8 +168,8 @@ int controld::Accept(void) { this->s_send("Reloading prev_list ... ",false); - ((controld*)(this->p_ParentThread))->unload_priv(); - if (((controld*)(this->p_ParentThread))->load_priv() == 0) + ((controld*)(this->GetParentThread()))->unload_priv(); + if (((controld*)(this->GetParentThread()))->load_priv() == 0) this->s_send("OK"); else this->s_send("Failed"); @@ -175,7 +179,7 @@ int controld::Accept(void) if (cmd == "ACTIVE") { - if (sscanf(out,"%*s %0s",temp) == 1) + if (sscanf(out,"%*s %20s",temp) == 1) cmd = strupr(temp); else cmd = ""; @@ -186,8 +190,11 @@ int controld::Accept(void) if (this->access.control) { this->s_send("201 Entering native mode"); - nntp_active nntpClient; + base_active nntpClient; nntpClient.configure(this->innd_id,this->innd_name,this->innd_server,this->innd_uid,"",0,this->w_conn_str); + + this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WAITING); + if (cmd == "POST") // Get & Post { nntpClient.work(true,false); @@ -196,6 +203,9 @@ int controld::Accept(void) { nntpClient.work(false,true); } + + this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); + this->s_send("Entering passive mode\r\n."); } else @@ -241,7 +251,7 @@ bool controld::IsShutdown(void) int controld::Shutdown(void) { - nntp_active nntpClient; + base_active nntpClient; if (this->thread_terminate) return 1; @@ -448,3 +458,31 @@ void controld::ShutdownChild(void) syslog << logfile::log_head << "End OUTD ... Failed" << endl; } } + +int controld::InitThreadPool(void) +{ + base* p_ParentThread; + + p_ParentThread = new controld(); + + this->SetParentThread(p_ParentThread); + this->bbsd.SetParentThread(p_ParentThread); + this->innd.SetParentThread(p_ParentThread); + this->outd.SetParentThread(p_ParentThread); + + p_ParentThread->SetThreadPool(new thread_pool(TS_MAX_THREAD)); + + if (p_ParentThread->GetThreadPool()->GetLastError() != 0) + { + syslog << logfile::log_head << "Create Thread Pool ... failed" << endl; + } + + return 0; +} + +int controld::CleanupThreadPool(void) +{ + delete(this->GetParentThread()); + + return 0; +}