allow a request to be processed in a job
Now we allow a request to be passed into a job queue, and after the job finishes the request is passed into a controller again. In order to achieve this we have a requests queue in System, when we put a request to the job this Request structure is preserved in the queue and for a new request a new Request is added to the queue. while here: - remove App::Lock()/Unlock(), use scoped locking - fix: Plugin now has a Call method which takes ModelConnector and a logger (used in multithreaded environment) - BaseThread has a main_model_connector pointer to the main (from the main thread) model connector - the FastCGI structure fcgi_request moved from App to Request - some methods for handling requests moved from App to Request - small refactoring in main.cpp - add Http class (a http client)
This commit is contained in:
@@ -51,6 +51,11 @@
|
||||
#include "models.h"
|
||||
#include "models/winixmodel.h"
|
||||
#include "header.h"
|
||||
#include "compress.h"
|
||||
#include "plugin.h"
|
||||
#include "mount.h"
|
||||
#include "mounts.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -60,7 +65,7 @@ namespace Winix
|
||||
|
||||
|
||||
class FunctionBase;
|
||||
|
||||
class Templates;
|
||||
|
||||
|
||||
|
||||
@@ -87,6 +92,15 @@ public:
|
||||
*/
|
||||
size_t id;
|
||||
|
||||
// the state of the request
|
||||
// not_assigned - the object is not being used
|
||||
// normal_run - run in the main thread, this state is set after a new request is made
|
||||
// assigned_to_job - the request is preserved and a new job will be called
|
||||
// job_run - run in the job thread (objects are locked)
|
||||
// finished - the request is finished and the object can be removed
|
||||
enum RunState { not_assigned = 0, normal_run, assigned_to_job, job_run, job_continuation_run, finished};
|
||||
|
||||
RunState run_state;
|
||||
|
||||
/*
|
||||
* request start time
|
||||
@@ -230,13 +244,23 @@ public:
|
||||
// null if there is no a function
|
||||
FunctionBase * function;
|
||||
|
||||
// current session (if exists, can be null)
|
||||
Session * session;
|
||||
|
||||
// current mount point (can be null, it is treated as cms filesystem then)
|
||||
Mount * mount;
|
||||
|
||||
// parameters (name:value)
|
||||
ParamTab param_tab;
|
||||
|
||||
// this is a pointer either to the item (if exists) or to the last directory
|
||||
Item * last_item;
|
||||
|
||||
// can we use gzip compression algorithm when sending content to the client
|
||||
bool accept_gzip;
|
||||
|
||||
// can we use deflate compression algorithm when sending content to the client
|
||||
bool accept_deflate;
|
||||
|
||||
|
||||
/*
|
||||
@@ -412,16 +436,24 @@ public:
|
||||
std::vector<Item> item_tab;
|
||||
|
||||
|
||||
/*
|
||||
* FastCGI request structure with pointers to input/output streams
|
||||
*/
|
||||
FCGX_Request fcgi_request;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
long job_id;
|
||||
pt::Space job;
|
||||
|
||||
|
||||
|
||||
Request();
|
||||
void SetConfig(Config * pconfig);
|
||||
|
||||
void SetConfig(Config * config);
|
||||
void SetTemplates(Templates * templates);
|
||||
void SetCompress(Compress * compress);
|
||||
void SetPlugin(Plugin * plugin);
|
||||
void SetMounts(Mounts * mounts);
|
||||
|
||||
|
||||
void fields();
|
||||
@@ -473,10 +505,34 @@ public:
|
||||
bool has_frame(const wchar_t * frame);
|
||||
bool has_frame(const std::wstring & frame);
|
||||
|
||||
void create_job(long job_id);
|
||||
void modify_status_code_if_needed();
|
||||
|
||||
// RENAMEME to add_header_if_not_exists
|
||||
bool AddHeader(const wchar_t * name, const wchar_t * value);
|
||||
bool AddHeader(const std::wstring & name, const std::wstring & value);
|
||||
bool AddHeader(const wchar_t * name, const pt::WTextStream & value);
|
||||
bool AddHeader(const std::wstring & name, const pt::WTextStream & value);
|
||||
|
||||
void FinishRequest();
|
||||
|
||||
private:
|
||||
|
||||
Config * config;
|
||||
Templates * templates;
|
||||
Compress * compress;
|
||||
Plugin * plugin;
|
||||
Mounts * mounts;
|
||||
|
||||
BinaryPage output_8bit;
|
||||
BinaryPage compressed_output;
|
||||
pt::WTextStream output_tmp_filtered_stream;
|
||||
pt::TextStream serialized_model;
|
||||
std::string aheader_name, aheader_value;
|
||||
std::wstring cookie_id_string;
|
||||
std::string send_data_buf;
|
||||
|
||||
|
||||
|
||||
// used in ParamValue() and PostVar() when there is no such a param
|
||||
const std::wstring str_empty;
|
||||
@@ -493,6 +549,45 @@ private:
|
||||
void http_status_error_title(EzcEnv & env);
|
||||
void http_status_error_description(EzcEnv & env);
|
||||
|
||||
void SendAnswer();
|
||||
void PrepareRawAnswer();
|
||||
void PrepareJsonAnswer();
|
||||
void PrepareXmlAnswer();
|
||||
void PrepareCsvAnswer();
|
||||
void PrepareContenerizedAnswer();
|
||||
void PutSeparatorIfNeeded(bool put_separator);
|
||||
void SerializeFieldJson(const wchar_t * field_name);
|
||||
void SerializeStream(const pt::WTextStream & input_stream, const wchar_t * field_name);
|
||||
void SerializeStreamJson(const pt::WTextStream & input_stream, const wchar_t * field_name);
|
||||
void SerializeStreamXml(const pt::WTextStream & input_stream, const wchar_t * field_name);
|
||||
void SerializeStreamCsv(const pt::WTextStream & input_stream, const wchar_t * field_name);
|
||||
void SerializeAllFrames();
|
||||
void SerializeSpecificFrames();
|
||||
void SerializeModels();
|
||||
void SerializeModel(morm::Wrapper & wrapper, const wchar_t * field_name);
|
||||
void SerializeModelJson(morm::Wrapper & wrapper, const wchar_t * field_name);
|
||||
void SerializeModelXml(morm::Wrapper & wrapper, const wchar_t * field_name);
|
||||
void SerializeModelCsv(morm::Wrapper & wrapper, const wchar_t * field_name);
|
||||
void FilterHtmlIfNeeded(const pt::WTextStream & input_stream, BinaryPage & output, bool clear_stream = true);
|
||||
void Send8bitOutput(BinaryPage & output);
|
||||
void SendData(const BinaryPage & page, FCGX_Stream * out);
|
||||
void UseEzcGenerator();
|
||||
int SelectDeflateVersion();
|
||||
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
|
||||
void PrepareSessionCookie();
|
||||
void PrepareHeaders(bool compressing, int compress_encoding, size_t output_size);
|
||||
void ModifyStatusForRedirect();
|
||||
void PrepareSendFileHeaderForStaticMountpoint();
|
||||
void PrepareSendFileHeader();
|
||||
void PrepareContentEncodingHeader(int compress_encoding);
|
||||
void PrepareContentLengthHeader(size_t output_size);
|
||||
void PrepareHeaderContentType();
|
||||
void PrepareHeaderStatus(int http_status);
|
||||
void SendHeaders();
|
||||
void SendCookies();
|
||||
bool CreateStaticResourcePath(pt::WTextStream & out_path);
|
||||
bool CanSendContent();
|
||||
void LogRequestTime();
|
||||
|
||||
MORM_MEMBER_FIELD(Request)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user