--- innwebd/controld.cpp 2004/07/03 13:56:04 1.4 +++ innwebd/controld.cpp 2005/02/26 16:10:25 1.12 @@ -1,10 +1,10 @@ /*******************************************************/ /* */ -/* LeafOK Innd */ -/* Copyright (C) LeafOK.com, 2003-2004 */ +/* LeafOK Innbbsd */ +/* Copyright (C) LeafOK.com, 2003-2005 */ /* */ /* 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 */ @@ -35,23 +35,20 @@ int controld::Accept(void) CString out,cmd; char temp[256]; int result; - HANDLE hThreadCurrent; try { - hThreadCurrent = GetCurrentThread(); - out.Format("200 %s ready.",App_common::GetVersion()); this->s_send(out); while(!this->thread_terminate) { - this->GetParentThread()->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WAITING); + this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WAITING); if (this->s_receive(out) == 0) //Connection closed break; out.Trim(); - this->GetParentThread()->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WORKING); + this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); syslog << logfile::log_head << "Cmd: " << out << endl; @@ -142,16 +139,16 @@ int controld::Accept(void) } else { - this>s_send("501 service"); + this->s_send("501 service"); } - contiinue; + continue; } if (cmd == "SHUTDOWN") { if (this->access.control) { - this->_send("Shutting down ... ",falsse); + this->s_send("Shutting down ... ",false); ((controld*)(this->GetParentThread()))->ShutdownChild(); @@ -182,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 = ""; @@ -195,6 +192,9 @@ int controld::Accept(void) this->s_send("201 Entering native mode"); 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); @@ -203,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 @@ -379,22 +382,6 @@ int controld::load_conf(const char* conf this->innd.configure(innd_id,innd_name,innd_server,innd_uid,innd_address,innd_port,conn_str); this->outd.configure(innd_id,innd_name,innd_server,innd_uid,innd_address,0,conn_str); - base* p_ParentThread; - - p_ParentThread = new base_active(); - - 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; } @@ -439,35 +426,80 @@ void controld::StartupChild(void) void controld::StartupDelay(void) { + syslog << logfile::log_head << "Startup delay for " << + this->startup_delay << " seconds"<< endl; + Sleep(this->startup_delay * 1000); } void controld::ShutdownChild(void) { - if (this->bbsd.end() == 0) - { - syslog << logfile::log_head << "End BBSD ... OK" << endl; - } - else + if (this->bbsd.IsRunning()) { - syslog << logfile::log_head << "End BBSD ... Failed" << endl; + if (this->bbsd.end() == 0) + { + syslog << logfile::log_head << "End BBSD ... OK" << endl; + } + else + { + syslog << logfile::log_head << "End BBSD ... Failed" << endl; + } } - if (this->innd.end() == 0) + if (this->innd.IsRunning()) { - syslog << logfile::log_head << "End INND ... OK" << endl; - } - else - { - syslog << logfile::log_head << "End INND ... Failed" << endl; + if (this->innd.end() == 0) + { + syslog << logfile::log_head << "End INND ... OK" << endl; + } + else + { + syslog << logfile::log_head << "End INND ... Failed" << endl; + } } - if (this->outd.end() == 0) + if (this->outd.IsRunning()) { - syslog << logfile::log_head << "End OUTD ... OK" << endl; + if (this->outd.end() == 0) + { + syslog << logfile::log_head << "End OUTD ... OK" << endl; + } + else + { + syslog << logfile::log_head << "End OUTD ... Failed" << endl; + } } - else +} + +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 << "End OUTD ... Failed" << endl; + syslog << logfile::log_head << "Create Thread Pool ... failed" << endl; } + + return 0; +} + +int controld::CleanupThreadPool(void) +{ + delete(this->GetParentThread()); + + return 0; +} + +bool controld::check_priv(void) +{ + return this->access.control; }