5 Star 8 Fork 3

LittleKu/client

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ConnectionPool.h 2.20 KB
一键复制 编辑 原始数据 按行查看 历史
LittleKu 提交于 2015-06-19 08:43 . 同步github
/****************************************
* class : CConnectionPool
* author : LittleKu (L.K)
* email : kklvzl@gmail.com
* date : 09-02-2014
****************************************/
#ifndef __CONNECTION_POOL_H__
#define __CONNECTION_POOL_H__
#pragma once
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <cstdlib>
#include <deque>
#include <list>
#include <iostream>
#include "Connection.h"
#include "msgbuffer.h"
namespace client
{
class CClientImpl;
typedef boost::function3<void, const boost::system::error_code &, StatusCode, CMsgBuffer::Ptr> cb_InitConnection;
typedef boost::function2<void, const boost::system::error_code &, CConnection::Ptr> cb_addConnection;
class CConnectionPool
: public boost::enable_shared_from_this<CConnectionPool>,
private boost::noncopyable
{
friend class CClientImpl;
public:
//typedef boost::function2<void, const boost::system::error_code &, CMessage::Ptr> cb_InitConnection;
public:
CConnectionPool(boost::asio::io_service &io_service);
~CConnectionPool();
void Init(const std::string &host, const std::string &port, cb_InitConnection cb, int connection_count, int connection_limit);
void Stop();
void GetConnection(cb_addConnection cb);
private:
void QueueConnection(const boost::system::error_code &err, StatusCode sc, CMsgBuffer::Ptr msg, cb_InitConnection cb, CConnection::Ptr connection);
void NewConnection(cb_InitConnection cb);
void CheckAvaliableConnection(const boost::system::error_code &err);
void TimeoutNewConnection(const boost::system::error_code &err, cb_InitConnection cb);
bool HasValidConnect();
private:
boost::mutex m_Mutex;
std::string m_Host;
std::string m_Port;
bool m_bIsStop;
boost::asio::io_service &m_Io_Service;
std::list<CConnection::Ptr> m_ListNew;
std::list<CConnection::Ptr> m_ListValid;
std::list<CConnection::Ptr> m_ListRun;
std::deque<cb_addConnection> m_DequeRequest;
int m_nConnectionCount;
int m_nConnectionLimit;
boost::asio::deadline_timer m_TryTimer;
boost::asio::deadline_timer m_TryTimerConnect;
int m_TryConnect;
int m_TimeoutRequest;
int m_TimeoutConnect;
};
}
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/LittleKu/client.git
git@gitee.com:LittleKu/client.git
LittleKu
client
client
master

搜索帮助