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

Contents of /innwebd/outd.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations)
Fri Apr 11 17:14:49 2008 UTC (17 years, 11 months ago) by sysadm
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +2 -6 lines
Content type: text/x-c++src
Error occurred while calculating annotation data.
Update copyright
Add extra log for exception

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

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