--- innwebd/base_passive.cpp 2004/07/03 05:22:23 1.1 +++ innwebd/base_passive.cpp 2005/02/26 16:10:25 1.9 @@ -1,10 +1,10 @@ /*******************************************************/ /* */ -/* LeafOK Innd */ -/* Copyright (C) LeafOK.com, 2003-2004 */ +/* LeafOK Innbbsd */ +/* Copyright (C) LeafOK.com, 2003-2005 */ /* */ /* Programmed by Leaf */ -/* E-mail:leaf@leafok.com QQ:6049044 */ +/* E-mail:leaflet@leafok.com QQ:6049044 */ /* */ /* http://bbs.leafok.com */ /* http://bbs.leafok.net */ @@ -18,10 +18,9 @@ using namespace std; -UINT base_passive::uThreadCount = 0; +// UINT base_passive::uThreadCount = 0; base_passive::base_passive(void) -: p_ParentThread(NULL) { } @@ -103,6 +102,12 @@ int base_passive::work() if (this->load_priv() != 0) return -1; + this->SetThreadPool(new thread_pool(MAX_CLIENT)); + if (this->p_ThreadPool->GetLastError() != 0) + { + return -1; + } + if (this->s_connect(this->w_address,this->w_port) == 0) { this->Startup(); @@ -117,11 +122,13 @@ int base_passive::work() continue; } - p->p_ParentThread = this; + p->SetParentThread(this); p->configure(this->innd_id,this->innd_name,this->innd_server,this->innd_uid,this->w_address,this->w_port,this->w_conn_str); this->running = true; + this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WAITING); + namelen = sizeof(sin); if ((p->s = accept(this->s,(LPSOCKADDR)&sin,&namelen)) == INVALID_SOCKET) { @@ -137,13 +144,14 @@ int base_passive::work() break; } + this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); strcpy(p->hostaddr,inet_ntoa(sin.sin_addr)); p->port = sin.sin_port; p->isConnected = true; // strcpy(p->w_conn_str,this->w_conn_str); - if (this->>get_priv(p)!=0) + if (this->get_priv(p)!=0) { p->s_send("502 Load access file failed.\r\n"); @@ -151,17 +159,18 @@ int base_passive::work() continue; } - if (!p->access.get) + if (!p->check_priv()) { p->s_send("502 You are not in my access file.\r\n"); delete(p); continue; } - if (base_passive::uThreadCount < MAX_THREAD) + +// if (base_passive::uThreadCount < MAX_CLIENT) if (this->GetThreadPool()->GetThreadCount() < MAX_CLIENT) { if (hThreadCurrent = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base_passive::AcceptThread,(LPVOID)p,0,&ulThreadId)) - base_passive::uThreadCount++; + { CloseHandle(hThreadCurrent); syslog << logfile::log_head << "Create accept thread ... OK" << endl; } @@ -195,6 +204,18 @@ DWORD base_passive::AcceptThread(LPVOID try { + p = (base_passive*)pParam; + + p->ulMainThreadId = GetCurrentThreadId(); + + syslog << logfile::log_head << "Accept connection from " << p->hostaddr + << ":" << p->port << endl; + + if (p->GetParentThread()->GetThreadPool()->AddThread(GetCurrentThreadId(), CLOCKS_PER_SEC * 30) != 0) + { + syslog << logfile::log_head << "Register thread ... Failed" << endl; + } + p->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); if (p->db_env_init() == 0) { @@ -203,8 +224,14 @@ DWORD base_passive::AcceptThread(LPVOID else { syslog << logfile::log_head << "DB_ENV_INIT failed" << endl; + } + + if (p->GetParentThread()->GetThreadPool()->RemoveThread(GetCurrentThreadId()) != 0) + { + syslog << logfile::log_head << "Unregister thread ... Failed" << endl; + } +// base_passive::uThreadCount--; - base_passive::uThreadCount--; delete(p); syslog << logfile::log_head << "Delete accept thread ... OK" << endl; } @@ -225,7 +252,7 @@ int base_passive::get_priv(base_passive* //Default value strcpy(p->access.ip,p->hostaddr); p->access.control = false; - p->access.get = true; + p->access.get = false; p->access.post = false; p->access.ihave = false; @@ -329,3 +356,8 @@ int base_passive::w_call(void) this->work(); return 0; } + +bool base_passive::check_priv(void) +{ + return this->access.get; +}