分类:
2008-10-13 16:12:07
没啥好说的,管理所有的客户端和内存池的功能。
class ClientManager : public SingleTon
{
public:
ClientManager():_header(NULL){}
~ClientManager(){}
public:
void init(unsigned int default_pool_size,unsigned int default_read_buf_size);
void fini();
public:
ClientHandler *get_clienthandler();
void release_client_handle(ClientHandler *client);
void check_time_out();
size_t get_client_count();
private:
ClientHandler *_header;
std::set
ACE_Recursive_Thread_Mutex _lock;
};
#include "clientmanager.h"
#include
ClientHandler *ClientManager::get_clienthandler()
{
FUNC_ENTER;
ACE_Guard
ClientHandler *ret=NULL;
if(_header==NULL)
{
ACE_DEBUG((LM_DEBUG,"client > max clients!!!\n"));
}
else
{
ret=_header;
_header=_header->next();
ret->init();
_active_clients.insert(ret);
}
FUNC_LEAVE;
return ret;
}
void ClientManager::release_client_handle(ClientHandler *client)
{
//FUNC_ENTER;
ACE_Guard
client->fini();
client->next(_header);
_header=client;
_active_clients.erase(client);
//FUNC_LEAVE;
}
void ClientManager::init(unsigned int default_pool_size,unsigned int default_read_buf_size)
{
//FUNC_ENTER;
for(unsigned int i=0;i
ClientHandler *client=new ClientHandler(default_read_buf_size);
client->next(_header);
_header=client;
}
//FUNC_LEAVE;
}
void ClientManager::fini()
{
//FUNC_ENTER;
while(_header)
{
ClientHandler *temp=_header->next();
delete _header;
_header=temp;
}
//FUNC_LEAVE;
}
void ClientManager::check_time_out()
{
time_t cur_time=ACE_OS::time(NULL);
ACE_Guard
for(std::set
{
(*it)->check_time_out(cur_time);
}
}
size_t ClientManager::get_client_count()
{
ACE_Guard
return _active_clients.size();
}