yhttpd: cleaner shutdown

This commit is contained in:
Stefan Seyfried
2013-05-09 16:19:55 +02:00
parent a58cd405d8
commit 363633dc1b

View File

@@ -104,6 +104,15 @@ void yhttpd_reload_config() {
//-----------------------------------------------------------------------------
// Main Entry
//-----------------------------------------------------------------------------
void thread_cleanup (void *p)
{
Cyhttpd *y = (Cyhttpd *)p;
if (y)
delete y;
y = NULL;
}
#ifndef Y_CONFIG_BUILD_AS_DAEMON
void * nhttpd_main_thread(void *) {
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
@@ -116,6 +125,8 @@ void * nhttpd_main_thread(void *) {
aprintf("Error initializing WebServer\n");
return (void *) EXIT_FAILURE;
}
/* we pthread_cancel this thread from the main thread, but still want to clean up */
pthread_cleanup_push(thread_cleanup, yhttpd);
yhttpd->flag_threading_off = true;
yhttpd->hooks_attach();
@@ -127,7 +138,9 @@ void * nhttpd_main_thread(void *) {
yhttpd->run();
}
pthread_cleanup_pop(0);
delete yhttpd;
yhttpd = NULL;
aprintf("Main end\n");
return (void *) EXIT_SUCCESS;
@@ -233,8 +246,10 @@ Cyhttpd::Cyhttpd() {
}
//-----------------------------------------------------------------------------
Cyhttpd::~Cyhttpd() {
stop_webserver();
if (webserver)
delete webserver;
CLanguage::deleteInstance();
webserver = NULL;
}