X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fhttp%2Fhttpthread.cpp;h=89edc931cfb884ddaf85e585738a08d1fae6abef;hb=023b2219068d481cd6a300982427c99bacd88a12;hp=dd4bd9b731a685f2d0696bc1c3ee1144462e4a87;hpb=d8ccfe2b3944adf07d35534459cdda19d15217c8;p=fms.git diff --git a/src/http/httpthread.cpp b/src/http/httpthread.cpp index dd4bd9b..89edc93 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,40 @@ HTTPThread::HTTPThread() { - - int port; + m_listenport=8080; 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); - -} - -HTTPThread::~HTTPThread() -{ - shttpd_fini(m_ctx); - - for(std::vector::iterator i=m_pagehandlers.begin(); i!=m_pagehandlers.end(); i++) - { - delete (*i); - } - + StringFunctions::Convert(portstr,m_listenport); } -void HTTPThread::PageCallback(shttpd_arg *arg) +void HTTPThread::run() { + m_log->debug("HTTPThread::run thread started."); - HTTPThread *thread=(HTTPThread *)arg->user_data; - - for(std::vector::iterator i=thread->m_pagehandlers.begin(); i!=thread->m_pagehandlers.end(); ) - { - if((*i)->Handle(arg)==true) - { - i=thread->m_pagehandlers.end(); - } - else - { - i++; - } - } + 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,sock,pParams); -} - -void HTTPThread::Run() -{ - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"HTTPThread::run thread started."); + srv.start(); + m_log->trace("Started HTTPServer"); do { - shttpd_poll(m_ctx,1000); + Poco::Thread::sleep(1000); }while(!IsCancelled()); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"HTTPThread::run thread exiting."); + 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) + { + Poco::Thread::sleep(500); + } + + m_log->debug("HTTPThread::run thread exiting."); }