Skip to content

Commit

Permalink
WebServer: add and use panic handler for MHD
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlson2k committed Mar 4, 2015
1 parent a74f0c6 commit 16d14a2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions xbmc/network/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifdef HAS_WEB_SERVER
#include <memory>
#include <algorithm>
#include <stdexcept>

#include "URL.h"
#include "Util.h"
Expand Down Expand Up @@ -1035,6 +1036,14 @@ void CWebServer::ContentReaderFreeCallback(void *cls)
#endif
}

// local helper
static void panicHandlerForMHD(void* unused, const char* file, unsigned int line, const char *reason)
{
CLog::Log(LOGSEVERE, "CWebServer: MHD serious error: reason \"%s\" in file \"%s\" at line %ui", reason ? reason : "",
file ? file : "", line);
throw std::runtime_error("MHD serious error"); // FIXME: better solution?
}

// local helper
static void logFromMHD(void* unused, const char* fmt, va_list ap)
{
Expand All @@ -1060,6 +1069,10 @@ struct MHD_Daemon* CWebServer::StartMHD(unsigned int flags, int port)
{
unsigned int timeout = 60 * 60 * 24;

#if MHD_VERSION >= 0x00040500
MHD_set_panic_func(&panicHandlerForMHD, NULL);
#endif

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
Expand Down

0 comments on commit 16d14a2

Please sign in to comment.