changeset 3178:6d558598d713

Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Jan 2019 12:41:20 +0100
parents 053e72ff9fc5
children fca730c267d7
files Core/HttpServer/HttpOutput.cpp Core/HttpServer/HttpServer.cpp NEWS Resources/CMake/CivetwebConfiguration.cmake
diffstat 4 files changed, 45 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutput.cpp	Wed Jan 30 10:24:12 2019 +0100
+++ b/Core/HttpServer/HttpOutput.cpp	Wed Jan 30 12:41:20 2019 +0100
@@ -46,6 +46,13 @@
 #include <boost/lexical_cast.hpp>
 
 
+#if ORTHANC_ENABLE_CIVETWEB == 1
+#  if !defined(CIVETWEB_HAS_DISABLE_KEEP_ALIVE)
+#    error Macro CIVETWEB_HAS_DISABLE_KEEP_ALIVE must be defined
+#  endif
+#endif
+
+
 namespace Orthanc
 {
   HttpOutput::StateMachine::StateMachine(IHttpOutputStream& stream,
@@ -432,11 +439,22 @@
       throw OrthancException(ErrorCode_NotImplemented,
                              "Multipart answers are not implemented together "
                              "with keep-alive connections if using Mongoose");
-#else
+      
+#elif ORTHANC_ENABLE_CIVETWEB == 1
+#  if CIVETWEB_HAS_DISABLE_KEEP_ALIVE == 1
       // Turn off Keep-Alive for multipart answers
       // https://github.com/civetweb/civetweb/issues/727
       stream_.DisableKeepAlive();
       header += "Connection: close\r\n";
+#  else
+      // The function "mg_disable_keep_alive()" is not available,
+      // let's continue with Keep-Alive. Performance of WADO-RS will
+      // decrease.
+      header += "Connection: keep-alive\r\n";
+#  endif   
+
+#else
+#  error Please support your embedded Web server here
 #endif
     }
     else
--- a/Core/HttpServer/HttpServer.cpp	Wed Jan 30 10:24:12 2019 +0100
+++ b/Core/HttpServer/HttpServer.cpp	Wed Jan 30 12:41:20 2019 +0100
@@ -47,6 +47,9 @@
 #elif ORTHANC_ENABLE_CIVETWEB == 1
 #  include <civetweb.h>
 #  define MONGOOSE_USE_CALLBACKS 1
+#  if !defined(CIVETWEB_HAS_DISABLE_KEEP_ALIVE)
+#    error Macro CIVETWEB_HAS_DISABLE_KEEP_ALIVE must be defined
+#  endif
 
 #else
 #  error "Either Mongoose or Civetweb must be enabled to compile this file"
@@ -114,8 +117,18 @@
 #if ORTHANC_ENABLE_MONGOOSE == 1
         throw OrthancException(ErrorCode_NotImplemented,
                                "Only available if using CivetWeb");
+
 #elif ORTHANC_ENABLE_CIVETWEB == 1
+#  if CIVETWEB_HAS_DISABLE_KEEP_ALIVE == 1
         mg_disable_keep_alive(connection_);
+#  else
+#       warning The function "mg_disable_keep_alive()" is not available, DICOMweb might run slowly
+        throw OrthancException(ErrorCode_NotImplemented,
+                               "Only available if using a patched version of CivetWeb");
+#  endif
+
+#else
+#  error Please support your embedded Web server here
 #endif
       }
     };
--- a/NEWS	Wed Jan 30 10:24:12 2019 +0100
+++ b/NEWS	Wed Jan 30 12:41:20 2019 +0100
@@ -13,6 +13,11 @@
 * New URI "/tools/metrics" to dynamically enable/disable the collection of metrics
 * New URI "/tools/metrics-prometheus" to retrieve metrics using Prometheus text format
 
+Maintenance
+-----------
+
+* Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
+
 
 Version 1.5.3 (2019-01-25)
 ==========================
--- a/Resources/CMake/CivetwebConfiguration.cmake	Wed Jan 30 10:24:12 2019 +0100
+++ b/Resources/CMake/CivetwebConfiguration.cmake	Wed Jan 30 12:41:20 2019 +0100
@@ -47,6 +47,10 @@
 
   source_group(ThirdParty\\Civetweb REGULAR_EXPRESSION ${CIVETWEB_SOURCES_DIR}/.*)
 
+  add_definitions(
+    -DCIVETWEB_HAS_DISABLE_KEEP_ALIVE=1
+    )
+
 else()
   CHECK_INCLUDE_FILE_CXX(civetweb.h HAVE_CIVETWEB_H)
   if (NOT HAVE_CIVETWEB_H)
@@ -61,4 +65,8 @@
   endif()
 
   link_libraries(civetweb)
+
+  add_definitions(
+    -DCIVETWEB_HAS_DISABLE_KEEP_ALIVE=0
+    )
 endif()