| 1 |
/*******************************************************/
|
| 2 |
/* */
|
| 3 |
/* LeafOK Innbbsd */
|
| 4 |
/* Copyright (C) LeafOK.com, 2003-2004 */
|
| 5 |
/* */
|
| 6 |
/* Programmed by Leaf */
|
| 7 |
/* E-mail:leaflet@leafok.com QQ:6049044 */
|
| 8 |
/* */
|
| 9 |
/* http://bbs.leafok.com */
|
| 10 |
/* http://bbs.leafok.net */
|
| 11 |
/* http://bbs.fenglin.info */
|
| 12 |
/* */
|
| 13 |
/*******************************************************/
|
| 14 |
|
| 15 |
#include "StdAfx.h"
|
| 16 |
#include ".\outd.h"
|
| 17 |
|
| 18 |
using namespace std;
|
| 19 |
|
| 20 |
bool outd::thread_terminate = true;
|
| 21 |
|
| 22 |
outd::outd(void)
|
| 23 |
{
|
| 24 |
}
|
| 25 |
|
| 26 |
outd::~outd(void)
|
| 27 |
{
|
| 28 |
}
|
| 29 |
|
| 30 |
int outd::work()
|
| 31 |
{
|
| 32 |
HANDLE hThreadCurrent;
|
| 33 |
ULONG ulThreadId;
|
| 34 |
base_active* p;
|
| 35 |
int t_count = 0;
|
| 36 |
|
| 37 |
if (this->running)
|
| 38 |
return 1;
|
| 39 |
|
| 40 |
this->running = true;
|
| 41 |
|
| 42 |
this->thread_terminate = false;
|
| 43 |
|
| 44 |
while(!this->IsShutdown())
|
| 45 |
{
|
| 46 |
this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING);
|
| 47 |
|
| 48 |
if (t_count >= 600 && base_active::uThreadCount == 0)
|
| 49 |
{
|
| 50 |
p = new base_active();
|
| 51 |
p->configure(this->innd_id,this->innd_name,this->innd_server,this->innd_uid,this->w_address,this->w_port,this->w_conn_str);
|
| 52 |
|
| 53 |
if (hThreadCurrent = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base_active::SendThread,(LPVOID)p,0,&ulThreadId))
|
| 54 |
{
|
| 55 |
base_active::uThreadCount++;
|
| 56 |
CloseHandle(hThreadCurrent);
|
| 57 |
syslog << logfile::log_head << "Create send thread ... OK" << endl;
|
| 58 |
}
|
| 59 |
else
|
| 60 |
{
|
| 61 |
delete(p);
|
| 62 |
syslog << logfile::log_head << "Create send thread ... Failed" << endl;
|
| 63 |
}
|
| 64 |
t_count = 0;
|
| 65 |
}
|
| 66 |
Sleep(100);
|
| 67 |
t_count++;
|
| 68 |
|
| 69 |
//Terminate if timeout(5 minutes) or stopped
|
| 70 |
if ((t_count >= 3000 || this->thread_terminate) && base_active::uThreadCount > 0)
|
| 71 |
{
|
| 72 |
if (TerminateThread(hThreadCurrent,-1))
|
| 73 |
{
|
| 74 |
syslog << logfile::log_head << "Terminate send thread ... OK" << endl;
|
| 75 |
}
|
| 76 |
else
|
| 77 |
{
|
| 78 |
syslog << logfile::log_head << "Terminate send thread ... Failed" << endl;
|
| 79 |
}
|
| 80 |
base_active::uThreadCount--;
|
| 81 |
}
|
| 82 |
}
|
| 83 |
|
| 84 |
this->running = false;
|
| 85 |
|
| 86 |
return 0;
|
| 87 |
}
|
| 88 |
|
| 89 |
int outd::Shutdown(void)
|
| 90 |
{
|
| 91 |
if (this->thread_terminate)
|
| 92 |
return 1;
|
| 93 |
|
| 94 |
this->thread_terminate = true;
|
| 95 |
|
| 96 |
return 0;
|
| 97 |
}
|
| 98 |
|
| 99 |
bool outd::IsShutdown(void)
|
| 100 |
{
|
| 101 |
return this->thread_terminate;
|
| 102 |
}
|
| 103 |
|
| 104 |
int outd::Startup(void)
|
| 105 |
{
|
| 106 |
if (!this->thread_terminate)
|
| 107 |
return 1;
|
| 108 |
|
| 109 |
this->thread_terminate = false;
|
| 110 |
|
| 111 |
return 0;
|
| 112 |
}
|
| 113 |
|
| 114 |
int outd::w_call(void)
|
| 115 |
{
|
| 116 |
this->work();
|
| 117 |
return 0;
|
| 118 |
}
|