// registerHandler("/", &index);
// registerHandler("/foo", &foo);
// registerHandler("/foo/<bar>/<baz>", &foobarbaz);
-void WebServer::registerHandler(const string& url, HandlerFunction *handler)
+void WebServer::registerHandler(const string& url, HandlerFunction handler)
{
std::size_t pos = 0, lastpos = 0;
continue;
}
- *handler = reg->handler;
+ *handler = ®->handler;
return true;
}
}
return false;
}
-void WebServer::setCaller(void *that)
-{
- d_that=that;
-}
-
static void *WebServerConnectionThreadStart(void *p) {
connectionThreadData* data = static_cast<connectionThreadData*>(p);
pthread_detach(pthread_self());
map<string, string> urlArgs;
if (route(baseUrl, urlArgs, &handler)) {
bool custom=false;
- string ret=(*handler)(method, post, varmap, d_that, &custom);
+ string ret=(*handler)(method, post, varmap, &custom);
if(!custom) {
client->putLine("HTTP/1.1 200 OK\n");
return (boost::format("%.01f%%") % val).str();
}
-string StatWebServer::indexfunction(const string& method, const string& post, const map<string,string> &varmap, void *ptr, bool *custom)
+string StatWebServer::indexfunction(const string& method, const string& post, const map<string,string> &varmap, bool *custom)
{
- StatWebServer *sws=static_cast<StatWebServer *>(ptr);
map<string,string>rvarmap=varmap;
if(!rvarmap["resetring"].empty()){
*custom=true;
"<br>"<<endl;
ret<<"Queries/second, 1, 5, 10 minute averages: "<<std::setprecision(3)<<
- sws->d_queries.get1()<<", "<<
- sws->d_queries.get5()<<", "<<
- sws->d_queries.get10()<<". Max queries/second: "<<sws->d_queries.getMax()<<
+ d_queries.get1()<<", "<<
+ d_queries.get5()<<", "<<
+ d_queries.get10()<<". Max queries/second: "<<d_queries.getMax()<<
"<br>"<<endl;
- if(sws->d_cachemisses.get10()+sws->d_cachehits.get10()>0)
+ if(d_cachemisses.get10()+d_cachehits.get10()>0)
ret<<"Cache hitrate, 1, 5, 10 minute averages: "<<
- makePercentage((sws->d_cachehits.get1()*100.0)/((sws->d_cachehits.get1())+(sws->d_cachemisses.get1())))<<", "<<
- makePercentage((sws->d_cachehits.get5()*100.0)/((sws->d_cachehits.get5())+(sws->d_cachemisses.get5())))<<", "<<
- makePercentage((sws->d_cachehits.get10()*100.0)/((sws->d_cachehits.get10())+(sws->d_cachemisses.get10())))<<
+ makePercentage((d_cachehits.get1()*100.0)/((d_cachehits.get1())+(d_cachemisses.get1())))<<", "<<
+ makePercentage((d_cachehits.get5()*100.0)/((d_cachehits.get5())+(d_cachemisses.get5())))<<", "<<
+ makePercentage((d_cachehits.get10()*100.0)/((d_cachehits.get10())+(d_cachemisses.get10())))<<
"<br>"<<endl;
- if(sws->d_qcachemisses.get10()+sws->d_qcachehits.get10()>0)
+ if(d_qcachemisses.get10()+d_qcachehits.get10()>0)
ret<<"Backend query cache hitrate, 1, 5, 10 minute averages: "<<std::setprecision(2)<<
- makePercentage((sws->d_qcachehits.get1()*100.0)/((sws->d_qcachehits.get1())+(sws->d_qcachemisses.get1())))<<", "<<
- makePercentage((sws->d_qcachehits.get5()*100.0)/((sws->d_qcachehits.get5())+(sws->d_qcachemisses.get5())))<<", "<<
- makePercentage((sws->d_qcachehits.get10()*100.0)/((sws->d_qcachehits.get10())+(sws->d_qcachemisses.get10())))<<
+ makePercentage((d_qcachehits.get1()*100.0)/((d_qcachehits.get1())+(d_qcachemisses.get1())))<<", "<<
+ makePercentage((d_qcachehits.get5()*100.0)/((d_qcachehits.get5())+(d_qcachemisses.get5())))<<", "<<
+ makePercentage((d_qcachehits.get10()*100.0)/((d_qcachehits.get10())+(d_qcachemisses.get10())))<<
"<br>"<<endl;
ret<<"Backend query load, 1, 5, 10 minute averages: "<<std::setprecision(3)<<
- sws->d_qcachemisses.get1()<<", "<<
- sws->d_qcachemisses.get5()<<", "<<
- sws->d_qcachemisses.get10()<<". Max queries/second: "<<sws->d_qcachemisses.getMax()<<
+ d_qcachemisses.get1()<<", "<<
+ d_qcachemisses.get5()<<", "<<
+ d_qcachemisses.get10()<<". Max queries/second: "<<d_qcachemisses.getMax()<<
"<br>"<<endl;
ret<<"Total queries: "<<S.read("udp-queries")<<". Question/answer latency: "<<S.read("latency")/1000.0<<"ms</p><br>"<<endl;
for(vector<string>::const_iterator i=entries.begin();i!=entries.end();++i)
printtable(ret,*i,S.getRingTitle(*i));
- sws->printvars(ret);
+ printvars(ret);
if(arg().mustDo("webserver-print-arguments"))
- sws->printargs(ret);
+ printargs(ret);
}
else
printtable(ret,rvarmap["ring"],S.getRingTitle(rvarmap["ring"]),100);
return returnJSONError("No or unknown command given");
}
-string StatWebServer::jsonstat(const string& method, const string& post, const map<string,string> &varmap, void *ptr, bool *custom)
+string StatWebServer::jsonstat(const string& method, const string& post, const map<string,string> &varmap, bool *custom)
{
*custom=1; // indicates we build the response
string ret="HTTP/1.1 200 OK\r\n"
return ret;
}
-string StatWebServer::cssfunction(const string& method, const string& post, const map<string,string> &varmap, void *ptr, bool *custom)
+string StatWebServer::cssfunction(const string& method, const string& post, const map<string,string> &varmap, bool *custom)
{
*custom=1; // indicates we build the response
ostringstream ret;
void StatWebServer::launch()
{
try {
- d_ws->setCaller(this);
- d_ws->registerHandler("/",&indexfunction);
- d_ws->registerHandler("/style.css",&cssfunction);
+ d_ws->registerHandler("/", boost::bind(&StatWebServer::indexfunction, this, _1, _2, _3, _4));
+ d_ws->registerHandler("/style.css", boost::bind(&StatWebServer::cssfunction, this, _1, _2, _3, _4));
if(::arg().mustDo("experimental-json-interface"))
- d_ws->registerHandler("/jsonstat", &jsonstat);
+ d_ws->registerHandler("/jsonstat", boost::bind(&StatWebServer::jsonstat, this, _1, _2, _3, _4));
d_ws->go();
}
catch(...) {
private:
static void *threadHelper(void *);
static void *statThreadHelper(void *p);
- static string indexfunction(const string& method, const string& post, const map<string,string> &varmap, void *ptr, bool *custom);
- static string cssfunction(const string& method, const string& post, const map<string,string> &varmap, void *ptr, bool *custom);
- static string jsonstat(const string& method, const string& post, const map<string,string> &varmap, void *ptr, bool *custom);
+ string indexfunction(const string& method, const string& post, const map<string,string> &varmap, bool *custom);
+ string cssfunction(const string& method, const string& post, const map<string,string> &varmap, bool *custom);
+ string jsonstat(const string& method, const string& post, const map<string,string> &varmap, bool *custom);
void printvars(ostringstream &ret);
void printargs(ostringstream &ret);
void launch();