X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fhttp%2Fhttpthread.cpp;h=23154392a47108c244e2a5ff4259c8317a628822;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=89edc931cfb884ddaf85e585738a08d1fae6abef;hpb=023b2219068d481cd6a300982427c99bacd88a12;p=fms.git diff --git a/src/http/httpthread.cpp b/src/http/httpthread.cpp index 89edc93..2315439 100644 --- a/src/http/httpthread.cpp +++ b/src/http/httpthread.cpp @@ -16,37 +16,52 @@ HTTPThread::HTTPThread() { m_listenport=8080; - std::string portstr; - Option::Instance()->Get("HTTPListenPort",portstr); - StringFunctions::Convert(portstr,m_listenport); } void HTTPThread::run() { m_log->debug("HTTPThread::run thread started."); - 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); + LoadDatabase(); + Option option(m_db); + + std::string portstr("8080"); + option.Get("HTTPListenPort",portstr); + StringFunctions::Convert(portstr,m_listenport); + + 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); + + srv.start(); + m_log->trace("Started HTTPServer"); - srv.start(); - m_log->trace("Started HTTPServer"); + do + { + Poco::Thread::sleep(1000); + }while(!IsCancelled()); - do + 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); + } + } + catch(Poco::Exception &e) { - 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) + m_log->fatal("HTTPThread::run caught "+e.displayText()); + } + catch(...) { - Poco::Thread::sleep(500); + m_log->fatal("HTTPThread::run caught unknown exception"); } m_log->debug("HTTPThread::run thread exiting.");