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_)));
    }
    

      

  • 相关阅读:
    RHEL双网卡绑定
    图解机房收费系统报表制作的全过程
    linux内存管理机制
    hdu4432 Sum of divisors(数论)
    树和而叉查找树的实现
    49. 面向对象的LotusScript(十五)之Log4Dom下
    HDU 4009 不定根最小树形图
    模拟+二分 poj-1019-Number Sequence
    SQL Server 事务日志传输
    百度开放云java+tomcat部署web项目-小皇帝詹姆斯
  • 原文地址:https://www.cnblogs.com/zyj23/p/14701429.html
Copyright © 2011-2022 走看看