/[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.4 by sysadm, Sun Jul 4 06:45:23 2004 UTC
# Line 1  Line 1 
1  /*******************************************************/  /*******************************************************/
2  /*                                                     */  /*                                                     */
3  /*  LeafOK Innd                                        */  /*  LeafOK Innbbsd                                     */
4  /*  Copyright (C) LeafOK.com, 2003-2004                */  /*  Copyright (C) LeafOK.com, 2003-2004                */
5  /*                                                     */  /*                                                     */
6  /*  Programmed by Leaf                                 */  /*  Programmed by Leaf                                 */
7  /*  E-mail:leaf@leafok.com  QQ:6049044                 */  /*  E-mail:leaflet@leafok.com  QQ:6049044              */
8  /*                                                     */  /*                                                     */
9  /*  http://bbs.leafok.com                              */  /*  http://bbs.leafok.com                              */
10  /*  http://bbs.leafok.net                              */  /*  http://bbs.leafok.net                              */
# 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->SetThreadPool(new thread_pool(MAX_CLIENT));
106            if (this->p_ThreadPool->GetLastError() != 0)
107            {
108                    return -1;
109            }
110    
111          if (this->s_connect(this->w_address,this->w_port) == 0)          if (this->s_connect(this->w_address,this->w_port) == 0)
112          {          {
113                  this->Startup();                  this->Startup();
# Line 117  int base_passive::work() Line 122  int base_passive::work()
122                                  continue;                                  continue;
123                          }                          }
124                                                    
125                          p->p_ParentThread = this;                          p->SetParentThread(this);
126                          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);
127                    
128                          this->running = true;                          this->running = true;
129    
130                            this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WAITING);
131    
132                          namelen = sizeof(sin);                          namelen = sizeof(sin);
133                          if ((p->s = accept(this->s,(LPSOCKADDR)&sin,&namelen)) == INVALID_SOCKET)                          if ((p->s = accept(this->s,(LPSOCKADDR)&sin,&namelen)) == INVALID_SOCKET)
134                          {                          {
# Line 137  int base_passive::work() Line 144  int base_passive::work()
144                                  break;                                  break;
145                          }                          }
146    
147                            this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),tread_pool::S_WORKING);
148    
149    
150                          strcpy(p->hostaddr,inet_ntoa(sin.sin_addr));                          strcpy(p->hostaddr,inet_ntoa(sin.sin_addr));
151                          p->port = sin.sin_port;                          p->port = sin.sin_port;
# Line 157  int base_passive::work() Line 166  int base_passive::work()
166                                  delete(p);                                  delete(p);
167                                  continue;                                  continue;
168                          }                          }
169                          if (base_passive::uThreadCount < MAX_CLIENT)  
170    //                      if (base_passive::uThreadCount < MAX_CLIENT)
171                          if (this->GetThreadPool()->GetThreadCount() < MAX_CLIENT)                          if (this->GetThreadPool()->GetThreadCount() < MAX_CLIENT)
172                          {                          {
173                                  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))
174                                          base_passive::uThreadCount++;  //                                      base_passive::uThreadCount++;
175                                          CloseHandle(hThreadCurrent);                                          CloseHandle(hThreadCurrent);
176                                          syslog << logfile::log_head << "Create accept thread ... OK" << endl;                                          syslog << logfile::log_head << "Create accept thread ... OK" << endl;
177                                  }                                  }
# Line 195  DWORD base_passive::AcceptThread(LPVOID Line 205  DWORD base_passive::AcceptThread(LPVOID
205    
206          try          try
207          {          {
208                    p = (base_passive*)pParam;
209    
210                    p->ulMainThreadId = GetCurrentThreadId();
211    
212                    if (p->GetParentThread()->GetThreadPool()->AddThread(GetCurrentThreadId(), CLOCKS_PER_SEC * 30) != 0)
213                    {
214                            syslog << logfile::log_head << "Register thread ... Failed" << endl;
215                    }
216                    p->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING);
217    
218                  if (p->db_env_init() == 0)                  if (p->db_env_init() == 0)
219                  {                  {
# Line 203  DWORD base_passive::AcceptThread(LPVOID Line 222  DWORD base_passive::AcceptThread(LPVOID
222                  else                  else
223                  {                  {
224                          syslog << logfile::log_head << "DB_ENV_INIT failed" << endl;                          syslog << logfile::log_head << "DB_ENV_INIT failed" << endl;
225                    }
226    
227                    if (p->GetParentThread()->GetThreadPool()->RemoveThread(GetCurrentThreadId()) != 0)
228                    {
229                            syslog << logfile::log_head << "Unregister thread ... Failed" << endl;
230                    }
231    //              base_passive::uThreadCount--;
232    
                 base_passive::uThreadCount--;  
233                  delete(p);                  delete(p);
234                  syslog << logfile::log_head << "Delete accept thread ... OK" << endl;                  syslog << logfile::log_head << "Delete accept thread ... OK" << endl;
235          }          }


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

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