From f72916f92c31d5c74e480a667230f4992453f780 Mon Sep 17 00:00:00 2001 From: Peter Kozarec Date: Sun, 24 Mar 2024 11:40:23 +0100 Subject: [PATCH] Added define for examples to be build --- CMakeLists.txt | 4 ++++ examples/websocket_example/CMakeLists.txt | 10 +--------- libs/libio/include/endpoint.hpp | 2 +- libs/libio/src/websocket.cpp | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c6d022..d8c0791 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,3 +4,7 @@ project(libio VERSION 0.0.1) set(CMAKE_CXX_STANDARD 20) add_subdirectory(libs/libio) + +if(BUILD_EXAMPLES) + add_subdirectory(examples/websocket_example) +endif() \ No newline at end of file diff --git a/examples/websocket_example/CMakeLists.txt b/examples/websocket_example/CMakeLists.txt index 49bb90c..61a5dc3 100644 --- a/examples/websocket_example/CMakeLists.txt +++ b/examples/websocket_example/CMakeLists.txt @@ -1,13 +1,5 @@ -cmake_minimum_required(VERSION 3.15) -project(websocket_example) -set(CMAKE_CXX_STANDARD 20) - -find_package(libio REQUIRED) -find_package(Boost COMPONENTS system log REQUIRED) -find_package(OpenSSL REQUIRED) add_executable(websocket_example src/main.cpp) -target_link_libraries(websocket_example PRIVATE ${LIBIO_LIBRARIES}) -target_compile_options(websocket_example PRIVATE "-fcoroutines") +target_link_libraries(websocket_example PRIVATE io) diff --git a/libs/libio/include/endpoint.hpp b/libs/libio/include/endpoint.hpp index 92ceb29..895953a 100644 --- a/libs/libio/include/endpoint.hpp +++ b/libs/libio/include/endpoint.hpp @@ -27,7 +27,7 @@ namespace io::priv virtual boost::asio::awaitable connect() noexcept = 0; virtual boost::asio::awaitable disconnect() noexcept = 0; - virtual boost::asio::awaitable write(const std::string &message) = 0; + virtual boost::asio::awaitable write(const std::string & message) = 0; virtual boost::asio::awaitable read() = 0; void set_host(const std::string & host); diff --git a/libs/libio/src/websocket.cpp b/libs/libio/src/websocket.cpp index 1280914..3c511c4 100644 --- a/libs/libio/src/websocket.cpp +++ b/libs/libio/src/websocket.cpp @@ -70,7 +70,7 @@ boost::asio::awaitable io::Websocket::listen() for (;;) { const auto result = co_await impl_->endpoint.read(); - + if (const auto observer = impl_->observer.lock()) { co_await observer->on_recieved(result);