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

Annotation of /innwebd/outd.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Sun Jul 4 22:49:03 2004 UTC (21 years, 8 months ago) by sysadm
Branch: MAIN
Changes since 1.4: +1 -0 lines
Content type: text/x-c++src
CloseHandle after use

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.4 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 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     if (TerminateThread(hThreadCurrent,-1))
73     {
74     syslog << logfile::log_head << "Terminate send thread ... OK" << endl;
75 sysadm 1.1 }
76 sysadm 1.4 else
77 sysadm 1.1 {
78 sysadm 1.4 syslog << logfile::log_head << "Terminate send thread ... Failed" << endl;
79 sysadm 1.1 }
80 sysadm 1.4 base_active::uThreadCount--;
81 sysadm 1.1 }
82 sysadm 1.4 }
83 sysadm 1.1
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     }

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