X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fhttp%2Fhttpthread.cpp;h=23154392a47108c244e2a5ff4259c8317a628822;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=dd4bd9b731a685f2d0696bc1c3ee1144462e4a87;hpb=d8ccfe2b3944adf07d35534459cdda19d15217c8;p=fms.git diff --git a/src/http/httpthread.cpp b/src/http/httpthread.cpp index dd4bd9b..2315439 100644 --- a/src/http/httpthread.cpp +++ b/src/http/httpthread.cpp @@ -1,7 +1,11 @@ #include "../../include/http/httpthread.h" +#include "../../include/http/fmshttprequesthandlerfactory.h" #include "../../include/option.h" #include "../../include/stringfunctions.h" -#include "../../include/http/pages/homepage.h" + +#include +#include +#include #include @@ -11,61 +15,55 @@ HTTPThread::HTTPThread() { - - int port; - std::string portstr; - Option::Instance()->Get("HTTPListenPort",portstr); - StringFunctions::Convert(portstr,port); - - m_pagehandlers.push_back(new HomePage()); - - m_ctx=0; - m_ctx=shttpd_init(NULL,"listen_ports",portstr.c_str(),NULL); - shttpd_listen(m_ctx,port,false); - - shttpd_register_uri(m_ctx,"*",HTTPThread::PageCallback,this); - + m_listenport=8080; } -HTTPThread::~HTTPThread() +void HTTPThread::run() { - shttpd_fini(m_ctx); + m_log->debug("HTTPThread::run thread started."); - for(std::vector::iterator i=m_pagehandlers.begin(); i!=m_pagehandlers.end(); i++) - { - delete (*i); - } + LoadDatabase(); + Option option(m_db); -} + std::string portstr("8080"); + option.Get("HTTPListenPort",portstr); + StringFunctions::Convert(portstr,m_listenport); -void HTTPThread::PageCallback(shttpd_arg *arg) -{ + try + { + Poco::Net::ServerSocket sock(m_listenport); + Poco::Net::HTTPServerParams* pParams = new Poco::Net::HTTPServerParams; + pParams->setMaxQueued(30); + pParams->setMaxThreads(5); + Poco::Net::HTTPServer srv(new FMSHTTPRequestHandlerFactory(m_db),sock,pParams); - HTTPThread *thread=(HTTPThread *)arg->user_data; + srv.start(); + m_log->trace("Started HTTPServer"); - for(std::vector::iterator i=thread->m_pagehandlers.begin(); i!=thread->m_pagehandlers.end(); ) - { - if((*i)->Handle(arg)==true) + do { - i=thread->m_pagehandlers.end(); - } - else + Poco::Thread::sleep(1000); + }while(!IsCancelled()); + + m_log->trace("Trying to stop HTTPServer"); + srv.stop(); + m_log->trace("Stopped HTTPServer"); + + m_log->trace("Waiting for current HTTP requests to finish"); + while(srv.currentConnections()>0) { - i++; + Poco::Thread::sleep(500); } } - -} - -void HTTPThread::Run() -{ - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"HTTPThread::run thread started."); - - do + catch(Poco::Exception &e) { - shttpd_poll(m_ctx,1000); - }while(!IsCancelled()); + m_log->fatal("HTTPThread::run caught "+e.displayText()); + } + catch(...) + { + m_log->fatal("HTTPThread::run caught unknown exception"); + } - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"HTTPThread::run thread exiting."); + m_log->debug("HTTPThread::run thread exiting."); }