mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 16:31:11 +02:00
- nhttp: enable threading
This is ported from neutrino-mp and contains code by martii and seife from following commits: 20d3031b8bb47b5af79bf10c385e3564fe5c26dc93d01c1987
363633dc1b
c3e1310a2f727e26ce11669e3aeae78305f87049
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <syscall.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <system/set_threadname.h>
|
||||
// yhttpd
|
||||
#include "yconfig.h"
|
||||
#include <ylogging.h>
|
||||
@@ -105,9 +106,22 @@ void yhttpd_reload_config() {
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main Entry
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void thread_cleanup (void *p)
|
||||
{
|
||||
Cyhttpd *y = (Cyhttpd *)p;
|
||||
if (y) {
|
||||
y->stop_webserver();
|
||||
delete y;
|
||||
}
|
||||
y = NULL;
|
||||
}
|
||||
|
||||
#ifndef Y_CONFIG_BUILD_AS_DAEMON
|
||||
void * nhttpd_main_thread(void *) {
|
||||
set_threadname(__func__);
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
aprintf("Webserver %s tid %ld\n", WEBSERVERNAME, syscall(__NR_gettid));
|
||||
yhttpd = new Cyhttpd();
|
||||
//CLogging::getInstance()->setDebug(true);
|
||||
@@ -116,7 +130,11 @@ 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);
|
||||
#ifndef Y_CONFIG_FEATURE_THREADING
|
||||
yhttpd->flag_threading_off = true;
|
||||
#endif
|
||||
|
||||
yhttpd->hooks_attach();
|
||||
yhttpd->ReadConfig();
|
||||
@@ -127,7 +145,9 @@ void * nhttpd_main_thread(void *) {
|
||||
|
||||
yhttpd->run();
|
||||
}
|
||||
pthread_cleanup_pop(0);
|
||||
delete yhttpd;
|
||||
yhttpd = NULL;
|
||||
|
||||
aprintf("Main end\n");
|
||||
return (void *) EXIT_SUCCESS;
|
||||
@@ -235,6 +255,7 @@ Cyhttpd::Cyhttpd() {
|
||||
Cyhttpd::~Cyhttpd() {
|
||||
if (webserver)
|
||||
delete webserver;
|
||||
CLanguage::deleteInstance();
|
||||
webserver = NULL;
|
||||
}
|
||||
|
||||
@@ -316,6 +337,7 @@ bool Cyhttpd::Configure() {
|
||||
// Main Webserver call
|
||||
//-----------------------------------------------------------------------------
|
||||
void Cyhttpd::run() {
|
||||
set_threadname(__func__);
|
||||
if (webserver) {
|
||||
if (flag_threading_off)
|
||||
webserver->is_threading = false;
|
||||
@@ -439,7 +461,7 @@ void Cyhttpd::ReadConfig(void) {
|
||||
log_level_printf(3, "ReadConfig Start\n");
|
||||
CConfigFile *Config = new CConfigFile(',');
|
||||
bool have_config = false;
|
||||
if (access(HTTPD_CONFIGFILE, 4) == 0)
|
||||
if (access(HTTPD_CONFIGFILE, R_OK) == 0)
|
||||
have_config = true;
|
||||
Config->loadConfig(HTTPD_CONFIGFILE);
|
||||
// convert old config files
|
||||
@@ -527,16 +549,16 @@ void Cyhttpd::ReadConfig(void) {
|
||||
|
||||
// Check location of logos
|
||||
if (Config->getString("Tuxbox.LogosURL", "") == "") {
|
||||
if (access(std::string(ConfigList["WebsiteMain.override_directory"] + "/logos").c_str(), 4) == 0) {
|
||||
if (access(std::string(ConfigList["WebsiteMain.override_directory"] + "/logos").c_str(), R_OK) == 0) {
|
||||
Config->setString("Tuxbox.LogosURL", ConfigList["WebsiteMain.override_directory"] + "/logos");
|
||||
have_config = false; //save config
|
||||
}
|
||||
else if (access(std::string(ConfigList["WebsiteMain.directory"] + "/logos").c_str(), 4) == 0){
|
||||
else if (access(std::string(ConfigList["WebsiteMain.directory"] + "/logos").c_str(), R_OK) == 0) {
|
||||
Config->setString("Tuxbox.LogosURL", ConfigList["WebsiteMain.directory"] + "/logos");
|
||||
have_config = false; //save config
|
||||
}
|
||||
#ifdef Y_CONFIG_USE_HOSTEDWEB
|
||||
else if (access(std::string(ConfigList["WebsiteMain.hosted_directory"] + "/logos").c_str(), 4) == 0){
|
||||
else if (access(std::string(ConfigList["WebsiteMain.hosted_directory"] + "/logos").c_str(), R_OK) == 0) {
|
||||
Config->setString("Tuxbox.LogosURL", ConfigList["WebsiteMain.hosted_directory"] + "/logos");
|
||||
have_config = false; //save config
|
||||
}
|
||||
|
Reference in New Issue
Block a user