代码拉取完成,页面将自动刷新
/***
* @Description:
* @Author: LeoTao
* @Date: 2023-10-21 21:53:53
* @LastEditTime: 2023-11-01 03:44:17
*/
#include "TcpConnection.h"
#include "Socket.h"
#include "Channel.h"
#include "logger.h"
static EventLoop* CheckLoopNotNull(EventLoop *loop){
if(loop == nullptr){
LOG_FATAL("%s:%s:%d mianloop is nullptr", __FILE__, __FUNCTION__, __LINE__);
}
return loop;
}
TcpConnection::TcpConnection(EventLoop* loop,
const std::string& name,
int sockfd,
const InetAddress& localAddr,
const InetAddress& peerAddr)
: loop_(CheckLoopNotNull(loop)),
name_(name),
state_(kConnecting),
reading_(true),
socket_(new Socket(sockfd)),
channel_(new Channel(loop, sockfd)),
localAddr_(localAddr),
peerAddr_(peerAddr),
highWaterMark_(64*1024*1024)//64M
{
//下面给channel设置相应得回调函数,poller给channel通知感兴趣得事件发生了,channel会回调相应得操作函数
channel_->setReadCallback(std::bind(&TcpConnection::handleRead, this, std::placeholders::_1));
channel_->setWriteCallback(std::bind(&TcpConnection::handleWrite, this));
channel_->setCloseCallback(std::bind(&TcpConnection::handleClose,this));
channel_->setErrorCallback(std::bind(&TcpConnection::handleError,this));
LOG_INFO("TcpConnection::ctor[%s] at fd = %d \n", name_.c_str(), sockfd);
socket_->setKeepAlive(true);
}
TcpConnection::~TcpConnection(){
LOG_INFO("TcpConnection::dtor[%s] at fd = %d\n", name_.c_str(), channel_->fd());
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。