加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
kcp_module.h 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
gaoqingfeng 提交于 2023-01-31 18:11 . kcp listen update
#pragma once
/*
* kcp server manager
*/
#include <string>
#include "kcp_server.h"
#include "type.h"
#include "knet.h"
#include "thread_pool.hpp"
#include "asio/asio.hpp"
namespace KCP {
class CKCPModule : public IKcpModule, asio::noncopyable {
protected:
CKCPModule();
virtual ~CKCPModule();
typedef std::vector<CKCPServer*> KCPServerArray;
public:
static CKCPModule& instance() {
static CKCPModule gInstance;
return gInstance;
}
public:
// implement IKcpModule interface.
virtual bool GNAPI Init();
virtual bool GNAPI Run(int count);
virtual IKServer* GNAPI Listen(const char* ip, unsigned short port, IKSessionFactory* factory);
virtual bool GNAPI Connect(const char* ip, unsigned short port, IKSessionFactory* factory);
public:
// Create kcp server:
// (ip,port) is remote address
// factory is a session factory, which can create session.
// listen denote server or client.
CKCPServer* Create(const std::string& ip, uint16 port, IKSessionFactory* factory, bool listen);
// Get main thread io_service.
asio::io_service& GetIOService() {
return m_ioService;
}
// Increase reference
void IncRef() {
m_ref++;
}
// decrease ref
void DecRef() {
m_ref--;
}
private:
// stop kcp server.
void stop(CKCPServer* server);
private:
// main io_service.
asio::io_service m_ioService;
KCPServerArray m_array;
CThreadPool m_ioServicePool;
int m_ref{0};
};
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化