zoukankan      html  css  js  c++  java
  • muduo网络库中重要的函数

    1、EventLoop类
    EventLoop::loop()
    {
    	poller_->poll();
    	{
    		 epoll_create1()
    		 EPollPoller::poll()
    		 {
    			 epoll_wait
    			 fillActiveChannels();
    		 }
    	}
    	currentActiveChannel_->handleEvent(pollReturnTime_);
    }
    2、EpollPoller类
    EPollPoller::updateChannel()
    {
    	
    }
    3、Channel类
    Channel::enableReading()
    {
    	Channel::update()
    	{
    		EventLoop::updateChannel()
    		{
    			Poller::updateChannel()
    			{
    				EPollPoller::update
    				{
    					//监听的时候需要、连接成功的时候需要
    					epoll_ctl();
    				}
    			}
    		}
    	}
    }
    Channel::handleEvent()
    {
    	Channel::handleEventWithGuard()
    	{
    		closeCallback_();
    		writeCallback_();
    		readCallback_();
    	}
    }
    Channel::setReadCallback(){readCallback_ }
    Channel::setWriteCallback()
    Channel::setCloseCallback()
    Channel::setErrorCallback()
    4、TcpConnection类  便会将对应的读写回调处理函数注册进Channel
    //构造
    TcpConnection::TcpConnection
    {
    	Channel::setReadCallback(std::bind(&TcpConnection::handleRead, this, _1));
    	{
    		TcpConnection::handleRead(Timestamp receiveTime)
    		{
    			inputBuffer_
    			messageCallback_(shared_from_this(), &inputBuffer_, receiveTime);
    		}
    		
    	}
    	Channel::setWriteCallback(std::bind(&TcpConnection::handleWrite, this));
    	{
    		TcpConnection::handleWrite
    		{
    			outputBuffer_
    			writeCompleteCallback_();
    		}
    		
    	}
        Channel::setCloseCallback(std::bind(&TcpConnection::handleClose, this));
    	{
    		TcpConnection::handleClose
    		{
    			connectionCallback_();
    			closeCallback_();
    		}
    		
    	}
        Channel::setErrorCallback(std::bind(&TcpConnection::handleError, this));
    	{
    		TcpConnection::handleError
    		{
    			sockets::getSocketError();
    		}
    	}
    }
    5、Acceptor类  EventLoop  Socket   Channel 
    //主要负责的就是对lfd的读事件的处理
    Acceptor::Acceptor
    {
    	Channel::setReadCallback(std::bind(&Acceptor::handleRead, this));
    	{
    		Acceptor::handleRead
    		{
    			accept()
    			newConnectionCallback_();
    		}
    	}
    	
    }
    Acceptor::setNewConnectionCallback{newConnectionCallback_}
    Acceptor::listen()
    {
    	listen()
    	Channel::enableReading();
    }
    6、TcpServer类
    TcpServer::TcpServer
    {
    	Acceptor::setNewConnectionCallback(std::bind(&TcpServer::newConnection, this, _1, _2));
    	{
    		TcpServer::newConnection
    		{
    			1)、EventLoop* ioLoop = threadPool_->getNextLoop();  //从线程池取一个loop
    			2)、new TcpConnection
    			//这些都是暴露给用户的接口
    			conn->setConnectionCallback(connectionCallback_);  
    			conn->setMessageCallback(messageCallback_);
    			conn->setWriteCompleteCallback(writeCompleteCallback_);
    			conn->setCloseCallback(
    			std::bind(&TcpServer::removeConnection, this, _1));  
    			ioLoop->runInLoop(std::bind(&TcpConnection::connectEstablished, conn)); 
    			{
    				TcpConnection::connectEstablished()
    				{
    					Channel::enableReading();
    					connectionCallback_
    				}
    			}
     
    		}
    	}
    }
    TcpServer::start()
    {
    	loop_->runInLoop(std::bind(&Acceptor::listen, get_pointer(acceptor_)));
    }
    

      

  • 相关阅读:
    为什么不能直接导入Statsmodels使用?
    数据分析工作的主要内容和基本流程
    Nodejs 包与 NPM 第三方模块安装和 package.json 以及 CNPM (4)
    CommonJs 和 Nodejs 中自定义模块 (3)
    pyhthon 处理pdf 合集
    02 nodejs HTTP模块和url模块配置supervisor
    1 nodejs简介与开发环境配置
    mysql 修改root密码和禁用无密码登录配置
    floodFill填充函数函数(六)
    粗略的调整图片对比度和亮度(五)
  • 原文地址:https://www.cnblogs.com/zyj23/p/14701429.html
Copyright © 2011-2022 走看看