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

Annotation of /innwebd/outd.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide 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 sysadm 1.1 /*******************************************************/
2     /* */
3 sysadm 1.4 /* LeafOK Innbbsd */
4 sysadm 1.1 /* Copyright (C) LeafOK.com, 2003-2004 */
5     /* */
6     /* Programmed by Leaf */
7 sysadm 1.4 /* E-mail:leaflet@leafok.com QQ:6049044 */
8 sysadm 1.1 /* */
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 sysadm 1.2 base_active* p;
35 sysadm 1.1 int t_count = 0;
36    
37     if (this->running)
38     return 1;
39    
40     this->running = true;
41    
42 sysadm 1.4 this->thread_terminate = false;
43    
44     while(!this->IsShutdown())
45     {
46     this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING);
47 sysadm 1.1
48 sysadm 1.4 if (t_count >= 600 && base_active::uThreadCount == 0)
49 sysadm 1.1 {
50 sysadm 1.4 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 sysadm 1.3
53 sysadm 1.4 if (hThreadCurrent = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base_active::SendThread,(LPVOID)p,0,&ulThreadId))
54 sysadm 1.1 {
55 sysadm 1.4 base_active::uThreadCount++;
56 sysadm 1.5 CloseHandle(hThreadCurrent);
57 sysadm 1.7 // syslog << logfile::log_head << "Create send thread ... OK" << endl;
58 sysadm 1.4 }
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 sysadm 1.1
69 sysadm 1.4 //Terminate if timeout(5 minutes) or stopped
70     if ((t_count >= 3000 || this->thread_terminate) && base_active::uThreadCount > 0)
71     {
72 sysadm 1.6 if ((hThreadCurrent = OpenThread(THREAD_TERMINATE,FALSE,ulThreadId)) == NULL)
73 sysadm 1.4 {
74 sysadm 1.6 syslog << logfile::log_head << "Get thread handle error in outd::work()" << endl;
75 sysadm 1.1 }
76 sysadm 1.4 else
77 sysadm 1.1 {
78 sysadm 1.6 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 sysadm 1.1 }
88 sysadm 1.4 base_active::uThreadCount--;
89 sysadm 1.1 }
90 sysadm 1.4 }
91 sysadm 1.1
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