{"id":13755801,"url":"https://github.com/wlgq2/eomaia","last_synced_at":"2026-01-25T15:36:45.980Z","repository":{"id":130576552,"uuid":"79718484","full_name":"wlgq2/eomaia","owner":"wlgq2","description":"一个基于reactor模式的Linux/C++网络库，支持one loop per thread机制。","archived":false,"fork":false,"pushed_at":"2020-04-14T15:41:41.000Z","size":245,"stargazers_count":188,"open_issues_count":1,"forks_count":46,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-08-03T11:01:22.241Z","etag":null,"topics":["epoll","reactor","tcp-server"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wlgq2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-01-22T13:10:49.000Z","updated_at":"2024-06-09T03:37:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"8bc83516-460a-4245-8f4d-afd795e68414","html_url":"https://github.com/wlgq2/eomaia","commit_stats":null,"previous_names":["whatsghost/agilnet"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wlgq2%2Feomaia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wlgq2%2Feomaia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wlgq2%2Feomaia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wlgq2%2Feomaia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wlgq2","download_url":"https://codeload.github.com/wlgq2/eomaia/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253354489,"owners_count":21895436,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["epoll","reactor","tcp-server"],"created_at":"2024-08-03T11:00:30.125Z","updated_at":"2026-01-25T15:36:45.974Z","avatar_url":"https://github.com/wlgq2.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# eomaia\n一个基Reactor模式+epoll复用机制实现的C++网络库，无任何依赖，基于C++11（需要g++5以上），支持one loop per thread。  参考学习陈硕的muduo\u003cbr\u003e\n\n\n\n## 编译\n\u003cbr\u003e提供codeblocks与Cmake两种方式编译。\u003c/br\u003e\n* codeblocks 编译： \n1.  `apt-get install codeblocks`\n2.  用codeblocks打开example目录下工程，点击build即可。\n* cmake编译： \n1.  `mkdir build`\n2.  `cd build`\n3.  `cmake ..`\n4.  将头文件与.so、.a文件加入工程。\n\n## 目录结构\n1.`example` 相关测试例程 \u003cbr\u003e\n2.`eomaia/net` 网络库的主要实现，包括reactor模式实现与TCP相关类封装\u003cbr\u003e\n3.`eomaia/base` 网络库的依赖，封装log接口、线程/线程池\u003cbr\u003e\n\n\n## reactor模式实现细节  \n1.`Epoll类`  :对linux epoll的封装，包括对epoll添加/删除/修改事件，以及调用wait操作等待事件\u003cbr\u003e\n2.`IOEvent类`:对事件的封装，包括一个文件fd成员变量，以及相关读写事件处理函数。所有需要响应事件的类都在内部包含一个IOEvent成员变量对象，并注册到loop中\u003cbr\u003e\n3.`IOEventCtrl类`: 内部包含一个IOEvent事件池，该类把事件注册到Epoll中，并调用waitAndRunHandle()等待并获得事件触发，并调用事件池中的事件回调函数\u003cbr\u003e\n4.`IOEventLoop类`: 事件循环类，一个事件循环类对应一个线程，内部包含一个IOEventCtrl成员变量，在run()函数中调用该成员变量等待/执行事件\u003cbr\u003e\n\n\n## Tcp相关类封装\n1.`TcpAccept` : 内部包括一个成员变量Socket对象，以及IOevent类，当有新连接时触发事件\u003cbr\u003e\n2.`TcpConnec` : TCP连接类，代表一次新的连接。当服务器与连接读写数据时触发事件\u003cbr\u003e\n3.`TcpServer` : Tcp服务器，内部包括一个 TcpConnect池，有新的连接时候向该池增加Tcpconnect对象，当连接断开时在池中删掉该对象\u003cbr\u003e\n4.`Buffer`    : 对缓存的封装\u003cbr\u003e\n5 `Socket 与SocketOperation` : socket 与socket操作的封装\u003cbr\u003e\n\n\n## 定时器列队实现原理\n1.在TimerQueue类中初始化一个timerFd，并加入epoll事件中等待触发\u003cbr\u003e\n2.考虑到可能会有多个相同时间的定时器，TimerQueue中有两个multimap容器：onceTimers和everyTimers，分别是定时只运行一次的事件，和定隔每次运行的事件\u003cbr\u003e\n3.每次添加定时器容器，如果加入事件比容器中时间最近的事件还近，则重置定时器为新添加事件\u003cbr\u003e\n4.定时器事件被触发时，执行设置时间小于当前时间的定时器回调函数，并删除列队。如果间隔每次触发的事件，则删除元素后，更新时间重新添加。\u003cbr\u003e\n\n\n## One loop per thread机制支持\n1.`base/Thread类`  ：把std::thead封装成类似Qt/QThead,用户线程需继承Thread类，实现纯虚函数run(),并调用start()启动线程。\u003cbr\u003e\n2.`net/IOEventLoopThread类`  ：Thread类的子类，实现具体业务逻辑，对应一个IOEventLoop事件循环，并在IOEventLoop记录当前线程ID。\u003cbr\u003e\n3.`net/IOEventLoopThreadPool类`  ：线程池类，有新连接建立时，从线程池中分配一个线程给该TCP连接使用。\u003cbr\u003e\n\n## 例程与使用\n* `example/echo`： 回显服务器。\n* `example/http`： http服务demo。\n* `example/timer`: 定时器使用例程。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwlgq2%2Feomaia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwlgq2%2Feomaia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwlgq2%2Feomaia/lists"}