加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
TcpServer.cpp 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
leo_1 提交于 2023-11-01 03:44 . tcpconnection部分实现
/***
* @Description:
* @Author: LeoTao
* @Date: 2023-10-03 22:44:11
* @LastEditTime: 2023-10-23 03:17:55
*/
#include "TcpServer.h"
#include "logger.h"
#include "Acceptor.h"
#include <functional>
static EventLoop* CheckLoopNotNull(EventLoop *loop){
if(loop == nullptr){
LOG_FATAL("%s:%s:%d mianloop is nullptr", __FILE__, __FUNCTION__, __LINE__);
}
return loop;
}
TcpServer::TcpServer(EventLoop* loop,
const InetAddress& listenAddr,
const std::string &nameArg,
Option option)
:loop_(CheckLoopNotNull(loop)),
ipPort_(listenAddr.toIpPort()),
name_(nameArg),
acceptor_(new Acceptor(loop,listenAddr,option == KReusePort)),
threadPool_(new EventLoopThreadPool(loop,name_)),
connectionCallback_(),
messageCallback_(),
nextconnId_(1)
{
//当有新用户连接时,会执行TcpServer::newConnection回调
acceptor_->setNewConnectionCallback(std::bind(&TcpServer::newConnection,this,
std::placeholders::_1, std::placeholders::_2));
}
TcpServer::~TcpServer(){
}
void TcpServer::newConnection(int sockfd, const InetAddress& peerAddr){
}
void TcpServer::removeConnection(const TcpConnectionPtr& conn){
}
void TcpServer::removeConnectionInLoop(const TcpConnectionPtr& conn){
}
void TcpServer::start(){
if(started_++ == 0){
threadPool_->start(threadInitCallback_);//启动底层的loop线程池
loop_->runInLoop(std::bind(&Acceptor::listen, acceptor_.get()));
}
}
void TcpServer::setThreadNum(int numThreads){
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化