gespielt mit std::unique_ptr und so...

This commit is contained in:
john stone 2014-01-25 23:32:02 +01:00
parent 7b64cb5b76
commit b4337f73b2
5 changed files with 63 additions and 34 deletions

View File

@ -1,5 +1,7 @@
#pragma once
#include <memory>
#include <mongoose.h>
#include "StaticFileHandler.H"
@ -12,8 +14,8 @@ public:
// const ???
static Routerin * get_instance()
{
static Routerin * me;
if ( ! me->hasInstance )
static Routerin * me = nullptr;
if (!me)
return me = new Routerin();
return me;
}
@ -38,8 +40,8 @@ public:
}
private:
explicit Routerin();
StaticFileHandler && sfh;
bool hasInstance = false;
std::unique_ptr<StaticFileHandler> sfh;
//bool hasInstance = false;
int event_request_route ( struct mg_event *event);
int event_newthread_route ( struct mg_event *event);

View File

@ -14,17 +14,11 @@ using std::endl;
Routerin::Routerin():
sfh( UltraSimpleStaticFileHandler())
sfh( new UltraSimpleStaticFileHandler())
{
cout << "Konstr Routering" << std::endl;
Routerin::hasInstance = true;
}
Routerin::~Routerin()
{
Routerin::hasInstance = false;
}
int Routerin::event_request_route(struct mg_event *event){
const RouterOp *blub=0;
@ -85,7 +79,7 @@ int Routerin::rq_static(char const * const reststr , struct mg_event *event)
{
std::cerr << " a static file is reqested!" << endl;
std::cerr << " path: " << reststr << endl;
sfh.answer_pathreq(reststr,event->conn);
sfh->answer_pathreq(reststr,event->conn);
return 1;
}

View File

@ -6,6 +6,7 @@ class UltraSimpleStaticFileHandler :public StaticFileHandler
public:
virtual ~UltraSimpleStaticFileHandler();
virtual int answer_pathreq(const char * const path, struct mg_connection *conn) override;
UltraSimpleStaticFileHandler(void);
};

View File

@ -22,10 +22,19 @@ static const char * hello_world_html = u8R"HERE(
</body>
</html>)HERE";
UltraSimpleStaticFileHandler::~UltraSimpleStaticFileHandler(){};
#include <iostream>
UltraSimpleStaticFileHandler::UltraSimpleStaticFileHandler()
{
std::cout << "hallo ausm construktor von USSFH [" << this << "] "
<< std::endl;
}
int UltraSimpleStaticFileHandler::answer_pathreq(const char * const path,
UltraSimpleStaticFileHandler::~UltraSimpleStaticFileHandler(){
std::cout << "Arrrr aus destruktor! und (∀Gute) zum Pinguintag!!" << std::endl;
}
int UltraSimpleStaticFileHandler::answer_pathreq(const char * const path __attribute__((unused)),
struct mg_connection *conn)
{
mg_printf(conn, "HTTP/1.0 200 OK\r\n"

View File

@ -2,6 +2,7 @@
#include <cstdio>
#include <cstring>
#include <iostream>
#include <signal.h>
#include <mongoose.h>
@ -102,6 +103,20 @@ bool configfile_parsing_action(int& argc, char **argv)
return true;
}
static void signalhandler(int signum){
switch(signum){
case SIGINT:
exit(0);
break;
default:
std::cout << "called sighandler with signal " << signum << " FUPP! " << std::endl;
}
}
static void exithandlerfunc(){
std::cout << "alles hat ein ende" << std::endl;
}
int main(int argc, char **argv)
{
@ -109,11 +124,19 @@ int main(int argc, char **argv)
std::cerr << "ERROR ERROR BEEP" << std::endl;
exit(1);
}
#ifdef DEBUG
dump_args();
if (std::atexit(&exithandlerfunc))
exit(-4);
#endif
struct sigaction sa;
sa.sa_handler = signalhandler;
sigaction(SIGINT, &sa ,nullptr);
MongooseHandler m(args_info.port_arg);
if (!args_info.daemonize_flag) {
while(1)
getchar();