--- innwebd/outd.cpp 2004/07/03 05:30:04 1.2 +++ innwebd/outd.cpp 2008/04/11 17:14:49 1.9 @@ -1,14 +1,10 @@ /*******************************************************/ /* */ -/* LeafOK Innd */ -/* Copyright (C) LeafOK.com, 2003-2004 */ +/* LeafOK Innbbsd */ /* */ -/* Programmed by Leaf */ -/* E-mail:leaf@leafok.com QQ:6049044 */ +/* Copyright (C) LeafOK.com, 2003-2008 */ /* */ -/* http://bbs.leafok.com */ -/* http://bbs.leafok.net */ -/* http://bbs.fenglin.info */ +/* http://www.leafok.com */ /* */ /*******************************************************/ @@ -39,32 +35,41 @@ int outd::work() this->running = true; - this->thread_terminate = false; + this->thread_terminate = false; - while(!this->IsShutdown()) + while(!this->IsShutdown()) + { + this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); + + if (t_count >= 600 && base_active::uThreadCount == 0) { - if (t_count >= 600 && base_active::uThreadCount == 0) - { - p = new base_active(); - p->configure(this->innd_id,this->innd_name,this->innd_server,this->innd_uid,this->w_address,this->w_port,this->w_conn_str); + p = new base_active(); + p->configure(this->innd_id,this->innd_name,this->innd_server,this->innd_uid,this->w_address,this->w_port,this->w_conn_str); - if (hThreadCurrent = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base_active::SendThread,(LPVOID)p,0,&ulThreadId)) - { - base_active::uThreadCount++; - syslog << logfile::log_head << "Create send thread ... OK" << endl; - } - else - { - delete(p); - syslog << logfile::log_head << "Create send thread ... Failed" << endl; - } - t_count = 0; + if (hThreadCurrent = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base_active::SendThread,(LPVOID)p,0,&ulThreadId)) + { + base_active::uThreadCount++; + CloseHandle(hThreadCurrent); +// syslog << logfile::log_head << "Create send thread ... OK" << endl; + } + else + { + delete(p); + syslog << logfile::log_head << "Create send thread ... Failed" << endl; } - Sleep(100); - t_count++; + t_count = 0; + } + Sleep(100); + t_count++; - //Terminate if timeout(5 minutes) or stopped - if ((t_count >= 3000 || this->thread_terminate) && base_active::uThreadCount > 0) + //Terminate if timeout(5 minutes) or stopped + if ((t_count >= 3000 || this->thread_terminate) && base_active::uThreadCount > 0) + { + if ((hThreadCurrent = OpenThread(THREAD_TERMINATE,FALSE,ulThreadId)) == NULL) + { + syslog << logfile::log_head << "Get thread handle error in outd::work()" << endl; + } + else { if (TerminateThread(hThreadCurrent,-1)) { @@ -74,9 +79,11 @@ int outd::work() { syslog << logfile::log_head << "Terminate send thread ... Failed" << endl; } - base_active::uThreadCount--; + CloseHandle(hThreadCurrent); } + base_active::uThreadCount--; } + } this->running = false;