From ee0b81848fd88be2ee736f5f11d4da502b2b6b3d Mon Sep 17 00:00:00 2001 From: m8mble Date: Tue, 7 Mar 2023 00:54:04 +0100 Subject: [PATCH] Add nghttp2-asio port (#29714) The nghttp2_asio library was formerly part of nghttp2 but by now is distributed as separate library. --- .../0001-Fix-exception-in-server.patch | 45 +++++++++++++++++++ .../0002-Honor-BUILD_SHARED_LIBS.patch | 26 +++++++++++ ports/nghttp2-asio/portfile.cmake | 40 +++++++++++++++++ ports/nghttp2-asio/vcpkg.json | 41 +++++++++++++++++ versions/baseline.json | 4 ++ versions/n-/nghttp2-asio.json | 9 ++++ 6 files changed, 165 insertions(+) create mode 100644 ports/nghttp2-asio/0001-Fix-exception-in-server.patch create mode 100644 ports/nghttp2-asio/0002-Honor-BUILD_SHARED_LIBS.patch create mode 100644 ports/nghttp2-asio/portfile.cmake create mode 100644 ports/nghttp2-asio/vcpkg.json create mode 100644 versions/n-/nghttp2-asio.json diff --git a/ports/nghttp2-asio/0001-Fix-exception-in-server.patch b/ports/nghttp2-asio/0001-Fix-exception-in-server.patch new file mode 100644 index 00000000000..b8ddb253e4f --- /dev/null +++ b/ports/nghttp2-asio/0001-Fix-exception-in-server.patch @@ -0,0 +1,45 @@ +From b4745aa3d87916c7d3da33c00da400b22a0539b5 Mon Sep 17 00:00:00 2001 +From: m8mble +Date: Fri, 20 Jan 2023 16:36:30 +0100 +Subject: [PATCH 1/1] Fix exception in server + +It can happen that a connection handler calls writefun when the +connection is already destroyed. This causes bad_weak_ptr exceptions +thrown from the server. + +Fix this issue by skipping the respective do_write invocations. + +Signed-off-by: m8mble +--- + lib/asio_server_connection.h | 13 ++++++++++++- + 1 file changed, 12 insertions(+), 1 deletion(-) + +diff --git a/lib/asio_server_connection.h b/lib/asio_server_connection.h +index a948965..94ed59f 100644 +--- a/lib/asio_server_connection.h ++++ b/lib/asio_server_connection.h +@@ -88,9 +88,20 @@ public: + void start() { + boost::system::error_code ec; + ++ auto make_writefun = [original_self = this->shared_from_this()] { ++ return [weak = std::weak_ptr{original_self}]() { ++ auto self = weak.lock(); ++ // If connection already got destroyed, the socket is already closed in particular. ++ // Therefore we can simply ignore further calls to write. ++ if (self) { ++ self->do_write(); ++ } ++ }; ++ }; ++ + handler_ = std::make_shared( + GET_IO_SERVICE(socket_), socket_.lowest_layer().remote_endpoint(ec), +- [this]() { do_write(); }, mux_); ++ make_writefun(), mux_); + if (handler_->start() != 0) { + stop(); + return; +-- +2.39.1 + diff --git a/ports/nghttp2-asio/0002-Honor-BUILD_SHARED_LIBS.patch b/ports/nghttp2-asio/0002-Honor-BUILD_SHARED_LIBS.patch new file mode 100644 index 00000000000..c74b57c4337 --- /dev/null +++ b/ports/nghttp2-asio/0002-Honor-BUILD_SHARED_LIBS.patch @@ -0,0 +1,26 @@ +From c68e0a22f8a96ceb5011aa09c4ad93d26c31dc0c Mon Sep 17 00:00:00 2001 +From: m8mble +Date: Fri, 24 Feb 2023 11:36:19 +0100 +Subject: [PATCH 1/1] Honor BUILD_SHARED_LIBS + +Signed-off-by: m8mble +--- + lib/CMakeLists.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt +index ee8f87d..0a67c14 100644 +--- a/lib/CMakeLists.txt ++++ b/lib/CMakeLists.txt +@@ -36,7 +36,7 @@ set(NGHTTP2_ASIO_SOURCES + asio_client_tls_context.cc + ) + +-add_library(nghttp2_asio SHARED ++add_library(nghttp2_asio + ${NGHTTP2_ASIO_SOURCES} + $ + ) +-- +2.39.1 + diff --git a/ports/nghttp2-asio/portfile.cmake b/ports/nghttp2-asio/portfile.cmake new file mode 100644 index 00000000000..123afacdc73 --- /dev/null +++ b/ports/nghttp2-asio/portfile.cmake @@ -0,0 +1,40 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO nghttp2/nghttp2-asio + REF e877868abe06a83ed0a6ac6e245c07f6f20866b5 + SHA512 ed9112d8062dc624cb954c6b4366f79e1e4a8c814a12c9f428a3da882127895b6ea0ff82a3660469c2bef29e3dea906ad9127faa46df773e00ed93b8c7c31d9c + PATCHES + 0001-Fix-exception-in-server.patch + 0002-Honor-BUILD_SHARED_LIBS.patch +) + +string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" ENABLE_STATIC_CRT) +string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" ENABLE_STATIC_LIB) +string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" ENABLE_SHARED_LIB) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + "-DENABLE_STATIC_CRT=${ENABLE_STATIC_CRT}" + "-DENABLE_STATIC_LIB=${ENABLE_STATIC_LIB}" + "-DENABLE_SHARED_LIB=${ENABLE_SHARED_LIB}" +) +vcpkg_cmake_install() +vcpkg_copy_pdbs() +vcpkg_fixup_pkgconfig() + +file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" + "${CURRENT_PACKAGES_DIR}/share/man" + "${CURRENT_PACKAGES_DIR}/share/doc" +) + +if(VCPKG_LIBRARY_LINKAGE STREQUAL static) + file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/bin" + "${CURRENT_PACKAGES_DIR}/debug/bin" + ) +endif() + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING") diff --git a/ports/nghttp2-asio/vcpkg.json b/ports/nghttp2-asio/vcpkg.json new file mode 100644 index 00000000000..f85bfd8f85d --- /dev/null +++ b/ports/nghttp2-asio/vcpkg.json @@ -0,0 +1,41 @@ +{ + "name": "nghttp2-asio", + "version-date": "2022-08-11", + "description": "High level abstraction API to build HTTP/2 applications with nghttp2 and boost asio.", + "homepage": "https://github.com/nghttp2/nghttp2-asio", + "license": "MIT", + "supports": "!windows", + "dependencies": [ + { + "name": "boost-asio", + "version>=": "1.81.0" + }, + "boost-system", + "boost-thread", + { + "name": "nghttp2", + "version>=": "1.51.0" + }, + { + "name": "vcpkg-cmake", + "host": true + } + ], + "default-features": [ + "tls" + ], + "features": { + "tls": { + "description": "Support HTTP/2 over TLS aka h2.", + "dependencies": [ + { + "name": "boost-asio", + "features": [ + "ssl" + ] + }, + "openssl" + ] + } + } +} diff --git a/versions/baseline.json b/versions/baseline.json index 1e9a7f4701c..d04d3ffbcc0 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -5412,6 +5412,10 @@ "baseline": "1.51.0", "port-version": 1 }, + "nghttp2-asio": { + "baseline": "2022-08-11", + "port-version": 0 + }, "nghttp3": { "baseline": "0.9.0", "port-version": 0 diff --git a/versions/n-/nghttp2-asio.json b/versions/n-/nghttp2-asio.json new file mode 100644 index 00000000000..40f58ac1c8b --- /dev/null +++ b/versions/n-/nghttp2-asio.json @@ -0,0 +1,9 @@ +{ + "versions": [ + { + "git-tree": "a2ef24d2428ea9d1a4cb733d3e4ce00e3f6f5c8d", + "port-version": 0, + "version-date": "2022-08-11" + } + ] +}