webserver: work around a potential crash bug in libmicrohttpd 0.9.x
authormontellese <montellese@xbmc.org>
Wed, 27 Feb 2013 09:16:44 +0000 (10:16 +0100)
committermontellese <montellese@xbmc.org>
Fri, 1 Mar 2013 11:36:25 +0000 (12:36 +0100)
As observed and investigated by ulion, libmicrohttpd 0.9.x can cause crashes
on specific platforms (e.g. iOS) when using a MHD_USE_SELECT_INTERNALLY in
combination with a thread pool (MHD_OPTION_THREAD_POOL_SIZE) because of non-
copyable mutex structures.
See https://gnunet.org/bugs/view.php?id=2803 for the bug report.

xbmc/network/WebServer.cpp

index 35102d9..71ce952 100644 (file)
@@ -541,20 +541,27 @@ void CWebServer::ContentReaderFreeCallback(void *cls)
 
 struct MHD_Daemon* CWebServer::StartMHD(unsigned int flags, int port)
 {
-  // WARNING: when using MHD_USE_THREAD_PER_CONNECTION, set MHD_OPTION_CONNECTION_TIMEOUT to something higher than 1
-  // otherwise on libmicrohttpd 0.4.4-1 it spins a busy loop
-
   unsigned int timeout = 60 * 60 * 24;
-  // MHD_USE_THREAD_PER_CONNECTION = one thread per connection
-  // MHD_USE_SELECT_INTERNALLY = use main thread for each connection, can only handle one request at a time [unless you set the thread pool size]
 
-  return MHD_start_daemon(flags,
+  return MHD_start_daemon(flags |
+#if (MHD_VERSION >= 0x00040002) && (MHD_VERSION < 0x00090B01)
+                          // use main thread for each connection, can only handle one request at a
+                          // time [unless you set the thread pool size]
+                          MHD_USE_SELECT_INTERNALLY
+#else
+                          // one thread per connection
+                          // WARNING: set MHD_OPTION_CONNECTION_TIMEOUT to something higher than 1
+                          // otherwise on libmicrohttpd 0.4.4-1 it spins a busy loop
+                          MHD_USE_THREAD_PER_CONNECTION
+#endif
+                          ,
                           port,
                           NULL,
                           NULL,
                           &CWebServer::AnswerToConnection,
                           this,
-#if (MHD_VERSION >= 0x00040002)
+
+#if (MHD_VERSION >= 0x00040002) && (MHD_VERSION < 0x00090B01)
                           MHD_OPTION_THREAD_POOL_SIZE, 4,
 #endif
                           MHD_OPTION_CONNECTION_LIMIT, 512,
@@ -568,7 +575,7 @@ bool CWebServer::Start(int port, const string &username, const string &password)
   SetCredentials(username, password);
   if (!m_running)
   {
-    m_daemon = StartMHD(MHD_USE_SELECT_INTERNALLY, port);
+    m_daemon = StartMHD(, port);
 
     m_running = m_daemon != NULL;
     if (m_running)