p26001-store-acs-soc-fw-app/network/HTTPServer.cpp
2026-09-28 21:33:04 +08:00

53 lines
1.4 KiB
C++

/*
*******************************************************************************
* INCLUDE
*******************************************************************************
*/
#include "HTTPServer.h"
using namespace Poco::Net;
namespace Network
{
class RouterRequestHandlerFactory: public HTTPRequestHandlerFactory
{
public:
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) override
{
throw Poco::NotFoundException("Not found");
}
};
/*
*******************************************************************************
* CLASS DEFINE
*******************************************************************************
*/
std::string HTTPServer::HOST = "host";
std::string HTTPServer::PORT = "port";
HTTPServer::HTTPServer(): _pHTTPServer(nullptr)
{
setParameter(HOST, std::string("::"));
setParameter(PORT, 80);
}
HTTPServer::~HTTPServer()
{
}
void HTTPServer::start()
{
Poco::Net::SocketAddress address(getParameter<std::string>(HOST), getParameter<int>(PORT));
Poco::Net::ServerSocket socket(address);
Poco::Net::HTTPServerParams* pParams = new Poco::Net::HTTPServerParams();
pParams->setKeepAlive(false);
_pHTTPServer = new Poco::Net::HTTPServer(new RouterRequestHandlerFactory, socket, pParams);
_pHTTPServer->start();
}
void HTTPServer::stop()
{
_pHTTPServer->stopAll();
}
}