/[LeafOK_CVS]/innwebd/outd.cpp
ViewVC logotype

Contents of /innwebd/outd.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations)
Thu Sep 16 15:41:54 2004 UTC (21 years, 6 months ago) by sysadm
Branch: MAIN
Changes since 1.6: +1 -1 lines
Content type: text/x-c++src
Do not log some unimportant infomation

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 ((hThreadCurrent = OpenThread(THREAD_TERMINATE,FALSE,ulThreadId)) == NULL)
73 {
74 syslog << logfile::log_head << "Get thread handle error in outd::work()" << endl;
75 }
76 else
77 {
78 if (TerminateThread(hThreadCurrent,-1))
79 {
80 syslog << logfile::log_head << "Terminate send thread ... OK" << endl;
81 }
82 else
83 {
84 syslog << logfile::log_head << "Terminate send thread ... Failed" << endl;
85 }
86 CloseHandle(hThreadCurrent);
87 }
88 base_active::uThreadCount--;
89 }
90 }
91
92 this->running = false;
93
94 return 0;
95 }
96
97 int outd::Shutdown(void)
98 {
99 if (this->thread_terminate)
100 return 1;
101
102 this->thread_terminate = true;
103
104 return 0;
105 }
106
107 bool outd::IsShutdown(void)
108 {
109 return this->thread_terminate;
110 }
111
112 int outd::Startup(void)
113 {
114 if (!this->thread_terminate)
115 return 1;
116
117 this->thread_terminate = false;
118
119 return 0;
120 }
121
122 int outd::w_call(void)
123 {
124 this->work();
125 return 0;
126 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1