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

Diff of /innwebd/base_passive.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 by sysadm, Sat Jul 3 08:47:07 2004 UTC Revision 1.3 by sysadm, Sat Jul 3 13:56:04 2004 UTC
# Line 18  Line 18 
18    
19  using namespace std;  using namespace std;
20    
21  UINT base_passive::uThreadCount = 0;  // UINT base_passive::uThreadCount = 0;
22    
23  base_passive::base_passive(void)  base_passive::base_passive(void)
 : p_ParentThread(NULL)  
24  {  {
25  }  }
26    
# Line 103  int base_passive::work() Line 102  int base_passive::work()
102          if (this->load_priv() != 0)          if (this->load_priv() != 0)
103                  return -1;                  return -1;
104    
105            this->p_ThreadPool = new thread_pool(MAX_CLIENT);
106            if (this->p_ThreadPool->GetLastError() != 0)
107            {
108                    return -1;
109            }
110    
111            hThreadCurrent = GetCurrentThread();
112    
113          if (this->s_connect(this->w_address,this->w_port) == 0)          if (this->s_connect(this->w_address,this->w_port) == 0)
114          {          {
115                  this->Startup();                  this->Startup();
# Line 117  int base_passive::work() Line 124  int base_passive::work()
124                                  continue;                                  continue;
125                          }                          }
126                                                    
127                          p->p_ParentThread = this;                          p->SetParentThread(this);
128                          p->configure(this->innd_id,this->innd_name,this->innd_server,this->innd_uid,this->w_address,this->w_port,this->w_conn_str);                          p->configure(this->innd_id,this->innd_name,this->innd_server,this->innd_uid,this->w_address,this->w_port,this->w_conn_str);
129                    
130                          this->running = true;                          this->running = true;
131    
132                            this->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WAITING);
133    
134                          namelen = sizeof(sin);                          namelen = sizeof(sin);
135                          if ((p->s = accept(this->s,(LPSOCKADDR)&sin,&namelen)) == INVALID_SOCKET)                          if ((p->s = accept(this->s,(LPSOCKADDR)&sin,&namelen)) == INVALID_SOCKET)
136                          {                          {
# Line 132  int base_passive::work() Line 141  int base_passive::work()
141                                  return -2;                                  return -2;
142                          }                          }
143    
144                            this->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WORKING);
145    
146                          if (this->IsShutdown())                          if (this->IsShutdown())
147                          {                          {
148                                  break;                                  break;
# Line 157  int base_passive::work() Line 168  int base_passive::work()
168                                  delete(p);                                  delete(p);
169                                  continue;                                  continue;
170                          }                          }
171                          if (base_passive::uThreadCount < MAX_CLIENT)  
172    //                      if (base_passive::uThreadCount < MAX_CLIENT)
173                          if (this->GetThreadPool()->GetThreadCount() < MAX_CLIENT)                          if (this->GetThreadPool()->GetThreadCount() < MAX_CLIENT)
174                          {                          {
175                                  if (hThreadCurrent = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base_passive::AcceptThread,(LPVOID)p,0,&ulThreadId))                                  if (hThreadCurrent = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base_passive::AcceptThread,(LPVOID)p,0,&ulThreadId))
176                                          base_passive::uThreadCount++;  //                                      base_passive::uThreadCount++;
177                                          CloseHandle(hThreadCurrent);                                          CloseHandle(hThreadCurrent);
178                                          syslog << logfile::log_head << "Create accept thread ... OK" << endl;                                          syslog << logfile::log_head << "Create accept thread ... OK" << endl;
179                                  }                                  }
# Line 181  int base_passive::work() Line 193  int base_passive::work()
193                  Sleep(1000*5); // Wait several seconds for all threads to exit                  Sleep(1000*5); // Wait several seconds for all threads to exit
194          }          }
195          this->s_close();          this->s_close();
196            delete(this->p_ThreadPool);
197    
198    
199          this->unload_priv();          this->unload_priv();
200    
# Line 190  int base_passive::work() Line 204  int base_passive::work()
204  }  }
205    
206  DWORD base_passive::AcceptThread(LPVOID pParam)  DWORD base_passive::AcceptThread(LPVOID pParam)
207            HANDLE hThreadCurrent;
208  {  {
209          base_passive* p;          base_passive* p;
210    
211          try          try
212          {          {
213                    hThreadCurrent = GetCurrentThread();
214                    p = (base_passive*)pParam;
215                    if (p->GetParentThread()->GetThreadPool()->AddThread(hThreadCurrent, CLOCKS_PER_SEC * 30) != 0)
216                    if (p->GetParentThread()->GetThreadPool()->AddThread(GetCurrentThreadId(), CLOCKS_PER_SEC * 30) != 0)
217                    {
218                            syslog << logfile::log_head << "Register thread ... Failed" << endl;
219                    p->GetParentThread()->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WORKING);
220                    p->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING);
221    
222                  if (p->db_env_init() == 0)                  if (p->db_env_init() == 0)
223                  {                  {
# Line 203  DWORD base_passive::AcceptThread(LPVOID Line 226  DWORD base_passive::AcceptThread(LPVOID
226                  else                  else
227                  {                  {
228                          syslog << logfile::log_head << "DB_ENV_INIT failed" << endl;                          syslog << logfile::log_head << "DB_ENV_INIT failed" << endl;
229                    }
230                    if (p->GetParentThread()->GetThreadPool()->RemoveThread(hThreadCurrent) != 0)
231                    if (p->GetParentThread()->GetThreadPool()->RemoveThread(GetCurrentThreadId()) != 0)
232                    {
233                            syslog << logfile::log_head << "Unregister thread ... Failed" << endl;
234                    }
235    //              base_passive::uThreadCount--;
236    
                 base_passive::uThreadCount--;  
237                  delete(p);                  delete(p);
238                  syslog << logfile::log_head << "Delete accept thread ... OK" << endl;                  syslog << logfile::log_head << "Delete accept thread ... OK" << endl;
239          }          }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

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