7

如何开发一个TcpServer -- 第二篇

 3 years ago
source link: http://blog.7rule.com/2019/06/29/how-to-do-cppbox-02.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

如何开发一个TcpServer -- 第二篇

Jun 29, 2019

上一次,我们开发了一个最简单的服务端程序。

这个程序有个问题,当服务端在处理一个连接的时候,其它的连接无法得到同时处理,也就是我们常说的,这不是个高并发服务程序。

本期我们来开始解决这个问题。

服务端并发模型

服务端编程发展到今天,并发模型这块,也是很成熟了。

cppbox使用的是单进程多线程的模式,每个线程都有各自单独的事件循环,这也是无锁化编程的基础。

cppbox多线程

ListenThread

这个线程在做的事情如下:

  1. 调用accept获得connfd
  2. 将这个connfd分配给一个ConnectionThread

ConnectionThread

开源的事件循环库


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK