Code Monkey home page Code Monkey logo

tiny-muduo's Introduction

Tiny Muduo

Overview

For User

sequenceDiagram
    actor User
    participant EventLoop
    participant TcpServer
    User->>EventLoop: call init()
    User->>TcpServer: call init(loop, addr)
    User->>TcpServer: call set*Connection()
    User->>TcpServer: call setThreadNum()
    User->>TcpServer: call start()
    User->>EventLoop: call loop()

For TcpServer

sequenceDiagram
    participant TcpServer
    participant EventLoopThreadPool
    participant TcpConnection
    participant Acceptor
    participant Socket
    participant Channel
    participant EventLoop
    participant Poller
    participant OS
    
    TcpServer->>TcpServer: init()
    TcpServer->>Acceptor: call init(loop, addr)
    Acceptor->>Socket: call create()
    Socket-->>Acceptor: fd
    Acceptor->>Channel: call init(loop, fd)
    Acceptor->>Socket: call bind(addr)
    Acceptor->>Channel: call setReadCallback(handleRead)
    TcpServer->>EventLoopThreadPool: call init(loop)
    TcpServer->>Acceptor: call setNewConnectionCallback(newConnection)
    
    TcpServer->>TcpServer: start()
    TcpServer->>EventLoop: call runInLoop(Acceptor::listen)
    EventLoop->>EventLoop: queueInLoop()
    EventLoop->>EventLoop: wakeUp()
    EventLoop->>EventLoop: loop()
    EventLoop->>EventLoop: doPendingFunctors()
    EventLoop->>Acceptor: call listen()
    Acceptor->>Socket: call listen()
    
    Acceptor->>Channel: call enableReading()
    Channel->>EventLoop: call updateChannel()
    EventLoop->>Poller: call updateChannel()
    Poller->Poller: update pollFdList
    
    EventLoop->>EventLoop: loop()
    EventLoop->>Poller: call poll()
    Poller->>OS: call poll(pollFdList)
    OS-->>Poller: update pollFdList
    Poller->>Poller: fillActiveChannels(pollFdList)
    Poller-->>EventLoop: return activeChannels
    EventLoop->>Channel: call handleEvent()
    
    Channel->>Acceptor: call handleRead()
    Acceptor->>Socket: call accept()
    Socket-->>Acceptor: return connfd, peerAddr
    Acceptor->>TcpServer: call newConnectionCallback(connfd, peerAddr)
    
    TcpServer->>TcpServer: newConnection()
    TcpServer->>EventLoopThreadPool: call getNextLoop()
    EventLoopThreadPool-->>TcpServer: return ioLoop
    TcpServer->>TcpConnection: call init(ioLoop, connfd, peerAddr)
    TcpConnection->>Socket: call init(connfd)
    TcpConnection->>Channel: call init(ioLoop, connfd)
    TcpServer->>TcpConnection: call set*Callback
    TcpConnection->>Channel: call set*Callback(TcpConnection::handle*)
    TcpServer->>EventLoop: call runInLoop(TcpConnection::connectEstablished, conn)
    

Timer

sequenceDiagram
    participant TcpServer
    participant Timer
    participant Timer Queue

Setup

sudo apt install build-essential cmake libboost-dev

Reference

https://github.com/chenshuo/recipes

tiny-muduo's People

Contributors

songquanpeng avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.