### Basic CMake Project Setup Source: https://github.com/boostorg/beast/blob/develop/test/cmake_test/CMakeLists.txt Initializes a CMake project for C++ and sets the minimum required CMake version. This is a standard starting point for any CMake project. ```cmake cmake_minimum_required(VERSION 3.5...3.16) project(cmake_subdir_test LANGUAGES CXX) ``` -------------------------------- ### Install OpenSSL Development Files (Ubuntu/Debian) Source: https://github.com/boostorg/beast/blob/develop/README.md Install the OpenSSL development libraries on Ubuntu or Debian systems. This is required for building tests and examples that use TLS/Secure sockets. ```bash sudo apt install libssl-dev ``` -------------------------------- ### Include Example Subdirectory Source: https://github.com/boostorg/beast/blob/develop/CMakeLists.txt Conditionally includes the example subdirectory if BOOST_BEAST_BUILD_EXAMPLES is defined, enabling the build of examples. ```cmake if (BOOST_BEAST_BUILD_EXAMPLES) add_subdirectory(example) endif () ``` -------------------------------- ### Install OpenSSL with vcpkg (Bash) Source: https://github.com/boostorg/beast/blob/develop/README.md Installs OpenSSL using vcpkg and exports the OPENSSL_ROOT environment variable for a 32-bit Windows build. Replace 'path' with your vcpkg installation directory. ```bash vcpkg.exe install openssl --triplet x32-windows export OPENSSL_ROOT=path/x32-windows ``` -------------------------------- ### Build Boost.Beast examples with bjam Source: https://github.com/boostorg/beast/blob/develop/README.md Builds the Boost.Beast examples using bjam, specifying C++11 standard and using two processors. Ensure bjam is in your system's PATH. ```bash b2 -j2 libs/beast/example cxxstd=11 # "-j2" means use two processors ``` -------------------------------- ### Install OpenSSL with vcpkg (CMD) Source: https://github.com/boostorg/beast/blob/develop/README.md Installs OpenSSL using vcpkg and sets the OPENSSL_ROOT environment variable for a 32-bit Windows build. Replace 'path' with your vcpkg installation directory. ```bat vcpkg install openssl --triplet x32-windows SET OPENSSL_ROOT=path\installed\x32-windows ``` -------------------------------- ### Install OpenSSL with vcpkg (PowerShell) Source: https://github.com/boostorg/beast/blob/develop/README.md Installs OpenSSL using vcpkg and sets the OPENSSL_ROOT environment variable for a 32-bit Windows build. Replace 'path' with your vcpkg installation directory. ```powershell vcpkg install openssl --triplet x32-windows $env:OPENSSL_ROOT = "path\x32-windows" ``` -------------------------------- ### Test Execution Setup Source: https://github.com/boostorg/beast/blob/develop/test/cmake_test/CMakeLists.txt Enables testing within CMake and adds a test case named 'main' that executes the compiled program. This allows for automated testing of the application. ```cmake enable_testing() add_test(NAME main COMMAND main) add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) ``` -------------------------------- ### Install OpenSSL with brew and set environment variable Source: https://github.com/boostorg/beast/blob/develop/README.md Installs OpenSSL using Homebrew and sets the OPENSSL_ROOT environment variable. This is for macOS. ```bash brew install openssl export OPENSSL_ROOT=$(brew --prefix openssl) # install bjam tool user specific configuration file to read OPENSSL_ROOT # see https://www.bfgroup.xyz/b2/manual/release/index.html cp ./libs/beast/tools/user-config.jam $HOME ``` -------------------------------- ### Handle Connection Upgrade Source: https://github.com/boostorg/beast/blob/develop/test/bench/parser/nodejs-parser/README.md Checks the 'upgrade' flag on the http_parser after execution to determine if the connection has been upgraded to a different protocol. Non-HTTP data starts after the parsed headers. ```c if (parser->upgrade) { /* handle new protocol */ } ``` -------------------------------- ### Generate Visual Studio solution (64-bit) Source: https://github.com/boostorg/beast/blob/develop/README.md Generates a Visual Studio 2022 solution for a 64-bit Windows build using CMake and vcpkg. Ensure the paths to vcpkg and the Beast toolchain file are correct. ```bash cmake -G "Visual Studio 17 2022" -A x64 -B bin64 -DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="C:/boost/libs/beast/cmake/toolchains/msvc.cmake" ``` -------------------------------- ### Generate Visual Studio solution (32-bit) Source: https://github.com/boostorg/beast/blob/develop/README.md Generates a Visual Studio 2022 solution for a 32-bit Windows build using CMake and vcpkg. Ensure the paths to vcpkg and the Beast toolchain file are correct. ```bash cmake -G "Visual Studio 17 2022" -A win32 -B bin -DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="C:/boost/libs/beast/cmake/toolchains/msvc.cmake" ``` -------------------------------- ### Build Boost.Beast documentation with bjam Source: https://github.com/boostorg/beast/blob/develop/README.md Builds the Boost.Beast documentation using bjam. Doxygen and Saxon are required for this process. Ensure bjam is in your system's PATH. ```bash b2 libs/beast/doc # Doxygen and Saxon are required for this ``` -------------------------------- ### Initialize HTTP Parser and Settings Source: https://github.com/boostorg/beast/blob/develop/test/bench/parser/nodejs-parser/README.md Initializes the http_parser structure and settings for a request parser. Requires defining callback functions for various parsing events. ```c http_parser_settings settings; ssettings.on_url = my_url_callback; settings.on_header_field = my_header_field_callback; /* ... */ http_parser *parser = malloc(sizeof(http_parser)); http_parser_init(parser, HTTP_REQUEST); parser->data = my_socket; ``` -------------------------------- ### Configure WebSocket Server Coro Executable Source: https://github.com/boostorg/beast/blob/develop/example/websocket/server/coro/CMakeLists.txt Defines the executable target 'websocket-server-coro' and links it against Boost.Beast. Ensure 'Jamfile' and 'websocket_server_coro.cpp' are in the same directory. ```cmake add_executable(websocket-server-coro Jamfile websocket_server_coro.cpp) source_group("" FILES Jamfile websocket_server_coro.cpp) target_link_libraries(websocket-server-coro PRIVATE Boost::beast) set_target_properties(websocket-server-coro PROPERTIES FOLDER "example-websocket-server") ``` -------------------------------- ### Build bjam on Windows Source: https://github.com/boostorg/beast/blob/develop/README.md Use this command to build the Boost build system (bjam) on Windows. This is necessary for building Beast and other Boost libraries. ```bat .\BOOTSTRAP.BAT ``` -------------------------------- ### Build CMakeLists.txt for WebSocket Client Sync Source: https://github.com/boostorg/beast/blob/develop/example/websocket/client/sync/CMakeLists.txt This CMakeLists.txt file configures the build for a synchronous WebSocket client. It defines the executable, links against Boost.Beast, and sets a folder for the target. ```cmake add_executable(websocket-client-sync Jamfile websocket_client_sync.cpp) source_group("" FILES Jamfile websocket_client_sync.cpp) target_link_libraries(websocket-client-sync PRIVATE Boost::beast) set_target_properties(websocket-client-sync PROPERTIES FOLDER "example-websocket-client") ``` -------------------------------- ### Set Target Properties Source: https://github.com/boostorg/beast/blob/develop/example/websocket/client/async-local/CMakeLists.txt Organizes the 'websocket-client-async-local' executable into a specific folder within the build system for better project structure. ```cmake set_target_properties(websocket-client-async-local PROPERTIES FOLDER "example-websocket-client") ``` -------------------------------- ### CMakeLists.txt Configuration for HTTP Client Async Local Source: https://github.com/boostorg/beast/blob/develop/example/http/client/async-local/CMakeLists.txt Configures the build for the http-client-async-local executable using CMake. It specifies the source files and links against the Boost::beast library. ```cmake add_executable(http-client-async-local Jamfile http_client_async_local.cpp) source_group("" FILES Jamfile http_client_async_local.cpp) target_link_libraries(http-client-async-local PRIVATE Boost::beast) set_target_properties(http-client-async-local PROPERTIES FOLDER "example-http-client") ``` -------------------------------- ### CMakeLists.txt Configuration for WebSocket Client Source: https://github.com/boostorg/beast/blob/develop/example/websocket/client/awaitable/CMakeLists.txt Configures the CMake build system to create an executable for the awaitable WebSocket client. It links against the Boost.Beast library and sets a folder property for organization. ```cmake add_executable(websocket-client-awaitable Jamfile websocket_client_awaitable.cpp) source_group("" FILES Jamfile websocket_client_awaitable.cpp) target_link_libraries(websocket-client-awaitable PRIVATE Boost::beast) set_target_properties(websocket-client-awaitable PROPERTIES FOLDER "example-websocket-client") ``` -------------------------------- ### Add Executable and Source Files Source: https://github.com/boostorg/beast/blob/develop/example/websocket/client/async-local/CMakeLists.txt Defines the executable target 'websocket-client-async-local' and associates it with its source files, including the Jamfile and the main C++ source file. ```cmake add_executable(websocket-client-async-local Jamfile websocket_client_async_local.cpp) source_group("" FILES Jamfile websocket_client_async_local.cpp) ``` -------------------------------- ### CMakeLists.txt Configuration for WebSocket Client Source: https://github.com/boostorg/beast/blob/develop/example/websocket/client/async/CMakeLists.txt Configures an executable for an asynchronous WebSocket client, linking against Boost.Beast. Ensure Boost::beast is available in your CMake configuration. ```cmake add_executable(websocket-client-async Jamfile websocket_client_async.cpp) source_group("" FILES Jamfile websocket_client_async.cpp) target_link_libraries(websocket-client-async PRIVATE Boost::beast) set_target_properties(websocket-client-async PROPERTIES FOLDER "example-websocket-client") ``` -------------------------------- ### Build bjam on Non-Windows Source: https://github.com/boostorg/beast/blob/develop/README.md Use this command to build the Boost build system (bjam) on non-Windows operating systems. This is necessary for building Beast and other Boost libraries. ```bash ./bootstrap.sh ``` -------------------------------- ### Include Boost.Beast Header Source: https://github.com/boostorg/beast/blob/develop/README.md To use Beast, include the main header file in your C++ source files. No additional linking is required for header-only usage. ```cpp #include ``` -------------------------------- ### CMakeLists.txt Configuration for HTTP Server Source: https://github.com/boostorg/beast/blob/develop/example/http/server/async-local/CMakeLists.txt Configures an executable for an asynchronous HTTP server. Links against Boost::beast and sets a folder property for organization. ```cmake add_executable(http-server-async-local Jamfile http_server_async_local.cpp) source_group("" FILES Jamfile http_server_async_local.cpp) target_link_libraries(http-server-async-local PRIVATE Boost::beast) set_target_properties(http-server-async-local PROPERTIES FOLDER "example-http-server") ``` -------------------------------- ### Build Configuration for WebSocket Server Source: https://github.com/boostorg/beast/blob/develop/example/websocket/server/sync/CMakeLists.txt This CMakeLists.txt snippet configures a C++ project to build a synchronous WebSocket server executable. It links against the Boost::beast library and sets a specific folder for the target. ```cmake add_executable(websocket-server-sync Jamfile websocket_server_sync.cpp) source_group("" FILES Jamfile websocket_server_sync.cpp) target_link_libraries(websocket-server-sync PRIVATE Boost::beast) set_target_properties(websocket-server-sync PROPERTIES FOLDER "example-websocket-server") ``` -------------------------------- ### Executable and Linking Configuration Source: https://github.com/boostorg/beast/blob/develop/test/cmake_test/CMakeLists.txt Defines the main executable and links it against the Boost::beast target. This is essential for creating a runnable application that uses the library. ```cmake add_executable(main main.cpp) source_group("" FILES main.cpp) target_link_libraries(main Boost::beast) ``` -------------------------------- ### Build Boost.Beast tests with bjam Source: https://github.com/boostorg/beast/blob/develop/README.md Builds the Boost.Beast tests using bjam, specifying C++11 standard. Ensure bjam is in your system's PATH. ```bash export PATH=$PWD:$PATH b2 -j2 libs/beast/test cxxstd=11 # bjam must be in your $PATH ``` -------------------------------- ### CMakeLists.txt Configuration for WebSocket Server Source: https://github.com/boostorg/beast/blob/develop/example/websocket/server/fast/CMakeLists.txt Configures a CMake project to build an executable named 'websocket-server-fast'. It specifies the source files, groups them, and links against the Boost::beast library. The target properties are set to place the executable in a specific folder. ```cmake add_executable(websocket-server-fast Jamfile websocket_server_fast.cpp) source_group("" FILES Jamfile websocket_server_fast.cpp) target_link_libraries(websocket-server-fast PRIVATE Boost::beast) set_target_properties(websocket-server-fast PROPERTIES FOLDER "example-websocket-server") ``` -------------------------------- ### Link Boost.Beast Library Source: https://github.com/boostorg/beast/blob/develop/example/websocket/client/async-local/CMakeLists.txt Links the 'websocket-client-async-local' executable against the Boost::beast imported target, making the Beast library available for use. ```cmake target_link_libraries(websocket-client-async-local PRIVATE Boost::beast) ``` -------------------------------- ### CMakeLists.txt Configuration for WebSocket Server Source: https://github.com/boostorg/beast/blob/develop/example/websocket/server/async/CMakeLists.txt Configures the CMake build system to create an executable for the asynchronous WebSocket server. It specifies the source files and links against the Boost::beast library. ```cmake add_executable(websocket-server-async Jamfile websocket_server_async.cpp) source_group("" FILES Jamfile websocket_server_async.cpp) target_link_libraries(websocket-server-async PRIVATE Boost::beast) set_target_properties(websocket-server-async PROPERTIES FOLDER "example-websocket-server") ``` -------------------------------- ### Define Boost.Beast WebSocket Test Executable Source: https://github.com/boostorg/beast/blob/develop/test/beast/websocket/CMakeLists.txt Configures a CMake executable for running Boost.Beast WebSocket tests. It links against necessary libraries and sets a target folder. ```cmake if (NOT TARGET boost_beast_lib_asio_ssl) return() endif () file(GLOB_RECURSE PFILES CONFIGURE_DEPENDS Jamfile *.cpp *.hpp) add_executable(boost_beast_tests_websocket ${PFILES}) source_group("" FILES ${PFILES}) target_link_libraries(boost_beast_tests_websocket boost_beast_lib_asio_ssl boost_beast_lib_test) set_target_properties(boost_beast_tests_websocket PROPERTIES FOLDER "tests") add_test(NAME boost_beast_tests_websocket COMMAND boost_beast_tests_websocket) add_dependencies(tests boost_beast_tests_websocket) ``` -------------------------------- ### Clone Boost Superproject Source: https://github.com/boostorg/beast/blob/develop/README.md To work with the latest official release or preview upcoming changes, clone the Boost superproject. This command recursively clones all subprojects. ```bash git clone --recursive https://github.com/boostorg/boost.git cd boost ``` -------------------------------- ### WebSocket Chat Client Logic Source: https://github.com/boostorg/beast/blob/develop/example/websocket/server/chat-multi/chat_client.html Handles WebSocket connection, message display, and user input for a chat client. Requires a WebSocket-compatible server. ```javascript var ws = null; function showMessage(msg) { messages.innerText += msg + "\n"; messages.scrollTop = messages.scrollHeight - messages.clientHeight; }; connect.onclick = function() { ws = new WebSocket(uri.value); ws.onopen = function(ev) { showMessage("\n[connection opened]\n"); }; ws.onclose = function(ev) { showMessage("\n[connection closed]\n"); }; ws.onmessage = function(ev) { showMessage(ev.data); }; ws.onerror = function(ev) { showMessage("\n[error]\n"); console.log(ev); }; }; disconnect.onclick = function() { ws.close(); }; send.onclick = function() { ws.send(userName.value + ": " + sendMessage.value); sendMessage.value = ""; }; sendMessage.onkeyup = function(ev) { ev.preventDefault(); if (ev.keyCode === 13) { send.click(); } } ``` -------------------------------- ### Thread-Safe Callback Data Handling in http-parser Source: https://github.com/boostorg/beast/blob/develop/test/bench/parser/nodejs-parser/README.md Demonstrates how to use thread-local storage (`parser->data`) to pass data between a thread and http-parser callbacks. This is crucial for multi-threaded applications to maintain thread safety and manage callback-specific data. ```c typedef struct { socket_t sock; void* buffer; int buf_len; } custom_data_t; int my_url_callback(http_parser* parser, const char *at, size_t length) { /* access to thread local custom_data_t struct. Use this access save parsed data for later use into thread local buffer, or communicate over socket */ parser->data; ... return 0; } ... void http_parser_thread(socket_t sock) { int nparsed = 0; /* allocate memory for user data */ custom_data_t *my_data = malloc(sizeof(custom_data_t)); /* some information for use by callbacks. * achieves thread -> callback information flow */ my_data->sock = sock; /* instantiate a thread-local parser */ http_parser *parser = malloc(sizeof(http_parser)); http_parser_init(parser, HTTP_REQUEST); /* initialise parser */ /* this custom data reference is accessible through the reference to the parser supplied to callback functions */ parser->data = my_data; http_parser_settings settings; / * set up callbacks */ settings.on_url = my_url_callback; /* execute parser */ nparsed = http_parser_execute(parser, &settings, buf, recved); ... /* parsed information copied from callback. can now perform action on data copied into thread-local memory from callbacks. achieves callback -> thread information flow */ my_data->buffer; ... } ``` -------------------------------- ### Define Boost.Beast Library Source: https://github.com/boostorg/beast/blob/develop/CMakeLists.txt Defines the Boost.Beast library as an INTERFACE library and creates an alias for it. It also sets include directories, link libraries, and required C++ features. ```cmake add_library(boost_beast INTERFACE) add_library(Boost::beast ALIAS boost_beast) target_include_directories(boost_beast INTERFACE include) target_link_libraries(boost_beast INTERFACE ${BOOST_BEAST_DEPENDENCIES}) target_compile_features(boost_beast INTERFACE cxx_std_11) ``` -------------------------------- ### Handle Boost.Beast Headers Source: https://github.com/boostorg/beast/blob/develop/CMakeLists.txt Conditionally finds and adds Boost.Beast headers if BOOST_BEAST_IS_ROOT is defined. It sets up source groups and targets for these headers. ```cmake if (BOOST_BEAST_IS_ROOT) file(GLOB_RECURSE BOOST_BEAST_HEADERS CONFIGURE_DEPENDS include/boost/*.hpp) set_property(GLOBAL PROPERTY USE_FOLDERS ON) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost PREFIX "" FILES ${BOOST_BEAST_HEADERS}) target_sources(boost_beast PRIVATE ${BOOST_BEAST_HEADERS} build.jam) endif () ``` -------------------------------- ### Register All Boost.Beast Fuzzers Source: https://github.com/boostorg/beast/blob/develop/test/fuzz/CMakeLists.txt This CMake code iterates through all C++ source files in the current directory, extracts a rule name from each file path, and registers a fuzzer for each using the `add_boost_beast_fuzzer` function. ```cmake file(GLOB BOOST_BEAST_FUZZER_SOURCE_FILES *.cpp) source_group("" FILES ${BOOST_BEAST_FUZZER_SOURCE_FILES}) foreach(BOOST_BEAST_FUZZER_SOURCE_FILE ${BOOST_BEAST_FUZZER_SOURCE_FILES}) file(RELATIVE_PATH BOOST_BEAST_FUZZER_SOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR} ${BOOST_BEAST_FUZZER_SOURCE_FILE}) string(REGEX REPLACE "(.*).cpp" "\1" RULE_NAME ${BOOST_BEAST_FUZZER_SOURCE_FILE}) add_boost_beast_fuzzer(${RULE_NAME} ${BOOST_BEAST_FUZZER_SOURCE_FILE}) endforeach() ``` -------------------------------- ### Define Boost.Beast Fuzzer CMake Function Source: https://github.com/boostorg/beast/blob/develop/test/fuzz/CMakeLists.txt This CMake function defines a fuzzer executable, links it with Boost.Beast, sets sanitization options, and creates a custom target to run the fuzzer with specified parameters. It also handles corpus merging and seeding. ```cmake function(add_boost_beast_fuzzer NAME) # Fuzzer executable set(SOURCE_FILES ${ARGN}) add_executable(fuzzer_${NAME} ${SOURCE_FILES}) source_group("" FILES ${SOURCE_FILES}) target_link_libraries(fuzzer_${NAME} PRIVATE boost_beast) target_compile_options(fuzzer_${NAME} PRIVATE -g -O2 -fsanitize=fuzzer,address,undefined -fno-sanitize-recover=undefined) target_link_libraries(fuzzer_${NAME} PRIVATE -fsanitize=fuzzer,address,undefined) set_target_properties(fuzzer_${NAME} PROPERTIES FOLDER "fuzzing") # Custom target to run fuzzer executable add_custom_target( fuzz_${NAME} ALL COMMAND ${CMAKE_COMMAND} -E make_directory ${BOOST_BEAST_FUZZER_CORPUS_DIR}/${NAME} COMMAND ${CMAKE_COMMAND} -E echo "Running fuzzer ${NAME} with corpus from ${BOOST_BEAST_FUZZER_CORPUS_DIR}/${NAME} and seeds from ${BOOST_BEAST_FUZZER_SEEDS_DIR}/${NAME}" COMMAND fuzzer_${NAME} -rss_limit_mb=${BOOST_BEAST_FUZZER_RSS_LIMIT} -max_total_time=${BOOST_BEAST_FUZZER_TOTAL_TIME} -timeout=${BOOST_BEAST_FUZZER_TIMEOUT} -max_len=${BOOST_BEAST_FUZZER_MAX_LEN} -jobs=${BOOST_BEAST_FUZZER_JOBS} ${BOOST_BEAST_FUZZER_CORPUS_DIR}/${NAME} ${BOOST_BEAST_FUZZER_SEEDS_DIR}/${NAME} COMMAND ${CMAKE_COMMAND} -E make_directory ${BOOST_BEAST_FUZZER_MERGED_CORPUS_DIR}/${NAME} COMMAND ${CMAKE_COMMAND} -E echo "Merging corpus from ${BOOST_BEAST_FUZZER_CORPUS_DIR}/${NAME} to ${BOOST_BEAST_FUZZER_MERGED_CORPUS_DIR}/${NAME}" COMMAND fuzzer_${NAME} -merge=1 ${BOOST_BEAST_FUZZER_MERGED_CORPUS_DIR}/${NAME} ${BOOST_BEAST_FUZZER_CORPUS_DIR}/${NAME} ${BOOST_BEAST_FUZZER_SEEDS_DIR}/${NAME} COMMAND ${CMAKE_COMMAND} -E echo "Replacing corpus in ${BOOST_BEAST_FUZZER_CORPUS_DIR}/${NAME} with merged corpus from ${BOOST_BEAST_FUZZER_MERGED_CORPUS_DIR}/${NAME}" COMMAND ${CMAKE_COMMAND} -E remove_directory ${BOOST_BEAST_FUZZER_CORPUS_DIR}/${NAME} COMMAND ${CMAKE_COMMAND} -E make_directory ${BOOST_BEAST_FUZZER_CORPUS_DIR}/${NAME} COMMAND ${CMAKE_COMMAND} -E copy_directory ${BOOST_BEAST_FUZZER_MERGED_CORPUS_DIR}/${NAME} ${BOOST_BEAST_FUZZER_CORPUS_DIR}/${NAME} COMMAND ${CMAKE_COMMAND} -E remove_directory ${BOOST_BEAST_FUZZER_MERGED_CORPUS_DIR}/${NAME} DEPENDS untar_corpus fuzzer_${NAME}) add_dependencies(fuzz_${NAME} fuzzer_${NAME}) add_dependencies(boost_beast_fuzz_all fuzz_${NAME}) set_target_properties(fuzz_${NAME} PROPERTIES ENVIRONMENT "UBSAN_OPTIONS=halt_on_error=false") set_target_properties(fuzz_${NAME} PROPERTIES FOLDER "fuzzing") if (BOOST_BEAST_FUZZER_ADD_TO_CTEST) add_test( NAME test_fuzz_${NAME} COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target fuzz_${NAME}) add_dependencies(tests test_fuzz_${NAME}) endif() endfunction() ``` -------------------------------- ### Conditional Boost Dependency Find Source: https://github.com/boostorg/beast/blob/develop/test/cmake_test/CMakeLists.txt Finds the Boost.Beast library configuration. This is used in CI environments to ensure the correct Boost version is found. ```cmake if(BOOST_CI_INSTALL_TEST) find_package(Boost CONFIG REQUIRED COMPONENTS beast) else() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) add_subdirectory(../.. boostorg/beast) set(BOOST_BEAST_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(deps # Primary dependencies asio assert bind config container container_hash core endian intrusive logic mp11 optional smart_ptr static_string system throw_exception type_index type_traits winapi # Secondary dependencies align context date_time move describe utility compat variant2 predef pool algorithm io lexical_cast numeric/conversion range tokenizer preprocessor array concept_check exception function iterator mpl regex tuple unordered conversion integer detail fusion function_types typeof ) foreach(dep IN LISTS deps) add_subdirectory(../../../${dep} boostorg/${dep} EXCLUDE_FROM_ALL) endforeach() endif() ``` -------------------------------- ### Conditionally Add SSL Subdirectory Source: https://github.com/boostorg/beast/blob/develop/example/doc/CMakeLists.txt Adds the 'ssl' subdirectory to the build if OpenSSL is found. This is a common pattern for enabling optional features based on system dependencies. ```cmake if (OPENSSL_FOUND) add_subdirectory(ssl) endif () ``` -------------------------------- ### HTTP Parser Callback Signatures Source: https://github.com/boostorg/beast/blob/develop/test/bench/parser/nodejs-parser/README.md Defines the function signatures for HTTP parser callbacks. Notification callbacks return an int, while data callbacks receive a pointer to the data and its length. ```c typedef int (*http_cb) (http_parser*); typedef int (*http_data_cb) (http_parser*, const char *at, size_t length); ``` -------------------------------- ### Execute HTTP Parser with Received Data Source: https://github.com/boostorg/beast/blob/develop/test/bench/parser/nodejs-parser/README.md Executes the HTTP parser with incoming data from a socket. Handles potential errors and signals EOF by passing 0 for the data length. ```c size_t len = 80*1024, nparsed; char buf[len]; ssize_t recved; recved = recv(fd, buf, len, 0); if (recved < 0) { /* Handle error. */ } /* Start up / continue the parser. * Note we pass recved==0 to signal that EOF has been received. */ nparsed = http_parser_execute(parser, &settings, buf, recved); if (parser->upgrade) { /* handle new protocol */ } else if (nparsed != recved) { /* Handle error. Usually just close the connection. */ } ``` -------------------------------- ### Include Test Subdirectory Source: https://github.com/boostorg/beast/blob/develop/CMakeLists.txt Conditionally includes the test subdirectory if BOOST_BEAST_BUILD_TESTS is defined, enabling the build of tests. ```cmake if (BOOST_BEAST_BUILD_TESTS) add_subdirectory(test) endif () ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.