diff --git a/winixd/core/app.cpp b/winixd/core/app.cpp index 2626a13..0294b6e 100644 --- a/winixd/core/app.cpp +++ b/winixd/core/app.cpp @@ -98,7 +98,7 @@ App::App() config.SetFileLog(&file_log); config.SetLogBuffer(&log_buffer); - cur.request = nullptr; + cur.request = nullptr; // they are first set in App::Init() cur.session = nullptr; cur.mount = nullptr; @@ -352,6 +352,12 @@ bool App::InitializePlugins() bool App::Init() { + cur.session = session_manager.GetTmpSession(); + cur.mount = system.mounts.GetEmptyMount();; + system.req_tab.resize(1); + cur.request = &system.req_tab.back(); + InitializeNewRequest(*cur.request); // this will set cur.request->session (from cur.session) and cur.request->mount (from cur.mount) + if( !config.db_conn_string.empty() ) postgresql_connector.set_conn_param(config.db_conn_string); else @@ -617,9 +623,10 @@ void App::MakeRenameMeToABetterName() cur.request->item.set_connector(model_connector); cur.session = session_manager.PrepareSession(); + cur.request->session = cur.session; model_connector.set_winix_session(cur.session); - functions.CheckFunctionAndSymlink(); // here a function can be changed + functions.CheckFunctionAndSymlink(); // here a function can be changed (and mount point but cur.mount and cur->request->mount will be set) if( cur.request->function ) { @@ -628,6 +635,7 @@ void App::MakeRenameMeToABetterName() } cur.session = session_manager.CheckIfFunctionRequireSession(); + cur.request->session = cur.session; model_connector.set_winix_session(cur.session); SetLocale(); @@ -736,6 +744,7 @@ void App::ProcessRequestThrow() } cur.mount = system.mounts.CalcCurMount(cur.request); + cur.request->mount = cur.mount; if( cur.mount->type != system.mounts.MountTypeStatic() ) { @@ -811,20 +820,20 @@ void App::ClearAfterRequest() } -bool App::InitializeRequestForFastCGI() +bool App::InitializeRequestForFastCGI(Request & request) { bool request_initialized = false; while( !synchro.was_stop_signal && !request_initialized ) { - if( FCGX_InitRequest(&cur.request->fcgi_request, fcgi_socket, FCGI_FAIL_ACCEPT_ON_INTR) == 0 ) + if( FCGX_InitRequest(&request.fcgi_request, fcgi_socket, FCGI_FAIL_ACCEPT_ON_INTR) == 0 ) { request_initialized = true; } else { log << log1 << "App: FCGX_InitRequest fails, I cannot read a new request, I wait 3s and will try again..." << logend << logsave; - sleep(3); // IMPROVEME put me to config + sleep(config.fcgi_cannot_create_request_delay); } } @@ -832,44 +841,30 @@ bool App::InitializeRequestForFastCGI() } -void App::SetRequestDependency() +void App::SetRequestDependency(Request & request) { - cur.request->SetConfig(&config); - cur.request->SetTemplates(&templates); - cur.request->SetCompress(&compress); - cur.request->SetPlugin(&plugin); - cur.request->SetMounts(&system.mounts); + request.SetConfig(&config); + request.SetTemplates(&templates); + request.SetCompress(&compress); + request.SetPlugin(&plugin); + request.SetMounts(&system.mounts); - cur.request->session = cur.session; - cur.request->mount = cur.mount; + request.session = cur.session; + request.mount = cur.mount; - cur.request->set_connector(&model_connector); - cur.request->item.set_connector(&model_connector); + request.set_connector(&model_connector); + request.item.set_connector(&model_connector); } -void App::InitializeNewRequest() +void App::InitializeNewRequest(Request & request) { - SetRequestDependency(); - cur.request->Clear(); // IMPROVE ME what about an 'id' in request? it should be unique? - InitializeRequestForFastCGI(); + SetRequestDependency(request); + request.Clear(); + InitializeRequestForFastCGI(request); } -// use with lock/unlock -void App::PrepareRequest() -{ - Winix::Lock lock(synchro); - - if( system.req_tab.empty() ) - { - system.req_tab.resize(1); - } - - cur.request = &system.req_tab.back(); - InitializeNewRequest(); -} - void App::PutRequestToJob() { @@ -903,12 +898,6 @@ void App::Start() { Winix::Lock lock(synchro); was_stop_signal = synchro.was_stop_signal; - } - - PrepareRequest(); - - { - Winix::Lock lock(synchro); fcgi_request = &cur.request->fcgi_request; } @@ -960,7 +949,7 @@ void App::Start() */ system.req_tab.resize(system.req_tab.size() + 1); cur.request = &system.req_tab.back(); - InitializeNewRequest(); + InitializeNewRequest(*cur.request); // cur.request->session, cur.request->mount, cur.request->id etc. are set when the request starts } } diff --git a/winixd/core/app.h b/winixd/core/app.h index b702ddb..2ec97e1 100644 --- a/winixd/core/app.h +++ b/winixd/core/app.h @@ -76,10 +76,9 @@ public: Log & GetMainLog(); bool InitializePlugins(); bool Init(); - bool InitializeRequestForFastCGI(); - void SetRequestDependency(); - void InitializeNewRequest(); - void PrepareRequest(); + bool InitializeRequestForFastCGI(Request & request); + void SetRequestDependency(Request & request); + void InitializeNewRequest(Request & request); void PutRequestToJob(); void Start(); void Close(); diff --git a/winixd/core/config.cpp b/winixd/core/config.cpp index 71a6e2a..be3e71b 100644 --- a/winixd/core/config.cpp +++ b/winixd/core/config.cpp @@ -136,6 +136,7 @@ void Config::AssignValues() fcgi_socket_user = Text(L"fcgi_socket_user"); fcgi_socket_group = Text(L"fcgi_socket_group"); fcgi_socket_listen = Int(L"fcgi_socket_listen", 1024); + fcgi_cannot_create_request_delay = Size(L"fcgi_cannot_create_request_delay", 3); log_level = Int(L"log_level", 1); log_request = Int(L"log_request", 1); log_save_each_line = Bool(L"log_save_each_line", false); diff --git a/winixd/core/config.h b/winixd/core/config.h index 4c99261..6d5400a 100644 --- a/winixd/core/config.h +++ b/winixd/core/config.h @@ -180,6 +180,12 @@ public: // default: 100 int fcgi_socket_listen; + // in order to read a request we need to properly initialize a FastCGI structure by + // using FCGX_InitRequest function, if FCGX_InitRequest fails then we wait fcgi_cannot_create_request_delay + // seconds and trying again + // default: 3 + size_t fcgi_cannot_create_request_delay; + std::wstring templates_dir; std::wstring templates_dir_default; // html templates from winix diff --git a/winixd/core/system.cpp b/winixd/core/system.cpp index c197696..ce10933 100644 --- a/winixd/core/system.cpp +++ b/winixd/core/system.cpp @@ -1445,7 +1445,8 @@ bool System::FollowAllLinks(const std::wstring & link_to, log << log3 << "System: current directory changed and the new file loaded" << logend; } - mounts.CalcCurMount(cur->request); + cur->mount = mounts.CalcCurMount(cur->request); + cur->request->mount = cur->mount; } else { diff --git a/winixd/functions/functions.cpp b/winixd/functions/functions.cpp index bc1201f..352bb84 100644 --- a/winixd/functions/functions.cpp +++ b/winixd/functions/functions.cpp @@ -172,6 +172,7 @@ Error Functions::CheckSpecialFile(const Item & item) system->mounts.ReadMounts(item.item_content.content_raw); system->mounts.CalcCurMount(cur->request); cur->mount = system->mounts.pmount; + cur->request->mount = cur->mount; templates->ReadNewIndexTemplates(); templates->ReadNewChangeTemplates(); diff --git a/winixd/plugins/mailregister/init.cpp b/winixd/plugins/mailregister/init.cpp index 5675d40..cebae89 100644 --- a/winixd/plugins/mailregister/init.cpp +++ b/winixd/plugins/mailregister/init.cpp @@ -123,9 +123,7 @@ void ConfigReload(PluginInfo & info) // iq.SetAll(true, false); // iq.WhereParentId(dir->id); - // CHECKME is it correct to get connector from the last item? - morm::ModelConnector * model_connector = info.cur->request->last_item->get_connector(); - morm::Finder finder(model_connector); + morm::Finder finder(info.model_connector); finder. select().