From 82a65d347e084d5bcaf329c5f09c7f93d73f044d Mon Sep 17 00:00:00 2001 From: Sergey Linev <S.Linev@gsi.de> Date: Fri, 26 Jun 2015 08:26:50 +0200 Subject: [PATCH] http: more clear way to detect error during server start Signed-off-by: Bertrand Bellenot <bertrand.bellenot@cern.ch> --- net/http/inc/TCivetweb.h | 5 +--- net/http/src/TCivetweb.cxx | 55 +++++++++----------------------------- 2 files changed, 14 insertions(+), 46 deletions(-) diff --git a/net/http/inc/TCivetweb.h b/net/http/inc/TCivetweb.h index 846748e44c8..326acda4329 100644 --- a/net/http/inc/TCivetweb.h +++ b/net/http/inc/TCivetweb.h @@ -14,10 +14,7 @@ protected: void *fCallbacks; //! call-back table for civetweb webserver TString fTopName; //! name of top item Bool_t fDebug; //! debug mode - Bool_t fStartError; //! error during server start - static TCivetweb* fTemp; //! temporary static pointer, used to deliver messages only when starting server - Int_t ProcessLog(const char* message); public: TCivetweb(); virtual ~TCivetweb(); @@ -36,7 +33,7 @@ public: return fDebug; } - static Int_t ProcessLogMessage(void *instance, const char* message); + Int_t ProcessLog(const char* message); ClassDef(TCivetweb, 0) // http server implementation, based on civetweb embedded server }; diff --git a/net/http/src/TCivetweb.cxx b/net/http/src/TCivetweb.cxx index 6128a7c632f..01e5b598ea1 100644 --- a/net/http/src/TCivetweb.cxx +++ b/net/http/src/TCivetweb.cxx @@ -11,11 +11,17 @@ #include "THttpServer.h" #include "TUrl.h" -TCivetweb* TCivetweb::fTemp = 0; - static int log_message_handler(const struct mg_connection *conn, const char *message) { - return TCivetweb::ProcessLogMessage(mg_get_request_info((struct mg_connection *)conn)->user_data, message); + TCivetweb* engine = (TCivetweb*) mg_get_request_info((struct mg_connection *)conn)->user_data; + + if (engine) return engine->ProcessLog(message); + + // provide debug output + if ((gDebug>0) || (strstr(message,"cannot bind to")!=0)) + fprintf(stderr, "Error in <TCivetweb::Log> %s\n",message); + + return 0; } @@ -191,8 +197,7 @@ TCivetweb::TCivetweb() : fCtx(0), fCallbacks(0), fTopName(), - fDebug(kFALSE), - fStartError(kFALSE) + fDebug(kFALSE) { // constructor } @@ -208,39 +213,12 @@ TCivetweb::~TCivetweb() fCallbacks = 0; } -//______________________________________________________________________________ -Int_t TCivetweb::ProcessLogMessage(void *instance, const char* message) -{ - // static method to process log messages from civetweb server - // introduced to resolve civetweb problem, that messages cannot be delivered directly - // during mg_start() call - - TCivetweb* engine = (TCivetweb*) instance; - - if (engine==0) engine = fTemp; - - if (engine) return engine->ProcessLog(message); - - // provide debug output - if (gDebug>0) printf("<TCivetweb::Log> %s\n",message); - - return 0; -} - //______________________________________________________________________________ Int_t TCivetweb::ProcessLog(const char* message) { - // process civetweb log message, used to detect critical errors + // process civetweb log message, can be used to detect critical errors - Bool_t critical = kFALSE; - - if ((strstr(message,"cannot bind to")!=0) && - (strstr(message,"(Address already in use)")!=0)) { - fStartError = kTRUE; - critical = kTRUE; - } - - if (critical || (gDebug>0)) Error("Log", "%s", message); + if (gDebug>0) Error("Log", "%s", message); return 0; } @@ -331,16 +309,9 @@ Bool_t TCivetweb::Create(const char *args) options[op++] = 0; - // workaround for civetweb - if (fTemp==0) fTemp = this; - // Start the web server. fCtx = mg_start((struct mg_callbacks *) fCallbacks, this, options); - if (fTemp==this) fTemp = 0; - - if (fStartError) return kFALSE; - - return kTRUE; + return fCtx != 0; } -- GitLab