From 1bad204afa253c1bfe4021bf3e93bd06a05b9aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Fri, 8 Nov 2024 17:46:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=AC=D1=83=D1=82=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BF=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 16 +- build/conan.lock | 21 +- build/conanbuildinfo.cmake | 18 +- build/conanbuildinfo.txt | 20 +- build/conaninfo.txt | 7 +- build/graph_info.json | 14 +- conanfile.txt | 2 +- src/main.cpp | 387 ++++++++++++++++++++++++++++++++++++- 8 files changed, 416 insertions(+), 69 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1175ea2..31c931e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,30 +1,18 @@ cmake_minimum_required(VERSION 3.11) -# Проект называется Hello и написан на C++ -project(Hello CXX) -# Исходый код будет компилироваться с поддержкой стандарта С++ 20 +project(App CXX) set(CMAKE_CXX_STANDARD 20) -# Подключаем сгенерированный скрипт conanbuildinfo.cmake, созданный Conan include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -# Выполняем макрос из conanbuildinfo.cmake, который настроит СMake на работу с библиотеками, установленными Conan conan_basic_setup() -# Ищем Boost версии 1.78 -find_package(Boost 1.78.0 REQUIRED) +find_package(Boost 1.84.0 REQUIRED) if(Boost_FOUND) - # Boost найден, добавляем к каталогам заголовочных файлов проекта путь к - # заголовочным файлам Boost include_directories(${Boost_INCLUDE_DIRS}) endif() -# Платформы вроде linux требуют подключения библиотеки pthread для -# поддержки стандартных потоков. -# Следующие две строки подключат эту библиотеку на таких платформах set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -# Проект содержит единственный исходный файл src/main.cpp add_executable(application src/main.cpp) -# Просим компоновщик подключить библиотеку для поддержки потоков target_link_libraries(application PRIVATE Threads::Threads) \ No newline at end of file diff --git a/build/conan.lock b/build/conan.lock index 49108a0..fccafc1 100644 --- a/build/conan.lock +++ b/build/conan.lock @@ -2,7 +2,7 @@ "graph_lock": { "nodes": { "0": { - "options": "boost:asio_no_deprecated=False\nboost:buildid=None\nboost:bzip2=True\nboost:debug_level=0\nboost:diagnostic_definitions=False\nboost:error_code_header_only=False\nboost:extra_b2_flags=None\nboost:filesystem_no_deprecated=False\nboost:filesystem_use_std_fs=False\nboost:filesystem_version=None\nboost:header_only=False\nboost:i18n_backend=deprecated\nboost:i18n_backend_iconv=off\nboost:i18n_backend_icu=False\nboost:layout=system\nboost:lzma=False\nboost:magic_autolink=False\nboost:multithreading=True\nboost:namespace=boost\nboost:namespace_alias=False\nboost:numa=True\nboost:pch=True\nboost:python_executable=None\nboost:python_version=None\nboost:segmented_stacks=False\nboost:shared=False\nboost:system_no_deprecated=False\nboost:system_use_utf8=False\nboost:visibility=hidden\nboost:without_atomic=False\nboost:without_chrono=False\nboost:without_container=False\nboost:without_context=False\nboost:without_contract=False\nboost:without_coroutine=False\nboost:without_date_time=False\nboost:without_exception=False\nboost:without_fiber=False\nboost:without_filesystem=False\nboost:without_graph=False\nboost:without_graph_parallel=True\nboost:without_iostreams=False\nboost:without_json=False\nboost:without_locale=False\nboost:without_log=False\nboost:without_math=False\nboost:without_mpi=True\nboost:without_nowide=False\nboost:without_program_options=False\nboost:without_python=True\nboost:without_random=False\nboost:without_regex=False\nboost:without_serialization=False\nboost:without_stacktrace=False\nboost:without_system=False\nboost:without_test=False\nboost:without_thread=False\nboost:without_timer=False\nboost:without_type_erasure=False\nboost:without_wave=False\nboost:zlib=True\nboost:zstd=False\nbzip2:build_executable=True\nbzip2:shared=False\nzlib:shared=False", + "options": "boost:asio_no_deprecated=False\nboost:buildid=None\nboost:bzip2=True\nboost:debug_level=0\nboost:diagnostic_definitions=False\nboost:error_code_header_only=False\nboost:extra_b2_flags=None\nboost:filesystem_no_deprecated=False\nboost:filesystem_use_std_fs=False\nboost:filesystem_version=None\nboost:header_only=False\nboost:i18n_backend=deprecated\nboost:i18n_backend_iconv=off\nboost:i18n_backend_icu=False\nboost:layout=system\nboost:lzma=False\nboost:magic_autolink=False\nboost:multithreading=True\nboost:namespace=boost\nboost:namespace_alias=False\nboost:pch=True\nboost:python_executable=None\nboost:python_version=None\nboost:segmented_stacks=False\nboost:shared=False\nboost:system_no_deprecated=False\nboost:system_use_utf8=False\nboost:visibility=hidden\nboost:without_atomic=False\nboost:without_chrono=False\nboost:without_cobalt=True\nboost:without_container=False\nboost:without_context=False\nboost:without_contract=False\nboost:without_coroutine=False\nboost:without_date_time=False\nboost:without_exception=False\nboost:without_fiber=True\nboost:without_filesystem=False\nboost:without_graph=False\nboost:without_graph_parallel=True\nboost:without_iostreams=False\nboost:without_json=False\nboost:without_locale=False\nboost:without_log=False\nboost:without_math=False\nboost:without_mpi=True\nboost:without_nowide=False\nboost:without_program_options=False\nboost:without_python=True\nboost:without_random=False\nboost:without_regex=False\nboost:without_serialization=False\nboost:without_stacktrace=False\nboost:without_system=False\nboost:without_test=False\nboost:without_thread=False\nboost:without_timer=False\nboost:without_type_erasure=False\nboost:without_url=False\nboost:without_wave=False\nboost:zlib=True\nboost:zstd=False\nbzip2:build_executable=True\nbzip2:shared=False\nzlib:shared=False", "requires": [ "1" ], @@ -10,18 +10,14 @@ "context": "host" }, "1": { - "ref": "boost/1.78.0", - "options": "asio_no_deprecated=False\nbuildid=None\nbzip2=True\ndebug_level=0\ndiagnostic_definitions=False\nerror_code_header_only=False\nextra_b2_flags=None\nfilesystem_no_deprecated=False\nfilesystem_use_std_fs=False\nfilesystem_version=None\nheader_only=False\ni18n_backend=deprecated\ni18n_backend_iconv=off\ni18n_backend_icu=False\nlayout=system\nlzma=False\nmagic_autolink=False\nmultithreading=True\nnamespace=boost\nnamespace_alias=False\nnuma=True\npch=True\npython_executable=None\npython_version=None\nsegmented_stacks=False\nshared=False\nsystem_no_deprecated=False\nsystem_use_utf8=False\nvisibility=hidden\nwithout_atomic=False\nwithout_chrono=False\nwithout_container=False\nwithout_context=False\nwithout_contract=False\nwithout_coroutine=False\nwithout_date_time=False\nwithout_exception=False\nwithout_fiber=False\nwithout_filesystem=False\nwithout_graph=False\nwithout_graph_parallel=True\nwithout_iostreams=False\nwithout_json=False\nwithout_locale=False\nwithout_log=False\nwithout_math=False\nwithout_mpi=True\nwithout_nowide=False\nwithout_program_options=False\nwithout_python=True\nwithout_random=False\nwithout_regex=False\nwithout_serialization=False\nwithout_stacktrace=False\nwithout_system=False\nwithout_test=False\nwithout_thread=False\nwithout_timer=False\nwithout_type_erasure=False\nwithout_wave=False\nzlib=True\nzstd=False\nbzip2:build_executable=True\nbzip2:shared=False\nzlib:shared=False", - "package_id": "9122dbc53b72d49447592b7c1471ee184105ccbd", + "ref": "boost/1.84.0", + "options": "asio_no_deprecated=False\nbuildid=None\nbzip2=True\ndebug_level=0\ndiagnostic_definitions=False\nerror_code_header_only=False\nextra_b2_flags=None\nfilesystem_no_deprecated=False\nfilesystem_use_std_fs=False\nfilesystem_version=None\nheader_only=False\ni18n_backend=deprecated\ni18n_backend_iconv=off\ni18n_backend_icu=False\nlayout=system\nlzma=False\nmagic_autolink=False\nmultithreading=True\nnamespace=boost\nnamespace_alias=False\npch=True\npython_executable=None\npython_version=None\nsegmented_stacks=False\nshared=False\nsystem_no_deprecated=False\nsystem_use_utf8=False\nvisibility=hidden\nwithout_atomic=False\nwithout_chrono=False\nwithout_cobalt=True\nwithout_container=False\nwithout_context=False\nwithout_contract=False\nwithout_coroutine=False\nwithout_date_time=False\nwithout_exception=False\nwithout_fiber=True\nwithout_filesystem=False\nwithout_graph=False\nwithout_graph_parallel=True\nwithout_iostreams=False\nwithout_json=False\nwithout_locale=False\nwithout_log=False\nwithout_math=False\nwithout_mpi=True\nwithout_nowide=False\nwithout_program_options=False\nwithout_python=True\nwithout_random=False\nwithout_regex=False\nwithout_serialization=False\nwithout_stacktrace=False\nwithout_system=False\nwithout_test=False\nwithout_thread=False\nwithout_timer=False\nwithout_type_erasure=False\nwithout_url=False\nwithout_wave=False\nzlib=True\nzstd=False\nbzip2:build_executable=True\nbzip2:shared=False\nzlib:shared=False", + "package_id": "e50863e182b9f1a9ce9e711c031065f1fe5f7f78", "prev": "0", - "modified": true, "requires": [ "2", "3" ], - "build_requires": [ - "4" - ], "context": "host" }, "2": { @@ -29,7 +25,6 @@ "options": "shared=False", "package_id": "5a61a86bb3e07ce4262c80e1510f9c05e9b6d48b", "prev": "0", - "modified": true, "context": "host" }, "3": { @@ -37,14 +32,6 @@ "options": "build_executable=True\nshared=False", "package_id": "53b5fd22ba061620078deefdae9a437c5f693201", "prev": "0", - "modified": true, - "context": "host" - }, - "4": { - "ref": "b2/5.2.1", - "options": "toolset=auto\nuse_cxx_env=False", - "package_id": "ca33edce272a279b24f87dc0d4cf5bbdcffbc187", - "prev": "0", "context": "host" } }, diff --git a/build/conanbuildinfo.cmake b/build/conanbuildinfo.cmake index 83c8a7c..8dfc863 100644 --- a/build/conanbuildinfo.cmake +++ b/build/conanbuildinfo.cmake @@ -38,16 +38,16 @@ endmacro() ################# ### BOOST ################# -set(CONAN_BOOST_ROOT "C:/.conan/5d244f/1") -set(CONAN_INCLUDE_DIRS_BOOST "C:/.conan/5d244f/1/include") -set(CONAN_LIB_DIRS_BOOST "C:/.conan/5d244f/1/lib") +set(CONAN_BOOST_ROOT "C:/.conan/029ec3/1") +set(CONAN_INCLUDE_DIRS_BOOST "C:/.conan/029ec3/1/include") +set(CONAN_LIB_DIRS_BOOST "C:/.conan/029ec3/1/lib") set(CONAN_BIN_DIRS_BOOST ) set(CONAN_RES_DIRS_BOOST ) set(CONAN_SRC_DIRS_BOOST ) set(CONAN_BUILD_DIRS_BOOST ) set(CONAN_FRAMEWORK_DIRS_BOOST ) -set(CONAN_LIBS_BOOST libboost_contract libboost_coroutine libboost_fiber_numa libboost_fiber libboost_context libboost_graph libboost_iostreams libboost_json libboost_locale libboost_log_setup libboost_log libboost_math_c99 libboost_math_c99f libboost_math_c99l libboost_math_tr1 libboost_math_tr1f libboost_math_tr1l libboost_nowide libboost_program_options libboost_random libboost_regex libboost_stacktrace_noop libboost_stacktrace_windbg libboost_stacktrace_windbg_cached libboost_timer libboost_type_erasure libboost_thread libboost_chrono libboost_container libboost_date_time libboost_unit_test_framework libboost_prg_exec_monitor libboost_test_exec_monitor libboost_exception libboost_wave libboost_filesystem libboost_atomic libboost_wserialization libboost_serialization) -set(CONAN_PKG_LIBS_BOOST libboost_contract libboost_coroutine libboost_fiber_numa libboost_fiber libboost_context libboost_graph libboost_iostreams libboost_json libboost_locale libboost_log_setup libboost_log libboost_math_c99 libboost_math_c99f libboost_math_c99l libboost_math_tr1 libboost_math_tr1f libboost_math_tr1l libboost_nowide libboost_program_options libboost_random libboost_regex libboost_stacktrace_noop libboost_stacktrace_windbg libboost_stacktrace_windbg_cached libboost_timer libboost_type_erasure libboost_thread libboost_chrono libboost_container libboost_date_time libboost_unit_test_framework libboost_prg_exec_monitor libboost_test_exec_monitor libboost_exception libboost_wave libboost_filesystem libboost_atomic libboost_wserialization libboost_serialization) +set(CONAN_LIBS_BOOST libboost_contract libboost_coroutine libboost_context libboost_graph libboost_iostreams libboost_json libboost_locale libboost_log_setup libboost_log libboost_math_c99 libboost_math_c99f libboost_math_c99l libboost_math_tr1 libboost_math_tr1f libboost_math_tr1l libboost_nowide libboost_program_options libboost_random libboost_regex libboost_stacktrace_noop libboost_stacktrace_windbg libboost_stacktrace_windbg_cached libboost_timer libboost_type_erasure libboost_thread libboost_chrono libboost_container libboost_date_time libboost_unit_test_framework libboost_prg_exec_monitor libboost_test_exec_monitor libboost_exception libboost_url libboost_wave libboost_filesystem libboost_atomic libboost_wserialization libboost_serialization) +set(CONAN_PKG_LIBS_BOOST libboost_contract libboost_coroutine libboost_context libboost_graph libboost_iostreams libboost_json libboost_locale libboost_log_setup libboost_log libboost_math_c99 libboost_math_c99f libboost_math_c99l libboost_math_tr1 libboost_math_tr1f libboost_math_tr1l libboost_nowide libboost_program_options libboost_random libboost_regex libboost_stacktrace_noop libboost_stacktrace_windbg libboost_stacktrace_windbg_cached libboost_timer libboost_type_erasure libboost_thread libboost_chrono libboost_container libboost_date_time libboost_unit_test_framework libboost_prg_exec_monitor libboost_test_exec_monitor libboost_exception libboost_url libboost_wave libboost_filesystem libboost_atomic libboost_wserialization libboost_serialization) set(CONAN_SYSTEM_LIBS_BOOST ole32 dbgeng bcrypt ntdll shell32 Advapi32 user32) set(CONAN_FRAMEWORKS_BOOST ) set(CONAN_FRAMEWORKS_FOUND_BOOST "") # Will be filled later @@ -177,17 +177,17 @@ set(CONAN_CMD_SHARED_LINKER_FLAGS ${CONAN_SHARED_LINKER_FLAGS}) set(CONAN_CMD_C_FLAGS ${CONAN_C_FLAGS}) # Defining accumulated conan variables for all deps -set(CONAN_INCLUDE_DIRS "C:/.conan/5d244f/1/include" +set(CONAN_INCLUDE_DIRS "C:/.conan/029ec3/1/include" "C:/Users/Антон/.conan/data/zlib/1.3.1/_/_/package/5a61a86bb3e07ce4262c80e1510f9c05e9b6d48b/include" "C:/Users/Антон/.conan/data/bzip2/1.0.8/_/_/package/53b5fd22ba061620078deefdae9a437c5f693201/include" ${CONAN_INCLUDE_DIRS}) -set(CONAN_LIB_DIRS "C:/.conan/5d244f/1/lib" +set(CONAN_LIB_DIRS "C:/.conan/029ec3/1/lib" "C:/Users/Антон/.conan/data/zlib/1.3.1/_/_/package/5a61a86bb3e07ce4262c80e1510f9c05e9b6d48b/lib" "C:/Users/Антон/.conan/data/bzip2/1.0.8/_/_/package/53b5fd22ba061620078deefdae9a437c5f693201/lib" ${CONAN_LIB_DIRS}) set(CONAN_BIN_DIRS "C:/Users/Антон/.conan/data/bzip2/1.0.8/_/_/package/53b5fd22ba061620078deefdae9a437c5f693201/bin" ${CONAN_BIN_DIRS}) set(CONAN_RES_DIRS ${CONAN_RES_DIRS}) set(CONAN_FRAMEWORK_DIRS ${CONAN_FRAMEWORK_DIRS}) -set(CONAN_LIBS libboost_contract libboost_coroutine libboost_fiber_numa libboost_fiber libboost_context libboost_graph libboost_iostreams libboost_json libboost_locale libboost_log_setup libboost_log libboost_math_c99 libboost_math_c99f libboost_math_c99l libboost_math_tr1 libboost_math_tr1f libboost_math_tr1l libboost_nowide libboost_program_options libboost_random libboost_regex libboost_stacktrace_noop libboost_stacktrace_windbg libboost_stacktrace_windbg_cached libboost_timer libboost_type_erasure libboost_thread libboost_chrono libboost_container libboost_date_time libboost_unit_test_framework libboost_prg_exec_monitor libboost_test_exec_monitor libboost_exception libboost_wave libboost_filesystem libboost_atomic libboost_wserialization libboost_serialization zlib bz2 ${CONAN_LIBS}) -set(CONAN_PKG_LIBS libboost_contract libboost_coroutine libboost_fiber_numa libboost_fiber libboost_context libboost_graph libboost_iostreams libboost_json libboost_locale libboost_log_setup libboost_log libboost_math_c99 libboost_math_c99f libboost_math_c99l libboost_math_tr1 libboost_math_tr1f libboost_math_tr1l libboost_nowide libboost_program_options libboost_random libboost_regex libboost_stacktrace_noop libboost_stacktrace_windbg libboost_stacktrace_windbg_cached libboost_timer libboost_type_erasure libboost_thread libboost_chrono libboost_container libboost_date_time libboost_unit_test_framework libboost_prg_exec_monitor libboost_test_exec_monitor libboost_exception libboost_wave libboost_filesystem libboost_atomic libboost_wserialization libboost_serialization zlib bz2 ${CONAN_PKG_LIBS}) +set(CONAN_LIBS libboost_contract libboost_coroutine libboost_context libboost_graph libboost_iostreams libboost_json libboost_locale libboost_log_setup libboost_log libboost_math_c99 libboost_math_c99f libboost_math_c99l libboost_math_tr1 libboost_math_tr1f libboost_math_tr1l libboost_nowide libboost_program_options libboost_random libboost_regex libboost_stacktrace_noop libboost_stacktrace_windbg libboost_stacktrace_windbg_cached libboost_timer libboost_type_erasure libboost_thread libboost_chrono libboost_container libboost_date_time libboost_unit_test_framework libboost_prg_exec_monitor libboost_test_exec_monitor libboost_exception libboost_url libboost_wave libboost_filesystem libboost_atomic libboost_wserialization libboost_serialization zlib bz2 ${CONAN_LIBS}) +set(CONAN_PKG_LIBS libboost_contract libboost_coroutine libboost_context libboost_graph libboost_iostreams libboost_json libboost_locale libboost_log_setup libboost_log libboost_math_c99 libboost_math_c99f libboost_math_c99l libboost_math_tr1 libboost_math_tr1f libboost_math_tr1l libboost_nowide libboost_program_options libboost_random libboost_regex libboost_stacktrace_noop libboost_stacktrace_windbg libboost_stacktrace_windbg_cached libboost_timer libboost_type_erasure libboost_thread libboost_chrono libboost_container libboost_date_time libboost_unit_test_framework libboost_prg_exec_monitor libboost_test_exec_monitor libboost_exception libboost_url libboost_wave libboost_filesystem libboost_atomic libboost_wserialization libboost_serialization zlib bz2 ${CONAN_PKG_LIBS}) set(CONAN_SYSTEM_LIBS ole32 dbgeng bcrypt ntdll shell32 Advapi32 user32 ${CONAN_SYSTEM_LIBS}) set(CONAN_FRAMEWORKS ${CONAN_FRAMEWORKS}) set(CONAN_FRAMEWORKS_FOUND "") # Will be filled later diff --git a/build/conanbuildinfo.txt b/build/conanbuildinfo.txt index b355245..e5c8a36 100644 --- a/build/conanbuildinfo.txt +++ b/build/conanbuildinfo.txt @@ -1,10 +1,10 @@ [includedirs] -C:/.conan/5d244f/1/include +C:/.conan/029ec3/1/include C:/Users/Антон/.conan/data/zlib/1.3.1/_/_/package/5a61a86bb3e07ce4262c80e1510f9c05e9b6d48b/include C:/Users/Антон/.conan/data/bzip2/1.0.8/_/_/package/53b5fd22ba061620078deefdae9a437c5f693201/include [libdirs] -C:/.conan/5d244f/1/lib +C:/.conan/029ec3/1/lib C:/Users/Антон/.conan/data/zlib/1.3.1/_/_/package/5a61a86bb3e07ce4262c80e1510f9c05e9b6d48b/lib C:/Users/Антон/.conan/data/bzip2/1.0.8/_/_/package/53b5fd22ba061620078deefdae9a437c5f693201/lib @@ -21,8 +21,6 @@ C:/Users/Антон/.conan/data/bzip2/1.0.8/_/_/package/53b5fd22ba061620078deefd [libs] libboost_contract libboost_coroutine -libboost_fiber_numa -libboost_fiber libboost_context libboost_graph libboost_iostreams @@ -53,6 +51,7 @@ libboost_unit_test_framework libboost_prg_exec_monitor libboost_test_exec_monitor libboost_exception +libboost_url libboost_wave libboost_filesystem libboost_atomic @@ -102,10 +101,10 @@ BOOST_ALL_NO_LIB [includedirs_boost] -C:/.conan/5d244f/1/include +C:/.conan/029ec3/1/include [libdirs_boost] -C:/.conan/5d244f/1/lib +C:/.conan/029ec3/1/lib [bindirs_boost] @@ -119,8 +118,6 @@ C:/.conan/5d244f/1/lib [libs_boost] libboost_contract libboost_coroutine -libboost_fiber_numa -libboost_fiber libboost_context libboost_graph libboost_iostreams @@ -151,6 +148,7 @@ libboost_unit_test_framework libboost_prg_exec_monitor libboost_test_exec_monitor libboost_exception +libboost_url libboost_wave libboost_filesystem libboost_atomic @@ -197,13 +195,13 @@ BOOST_ALL_NO_LIB [rootpath_boost] -C:/.conan/5d244f/1 +C:/.conan/029ec3/1 [name_boost] boost [version_boost] -1.78.0 +1.84.0 [generatornames_boost] cmake_find_package=Boost @@ -349,7 +347,7 @@ stacktrace_addr2line_available=False [USER_bzip2] [USER_zlib] [ENV_boost] -BOOST_ROOT=C:\.conan\5d244f\1 +BOOST_ROOT=C:\.conan\029ec3\1 [ENV_zlib] [ENV_bzip2] PATH=["C:\Users\Антон\.conan\data\bzip2\1.0.8\_\_\package\53b5fd22ba061620078deefdae9a437c5f693201\bin"] \ No newline at end of file diff --git a/build/conaninfo.txt b/build/conaninfo.txt index a341de3..ec4a285 100644 --- a/build/conaninfo.txt +++ b/build/conaninfo.txt @@ -23,7 +23,7 @@ os_build=Windows [full_requires] - boost/1.78.0:9122dbc53b72d49447592b7c1471ee184105ccbd + boost/1.84.0:e50863e182b9f1a9ce9e711c031065f1fe5f7f78 bzip2/1.0.8:53b5fd22ba061620078deefdae9a437c5f693201 zlib/1.3.1:5a61a86bb3e07ce4262c80e1510f9c05e9b6d48b @@ -48,7 +48,6 @@ boost:multithreading=True boost:namespace=boost boost:namespace_alias=False - boost:numa=True boost:pch=True boost:python_executable=None boost:python_version=None @@ -59,13 +58,14 @@ boost:visibility=hidden boost:without_atomic=False boost:without_chrono=False + boost:without_cobalt=True boost:without_container=False boost:without_context=False boost:without_contract=False boost:without_coroutine=False boost:without_date_time=False boost:without_exception=False - boost:without_fiber=False + boost:without_fiber=True boost:without_filesystem=False boost:without_graph=False boost:without_graph_parallel=True @@ -87,6 +87,7 @@ boost:without_thread=False boost:without_timer=False boost:without_type_erasure=False + boost:without_url=False boost:without_wave=False boost:zlib=True boost:zstd=False diff --git a/build/graph_info.json b/build/graph_info.json index e5e6ab1..d6c677b 100644 --- a/build/graph_info.json +++ b/build/graph_info.json @@ -80,10 +80,6 @@ "boost:namespace_alias", "False" ], - [ - "boost:numa", - "True" - ], [ "boost:pch", "True" @@ -124,6 +120,10 @@ "boost:without_chrono", "False" ], + [ + "boost:without_cobalt", + "True" + ], [ "boost:without_container", "False" @@ -150,7 +150,7 @@ ], [ "boost:without_fiber", - "False" + "True" ], [ "boost:without_filesystem", @@ -236,6 +236,10 @@ "boost:without_type_erasure", "False" ], + [ + "boost:without_url", + "False" + ], [ "boost:without_wave", "False" diff --git a/conanfile.txt b/conanfile.txt index 2c6fad0..af38618 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,5 +1,5 @@ [requires] -boost/1.78.0 +boost/1.84.0 [generators] cmake diff --git a/src/main.cpp b/src/main.cpp index 5871fe3..1793c58 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,14 +1,383 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include +#include +#include +#include +#include -using namespace std; -using namespace boost; +namespace beast = boost::beast; +namespace http = beast::http; +namespace net = boost::asio; +using tcp = boost::asio::ip::tcp; -int main() +beast::string_view +mime_type(beast::string_view path) { - optional opt_string = "Hello, World!"s; - - cout << opt_string.value() << endl; - - return 0; + using beast::iequals; + auto const ext = [&path] + { + auto const pos = path.rfind("."); + if (pos == beast::string_view::npos) + return beast::string_view {}; + return path.substr(pos); + }(); + if (iequals(ext, ".htm")) return "text/html"; + if (iequals(ext, ".html")) return "text/html"; + if (iequals(ext, ".php")) return "text/html"; + if (iequals(ext, ".css")) return "text/css"; + if (iequals(ext, ".txt")) return "text/plain"; + if (iequals(ext, ".js")) return "application/javascript"; + if (iequals(ext, ".json")) return "application/json"; + if (iequals(ext, ".xml")) return "application/xml"; + if (iequals(ext, ".swf")) return "application/x-shockwave-flash"; + if (iequals(ext, ".flv")) return "video/x-flv"; + if (iequals(ext, ".png")) return "image/png"; + if (iequals(ext, ".jpe")) return "image/jpeg"; + if (iequals(ext, ".jpeg")) return "image/jpeg"; + if (iequals(ext, ".jpg")) return "image/jpeg"; + if (iequals(ext, ".gif")) return "image/gif"; + if (iequals(ext, ".bmp")) return "image/bmp"; + if (iequals(ext, ".ico")) return "image/vnd.microsoft.icon"; + if (iequals(ext, ".tiff")) return "image/tiff"; + if (iequals(ext, ".tif")) return "image/tiff"; + if (iequals(ext, ".svg")) return "image/svg+xml"; + if (iequals(ext, ".svgz")) return "image/svg+xml"; + return "application/text"; } + +std::string +path_cat( + beast::string_view base, + beast::string_view path) +{ + if (base.empty()) + return std::string(path); + std::string result(base); +#ifdef BOOST_MSVC + char constexpr path_separator = '\\'; + if (result.back() == path_separator) + result.resize(result.size() - 1); + result.append(path.data(), path.size()); + for (auto& c: result) + if (c == '/') + c = path_separator; +#else + char constexpr path_separator = '/'; + if(result.back() == path_separator) + result.resize(result.size() - 1); + result.append(path.data(), path.size()); +#endif + return result; +} + +template +http::message_generator +handle_request( + beast::string_view doc_root, + http::request>&& req) +{ + auto const bad_request = + [&req](beast::string_view why) + { + http::response res {http::status::bad_request, req.version()}; + res.set(http::field::server, BOOST_BEAST_VERSION_STRING); + res.set(http::field::content_type, "text/html"); + res.keep_alive(req.keep_alive()); + res.body() = std::string(why); + res.prepare_payload(); + return res; + }; + + auto const not_found = + [&req](beast::string_view target) + { + http::response res {http::status::not_found, req.version()}; + res.set(http::field::server, BOOST_BEAST_VERSION_STRING); + res.set(http::field::content_type, "text/html"); + res.keep_alive(req.keep_alive()); + res.body() = "The resource '" + std::string(target) + "' was not found."; + res.prepare_payload(); + return res; + }; + + auto const server_error = + [&req](beast::string_view what) + { + http::response res {http::status::internal_server_error, req.version()}; + res.set(http::field::server, BOOST_BEAST_VERSION_STRING); + res.set(http::field::content_type, "text/html"); + res.keep_alive(req.keep_alive()); + res.body() = "An error occurred: '" + std::string(what) + "'"; + res.prepare_payload(); + return res; + }; + + if (req.method() != http::verb::get && + req.method() != http::verb::head) + return bad_request("Unknown HTTP-method"); + + if (req.target().empty() || + req.target()[0] != '/' || + req.target().find("..") != beast::string_view::npos) + return bad_request("Illegal request-target"); + + std::string path = path_cat(doc_root, req.target()); + if (req.target().back() == '/') + path.append("index.html"); + + beast::error_code ec; + http::file_body::value_type body; + body.open(path.c_str(), beast::file_mode::scan, ec); + + if (ec == beast::errc::no_such_file_or_directory) + return not_found(req.target()); + + if (ec) + return server_error(ec.message()); + + auto const size = body.size(); + + if (req.method() == http::verb::head) + { + http::response res {http::status::ok, req.version()}; + res.set(http::field::server, BOOST_BEAST_VERSION_STRING); + res.set(http::field::content_type, mime_type(path)); + res.content_length(size); + res.keep_alive(req.keep_alive()); + return res; + } + + http::response res { + std::piecewise_construct, + std::make_tuple(std::move(body)), + std::make_tuple(http::status::ok, req.version())}; + res.set(http::field::server, BOOST_BEAST_VERSION_STRING); + res.set(http::field::content_type, mime_type(path)); + res.content_length(size); + res.keep_alive(req.keep_alive()); + return res; +} + +void +fail(beast::error_code ec, char const* what) +{ + std::cerr << what << ": " << ec.message() << "\n"; +} + +class session : public std::enable_shared_from_this +{ + beast::tcp_stream stream_; + beast::flat_buffer buffer_; + std::shared_ptr doc_root_; + http::request req_; + + public: + session( + tcp::socket&& socket, + std::shared_ptr const& doc_root) + : stream_(std::move(socket)), doc_root_(doc_root) + { + } + + void + run() + { + net::dispatch(stream_.get_executor(), + beast::bind_front_handler( + &session::do_read, + shared_from_this())); + } + + void + do_read() + { + req_ = {}; + + stream_.expires_after(std::chrono::seconds(30)); + + http::async_read(stream_, buffer_, req_, + beast::bind_front_handler( + &session::on_read, + shared_from_this())); + } + + void + on_read( + beast::error_code ec, + std::size_t bytes_transferred) + { + boost::ignore_unused(bytes_transferred); + + if (ec == http::error::end_of_stream) + return do_close(); + + if (ec) + return fail(ec, "read"); + + send_response( + handle_request(*doc_root_, std::move(req_))); + } + + void + send_response(http::message_generator&& msg) + { + bool keep_alive = msg.keep_alive(); + + beast::async_write( + stream_, + std::move(msg), + beast::bind_front_handler( + &session::on_write, shared_from_this(), keep_alive)); + } + + void + on_write( + bool keep_alive, + beast::error_code ec, + std::size_t bytes_transferred) + { + boost::ignore_unused(bytes_transferred); + + if (ec) + return fail(ec, "write"); + + if (!keep_alive) + { + return do_close(); + } + + do_read(); + } + + void + do_close() + { + beast::error_code ec; + stream_.socket().shutdown(tcp::socket::shutdown_send, ec); + + } +}; + +class listener : public std::enable_shared_from_this +{ + net::io_context& ioc_; + tcp::acceptor acceptor_; + std::shared_ptr doc_root_; + + public: + listener( + net::io_context& ioc, + tcp::endpoint endpoint, + std::shared_ptr const& doc_root) + : ioc_(ioc), acceptor_(net::make_strand(ioc)), doc_root_(doc_root) + { + beast::error_code ec; + + acceptor_.open(endpoint.protocol(), ec); + if (ec) + { + fail(ec, "open"); + return; + } + + acceptor_.set_option(net::socket_base::reuse_address(true), ec); + if (ec) + { + fail(ec, "set_option"); + return; + } + + acceptor_.bind(endpoint, ec); + if (ec) + { + fail(ec, "bind"); + return; + } + + acceptor_.listen( + net::socket_base::max_listen_connections, ec); + if (ec) + { + fail(ec, "listen"); + return; + } + } + + void + run() + { + do_accept(); + } + + private: + void + do_accept() + { + acceptor_.async_accept( + net::make_strand(ioc_), + beast::bind_front_handler( + &listener::on_accept, + shared_from_this())); + } + + void + on_accept(beast::error_code ec, tcp::socket socket) + { + if (ec) + { + fail(ec, "accept"); + return; + } + else + { + std::make_shared( + std::move(socket), + doc_root_)->run(); + } + + do_accept(); + } +}; + +int main(int argc, char* argv[]) +{ + if (argc != 5) + { + std::cerr << + "Usage: http-server-async
\n" << + "Example:\n" << + " http-server-async 0.0.0.0 8080 . 1\n"; + return EXIT_FAILURE; + } + auto const address = net::ip::make_address(argv[1]); + auto const port = static_cast(std::atoi(argv[2])); + auto const doc_root = std::make_shared(argv[3]); + auto const threads = std::max(1, std::atoi(argv[4])); + + net::io_context ioc {threads}; + + std::make_shared( + ioc, + tcp::endpoint {address, port}, + doc_root)->run(); + + std::vector v; + v.reserve(threads - 1); + for (auto i = threads - 1; i > 0; --i) + v.emplace_back( + [&ioc] + { + ioc.run(); + }); + ioc.run(); + + return EXIT_SUCCESS; +} \ No newline at end of file