整理代码
This commit is contained in:
commit
c7b4e178ec
364 changed files with 59691 additions and 0 deletions
53
network/HTTPServer.cpp
Normal file
53
network/HTTPServer.cpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue