Skip to content
Snippets Groups Projects
Commit 82a65d34 authored by Sergey Linev's avatar Sergey Linev Committed by Bertrand Bellenot
Browse files

http: more clear way to detect error during server start

parent e6ba3df2
No related branches found
No related tags found
No related merge requests found
......@@ -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
};
......
......@@ -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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment