{"id":20968599,"url":"https://github.com/rnburn/coevent","last_synced_at":"2025-05-14T09:33:52.664Z","repository":{"id":47439557,"uuid":"174752171","full_name":"rnburn/coevent","owner":"rnburn","description":"Asynchronous coroutines networking library for C++","archived":false,"fork":false,"pushed_at":"2019-03-29T07:18:59.000Z","size":167,"stargazers_count":9,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T16:25:37.852Z","etag":null,"topics":["asynchronous-io","c-plus-plus","c-plus-plus-20","coroutine-library","coroutines-ts","libevent"],"latest_commit_sha":null,"homepage":"","language":"C++","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/rnburn.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}},"created_at":"2019-03-09T22:17:55.000Z","updated_at":"2024-10-01T16:36:37.000Z","dependencies_parsed_at":"2022-08-30T17:20:53.041Z","dependency_job_id":null,"html_url":"https://github.com/rnburn/coevent","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnburn%2Fcoevent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnburn%2Fcoevent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnburn%2Fcoevent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnburn%2Fcoevent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rnburn","download_url":"https://codeload.github.com/rnburn/coevent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254112608,"owners_count":22016809,"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":["asynchronous-io","c-plus-plus","c-plus-plus-20","coroutine-library","coroutines-ts","libevent"],"created_at":"2024-11-19T03:14:42.347Z","updated_at":"2025-05-14T09:33:52.161Z","avatar_url":"https://github.com/rnburn.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# coevent\n\nA C++ coroutine library for asynchronous networking. (Based off of [libevent](https://libevent.org/)).\n\n## Quick Start\n\nMake a simple echo server and client\n\n```cpp\n// server\n\nstatic coevent::detached_task process_session(coevent::socket socket) {\n  std::array\u003cchar, 500\u003e buffer;\n  while (true) {\n    co_await coevent::until_readable(socket);\n    auto read_result = coevent::read(socket, {buffer.data(), buffer.size()});\n    if (read_result.eof()) {\n      co_return;\n    }\n    co_await coevent::write(socket, {buffer.data(), read_result.num_read()});\n  }\n}\n\nstatic coevent::detached_task run_server(coevent::socket\u0026 listener_socket) {\n  while (true) {\n    auto socket = co_await accept(listener_socket);\n    process_session(std::move(socket));\n  }\n}\n\nint main() {\n  coevent::io_context io_context;\n  coevent::endpoint endpoint{\"127.0.0.1\", 8080};\n  coevent::socket socket{io_context};\n  socket.bind(endpoint);\n  listen(socket, 10);\n  run_server(socket);\n  io_context.run();\n  return 0;\n}\n\n```\n\n```cpp\n// client\n\nstatic coevent::task\u003cvoid\u003e random_sleep(coevent::io_context\u0026 io_context) {\n  static thread_local std::mt19937 random_number_generator{std::random_device{}()};\n  std::uniform_int_distribution distribution(0, 1000);\n  co_await coevent::sleep(\n      io_context,\n      std::chrono::milliseconds{distribution(random_number_generator)});\n}\n\nstatic coevent::detached_task run_client(coevent::io_context\u0026 io_context, int index) {\n  co_await random_sleep(io_context);\n\n  coevent::socket socket{io_context, coevent::endpoint{\"127.0.0.1\", 8080}};\n\n  auto send_message = \"Hello from \" + std::to_string(index);\n  std::cout \u003c\u003c \"Sent: \" \u003c\u003c send_message \u003c\u003c \"\\n\";\n  co_await coevent::write(socket, {send_message.data(), send_message.size()});\n\n  std::string received_message(send_message.size(), ' ');\n  co_await coevent::read(socket, {received_message.data(), received_message.size()});\n  std::cout \u003c\u003c \"Received: \" \u003c\u003c received_message \u003c\u003c \"\\n\";\n}\n\nint main() {\n  coevent::io_context io_context;\n  for (int i=0; i\u003c10; ++i) {\n    run_client(io_context, i);\n  }\n  io_context.run();\n  return 0;\n}\n```\n\nSee [example/echo](example/echo) for the full example.\n\n## Installation\n\ncoevent requires [libevent](https://libevent.org/) and a C++ compiler that supports coroutines.\n(Tested against clang-9).\n\n```\n$ mkdir .build\n$ cd .build\n# For clang use libc++ instead of libstdc++\n$ cmake -DCMAKE_CXX_FLAGS=\"-stdlib=libc++\" ..\n$ make\n$ sudo make install\n```\n\nThe docker image [rnburn/clang](https://hub.docker.com/r/rnburn/clang) contains a version of clang\nsuitable for building the library and the script [ci/run_coevent_docker.sh](ci/run_coevent_docker.sh)\ncan be used to spin up a docker environment that builds the project.\n\n```\n$ ./ci/run_coevent_docker.sh\n# bazel build //...\n# bazel test //...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frnburn%2Fcoevent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frnburn%2Fcoevent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frnburn%2Fcoevent/lists"}