L<<Logger::Error<<"HTTP: Unknown exception"<<endl;
}
-WebServer::WebServer(const string &listenaddress, int port) : d_server(NULL)
+WebServer::WebServer(const string &listenaddress, int port) : d_server(nullptr)
{
d_listenaddress=listenaddress;
d_port=port;
}
catch(NetworkError &e) {
L<<Logger::Error<<"Listening on HTTP socket failed: "<<e.what()<<endl;
- d_server = NULL;
+ d_server = nullptr;
}
}
d_server_socket.bind(d_local);
d_server_socket.listen();
}
+ virtual ~Server() { };
ComboAddress d_local;
{
public:
WebServer(const string &listenaddress, int port);
+ virtual ~WebServer() { };
void bind();
void go();
protected:
void registerBareHandler(const string& url, HandlerFunction handler);
- virtual Server* createServer() {
- return new Server(d_listenaddress, d_port);
+ virtual std::shared_ptr<Server> createServer() {
+ return std::make_shared<Server>(d_listenaddress, d_port);
}
string d_listenaddress;
int d_port;
string d_password;
- Server* d_server;
+ std::shared_ptr<Server> d_server;
};
#endif /* WEBSERVER_HH */
void AsyncWebServer::go() {
if (!d_server)
return;
- ((AsyncServer*)d_server)->asyncWaitForConnections(d_fdm, boost::bind(&AsyncWebServer::serveConnection, this, _1));
+ auto server = std::dynamic_pointer_cast<AsyncServer>(d_server);
+ if (!server)
+ return;
+ server->asyncWaitForConnections(d_fdm, boost::bind(&AsyncWebServer::serveConnection, this, _1));
}
void serveConnection(Socket *socket);
protected:
- virtual Server* createServer() {
- return new AsyncServer(d_listenaddress, d_port);
+ virtual std::shared_ptr<Server> createServer() override {
+ return std::make_shared<AsyncServer>(d_listenaddress, d_port);
};
};