Code Monkey home page Code Monkey logo

threadpollepoll's Introduction

HTTP服务器

服务器架构

  • 使用Socket + pthreadpool + epoll IO 多路复用,实现server高并发
  • http 服务器使用cgi程序,处理动态页面请求o
  • 使用 C++ 封装 Socket 线程池模型 Epoll 模型 Http协议

模型的核心:

主线程负责所有I/O操作,收其一个请求所有数据之后,交给工作线程进行处理。 处理完成之后,把需要写回的数据还给主线程去发送给客户端,

epoll模型的使用方式,

epoll_wait()等待事件的发生,判断是否为新的套接字,如果是添加到任务队列 如果套接字可读,将数据读出,并传给子线程处理,子线程处理完成后,会把数据发送给主线程, 主线程调用epoll_ctl() EPOLL_CTL_MOD将套接字设置成EPOLLOUT,然后 调用send(),发送给客户端,待数据发送完毕,关闭套接字。

实现http协议

参考tinyhttp源码 tinyhttp 是一款轻量级的web服务器,只有500行代码,本项目对http进行改造, tinyhttp 调用recv(),每次只读取一个字节,本项目将http请求的所有内容一次性全部读取,再分别 进行处理. 并使用 c++ 进行封装, 

CGI

当web服务器请求动态页面,使用fork() 派生成子进程, 子进程执行 execve(), 父进程 和子进程采用管道进行通信,在子进程中 使用dup2()将写端重定向到STDOUT, 读端重定向 到STDIN, 本项目采用python3脚本进行测试

threadpollepoll's People

Contributors

huangliang0412 avatar

Stargazers

llce avatar Kranti avatar  avatar  avatar  avatar  avatar

Watchers

James Cloos 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.