{"id":47805641,"url":"https://github.com/hesphoros/libevent_notes","last_synced_at":"2026-04-03T17:35:05.758Z","repository":{"id":255673893,"uuid":"850008340","full_name":"hesphoros/libevent_notes","owner":"hesphoros","description":"This is a document about libevent","archived":false,"fork":false,"pushed_at":"2025-09-23T07:51:49.000Z","size":20256,"stargazers_count":27,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-23T09:27:27.950Z","etag":null,"topics":["c","docs","libevent","markdown","obsidian-md","pdf"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hesphoros.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-30T17:30:39.000Z","updated_at":"2025-09-22T15:22:09.000Z","dependencies_parsed_at":"2024-09-15T08:15:18.167Z","dependency_job_id":"2db2426e-2b46-45a6-ba11-9213f6918bf2","html_url":"https://github.com/hesphoros/libevent_notes","commit_stats":null,"previous_names":["luciferau/libevent_notes","hesphoros/libevent_notes"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hesphoros/libevent_notes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hesphoros%2Flibevent_notes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hesphoros%2Flibevent_notes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hesphoros%2Flibevent_notes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hesphoros%2Flibevent_notes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hesphoros","download_url":"https://codeload.github.com/hesphoros/libevent_notes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hesphoros%2Flibevent_notes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31366366,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T17:13:05.644Z","status":"ssl_error","status_checked_at":"2026-04-03T17:13:04.413Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["c","docs","libevent","markdown","obsidian-md","pdf"],"created_at":"2026-04-03T17:35:05.072Z","updated_at":"2026-04-03T17:35:05.745Z","avatar_url":"https://github.com/hesphoros.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"![libevent](images/libevent.png)\n \n## 前言\n\n此笔记采用obsidian编写。如遇到无法打开笔记、照片等问题，请使用obsidan。\n\nLibevent是用于编写高速可移植非阻塞IO应用的库，其设计目标是：\n\n- 可移植性：使用libevent编写的程序应该可以在libevent支持的所有平台上工作。即使没有好的方式进行非阻塞IO，libevent也应该支持一般的方式，让程序可以在受限的环境中运行\n    \n- 速度：libevent尝试使用每个平台上最高速的非阻塞IO实现，并且不引入太多的额外开销。\n    \n- 可扩展性：libevent被设计为程序即使需要上万个活动套接字的时候也可以良好工作。\n    \n- 方便：无论何时，最自然的使用libevent编写程序的方式应该是稳定的、可移植的。(_Libevent_ should compile on Linux, *BSD, Mac OS X, Solaris, Windows, and more.)\n---\n\n\nlibevent由下列组件构成：\n\n- evutil：用于抽象不同平台网络实现差异的通用功能。\n    \n- event和event_base：libevent的核心，为各种平台特定的、基于事件的非阻塞IO后端提供抽象API，让程序可以知道套接字何时已经准备好，可以读或者写，并且处理基本的超时功能，检测OS信号。\n    \n- bufferevent：为libevent基于事件的核心提供使用更方便的封装。除了通知程序套接字已经准备好读写之外，还让程序可以请求缓冲的读写操作，可以知道何时IO已经真正发生。（bufferevent接口有多个后端，可以采用系统能够提供的更快的非阻塞IO方式，如Windows中的IOCP。）\n    \n- evbuffer：在bufferevent层之下实现了缓冲功能，并且提供了方便有效的访问函数。\n    \n- evhttp：一个简单的HTTP客户端/服务器实现。\n    \n- evdns：一个简单的DNS客户端/服务器实现。\n    \n- evrpc：一个简单的RPC实现。\n\n---\n\n---\n- libevent API提供了一种机制，可以在文件描述符上发生特定事件或达到超时后执行回调函数。此外，libevent还支持由于信号或常规超时而产生的回调。\n    \n- Libevent旨在取代事件驱动网络服务器中的事件循环。应用程序只需要调用event_dispatch()，然后动态地添加或删除事件，而不必更改事件循环。\n    \n- Libevent还为缓冲网络IO提供了一个复杂的框架，支持套接字、过滤器、速率限制、SSL、零拷贝文件传输和IOCP。Libevent支持几种有用的协议，包括DNS、HTTP和一个最小的RPC框架。\n\n![](images/Pasted%20image%2020240904111332.png) \n\n\n## 相关的库\nlibevent公用头文件都安装在event2目录中，分为三类：\n\n- API头文件：定义libevent公用接口。这类头文件没有特定后缀。\n    \n- 兼容头文件：为已废弃的函数提供兼容的头部包含定义。不应该使用这类头文件，除非是在移植使用较老版本libevent的程序时。\n    \n- 结构头文件：这类头文件以相对不稳定的布局定义各种结构体。这些结构体中的一些是为了提供快速访问而暴露；一些是因为历史原因而暴露。直接依赖这类头文件中的任何结构体都会破坏程序对其他版本libevent的二进制兼容性，有时候是以非常难以调试的方式出现。这类头文件具有后缀“_struct.h”。\n\n## 如何使用libevent\n\n### 创建event_base\n [event_base](event_base.md)\n \n## 使用事件循环\n [Event loop](Event%20loop.md)\n\n## 创建事件\n[Create event](Create%20event.md)\n\n## 相关的辅助函数和类型\n[Helper types and functions](Helper%20types%20and%20functions.md)\n\n## DNS\n[DNS with libevent](DNS%20with%20libevent.md)\n\n ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhesphoros%2Flibevent_notes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhesphoros%2Flibevent_notes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhesphoros%2Flibevent_notes/lists"}