File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
66set (ASYNCIO_VERSION 1.1.0)
77
88option (BUILD_SAMPLES "Build asyncio samples" ON )
9+ option (BUILD_INTEGRATION_SAMPLES "Build asyncio integration samples" OFF )
910option (BUILD_SHARED_LIBS "Build using shared libraries" OFF )
1011option (ASYNCIO_EMBED_CA_CERT "Use built-in CA certificates instead of system certificates" OFF )
1112
Original file line number Diff line number Diff line change 1+ if (BUILD_INTEGRATION_SAMPLES)
2+ find_package (httplib CONFIG REQUIRED )
3+ endif ()
4+
15add_executable (asyncio_tcp_client tcp/client.cpp )
26target_link_libraries (asyncio_tcp_client PRIVATE asyncio-main )
37
@@ -10,8 +14,13 @@ target_link_libraries(asyncio_tls_client PRIVATE asyncio-main)
1014add_executable (asyncio_tls_server tls/server.cpp )
1115target_link_libraries (asyncio_tls_server PRIVATE asyncio-main )
1216
13- add_executable (asyncio_http http/main.cpp )
14- target_link_libraries (asyncio_http PRIVATE asyncio-main )
17+ add_executable (asyncio_http_client http/client.cpp )
18+ target_link_libraries (asyncio_http_client PRIVATE asyncio-main )
19+
20+ if (BUILD_INTEGRATION_SAMPLES)
21+ add_executable (asyncio_http_server http/server.cpp )
22+ target_link_libraries (asyncio_http_server PRIVATE asyncio-main httplib::httplib )
23+ endif ()
1524
1625add_executable (asyncio_ws ws/main.cpp )
1726target_link_libraries (asyncio_ws PRIVATE asyncio-main )
File renamed without changes.
Original file line number Diff line number Diff line change 1+ #include < asyncio/thread.h>
2+ #include < asyncio/signal.h>
3+ #include < asyncio/error.h>
4+ #include < zero/cmdline.h>
5+ #include < httplib.h>
6+
7+ asyncio::task::Task<void > asyncMain (const int argc, char *argv[]) {
8+ zero::Cmdline cmdline;
9+
10+ cmdline.add <std::string>(" ip" , " IP address to bind" );
11+ cmdline.add <std::uint16_t >(" port" , " Port number to listen on" );
12+
13+ cmdline.parse (argc, argv);
14+
15+ const auto ip = cmdline.get <std::string>(" ip" );
16+ const auto port = cmdline.get <std::uint16_t >(" port" );
17+
18+ httplib::Server server;
19+
20+ server.Get (
21+ " /hi" ,
22+ [](const httplib::Request &, httplib::Response &response) {
23+ response.set_content (" Hello World!" , " text/plain" );
24+ }
25+ );
26+
27+ auto signal = asyncio::Signal::make ();
28+
29+ co_await race (
30+ asyncio::toThread (
31+ [&] {
32+ if (!server.listen (ip, port)) {
33+ #ifdef _WIN32
34+ throw std::system_error{WSAGetLastError (), std::system_category ()};
35+ #else
36+ throw std::system_error{errno, std::system_category ()};
37+ #endif
38+ }
39+ },
40+ [&](std::thread::native_handle_type) -> std::expected<void , std::error_code> {
41+ server.stop ();
42+ return {};
43+ }
44+ ),
45+ asyncio::task::spawn ([&]() -> asyncio::task::Task<void > {
46+ co_await asyncio::error::guard (signal.on (SIGINT));
47+ })
48+ );
49+ }
Original file line number Diff line number Diff line change 1515 " tests"
1616 ],
1717 "features" : {
18+ "integration-samples" : {
19+ "description" : " Build integration samples" ,
20+ "dependencies" : [
21+ " cpp-httplib"
22+ ]
23+ },
1824 "tests" : {
1925 "description" : " Build Tests" ,
2026 "dependencies" : [
You can’t perform that action at this time.
0 commit comments