NCBI C++ ToolKit
fcgiapp_mt.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CGI___FCGIAPP_MT__HPP
2 #define CGI___FCGIAPP_MT__HPP
3 
4 /* $Id: fcgiapp_mt.hpp 94581 2021-08-18 17:20:20Z grichenk $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Aleksey Grichenko
30 *
31 * File Description:
32 * Base class for multithreaded Fast-CGI applications
33 */
34 
35 #include <cgi/cgiapp.hpp>
36 #include <fastcgi++/manager.hpp>
37 #include <fastcgi++/request.hpp>
38 #include <sstream>
39 
40 /** @addtogroup CGIBase
41  *
42  * @{
43  */
44 
45 
47 
48 class ICache;
49 
50 
51 /////////////////////////////////////////////////////////////////////////////
52 // CFastCgiApplicationMT::
53 //
54 
55 class CFastCgiThreadedRequest : public Fastcgipp::Request<char>
56 {
57 public:
58  typedef Fastcgipp::Request<char> TParent;
61 
64 
65  bool response(void) override;
66  void errorHandler(void) override;
67  bool inProcessor(void) override;
68 
69  TInput& in(void) { return *m_InputStream; }
70  TOutput& out(void) { return TParent::out; }
71  TOutput& err(void) { return TParent::err; }
72  const char* const* env(void) const {
73  if ( m_Env.data.empty() ) x_ParseEnv();
74  return m_Env.data.data();
75  }
76 
77 private:
78  void x_ParseEnv(void) const;
79 
80  class CEnv {
81  public:
82  CEnv(void) {}
83  ~CEnv(void) {
84  for (auto p: data) {
85  if ( p ) free(p);
86  }
87  }
88 
89  void Set(const string& name, const string& value) {
90  string env = name + "=" + value;
91  data.push_back(strdup(env.c_str()));
92  }
93 
94  vector<char*> data;
95  };
96 
97  shared_ptr<istream> m_InputStream;
98  mutable CEnv m_Env;
99 };
100 
101 /////////////////////////////////////////////////////////////////////////////
102 // CFastCgiApplicationMT::
103 //
104 
106 {
107 public:
109  ~CFastCgiApplicationMT(void);
110 
111  /// Singleton
112  static CFastCgiApplicationMT* Instance(void);
113 
114  /// This method is not used by multithreaded FastCGI and should never be called.
115  /// Override CreateRequestProcessor and ICgiRequestProcessor::ProcessRequest instead.
116  int ProcessRequest(CCgiContext& context) override { return -1; }
117 
118  bool IsFastCGI(void) const override { return true; }
119 
120 protected:
121  bool x_RunFastCGI(int* result, unsigned int def_iter = 10) override;
122  void FASTCGI_ScheduleExit(void) override;
123 
124 private:
126  friend void s_ScheduleFastCGIMTExit(void);
127 
128  void x_ProcessThreadedRequest(CFastCgiThreadedRequest& req);
129 
130  typedef Fastcgipp::Manager<CFastCgiThreadedRequest> TManager;
131 
132  unique_ptr<TManager> m_Manager;
133  CAtomicCounter m_ErrorCounter; // failed requests
135  unique_ptr<CCgiStatistics> m_Stat;
136  unsigned int m_MaxIterations;
137  unique_ptr<CCgiWatchFile> m_Watcher;
138  unsigned int m_WatchTimeout;
143 };
144 
145 
146 /////////////////////////////////////////////////////////////////////////////
147 // CCgiRequestProcessorMT::
148 //
149 
151 {
152  friend class CFastCgiApplicationMT;
153 
154 public:
156  virtual ~CCgiRequestProcessorMT(void);
157 
158 private:
159  unique_ptr<CNcbiResource> m_Resource;
160 };
161 
162 
164 
165 
166 /* @} */
167 
168 
169 #endif // CGI___FCGIAPP_MT__HPP
CAtomicCounter –.
Definition: ncbicntr.hpp:71
Base class for request processors.
Definition: cgiapp.hpp:579
CTime –.
Definition: ncbitime.hpp:296
BLOB cache read/write/maintenance interface.
Definition: icache.hpp:64
std::ofstream out("events_result.xml")
main entry point for tests
void s_ScheduleFastCGIMTExit(void)
Definition: fcgiapp_mt.cpp:56
TOutput & err(void)
Definition: fcgiapp_mt.hpp:71
unique_ptr< CCgiStatistics > m_Stat
Definition: fcgiapp_mt.hpp:135
virtual bool x_RunFastCGI(int *result, unsigned int def_iter=10)
Definition: cgi_run.cpp:44
Fastcgipp::Request< char > TParent
Definition: fcgiapp_mt.hpp:58
int ProcessRequest(CCgiContext &context) override
This method is not used by multithreaded FastCGI and should never be called.
Definition: fcgiapp_mt.hpp:116
Fastcgipp::Manager< CFastCgiThreadedRequest > TManager
Definition: fcgiapp_mt.hpp:130
unique_ptr< TManager > m_Manager
Definition: fcgiapp_mt.hpp:132
TOutput & out(void)
Definition: fcgiapp_mt.hpp:70
unsigned int m_WatchTimeout
Definition: fcgiapp_mt.hpp:138
void Set(const string &name, const string &value)
Definition: fcgiapp_mt.hpp:89
unique_ptr< CNcbiResource > m_Resource
Definition: fcgiapp_mt.hpp:159
unique_ptr< CCgiWatchFile > m_Watcher
Definition: fcgiapp_mt.hpp:137
virtual void FASTCGI_ScheduleExit(void)
Schedule Fast-CGI loop to end as soon as possible, after safely finishing the currently processed req...
Definition: cgiapp.hpp:225
void errorHandler(void) override
Definition: fcgiapp_mt.cpp:464
CAtomicCounter m_ErrorCounter
Definition: fcgiapp_mt.hpp:133
static CCgiApplication * Instance(void)
Singleton.
Definition: cgiapp.cpp:457
bool inProcessor(void) override
Definition: fcgiapp_mt.cpp:471
const char *const * env(void) const
Definition: fcgiapp_mt.hpp:72
void x_ParseEnv(void) const
Definition: fcgiapp_mt.cpp:481
shared_ptr< istream > m_InputStream
Definition: fcgiapp_mt.hpp:97
bool response(void) override
Definition: fcgiapp_mt.cpp:455
bool IsFastCGI(void) const override
Return TRUE if it is running as a "fast" CGI.
Definition: fcgiapp_mt.hpp:118
unsigned int m_MaxIterations
Definition: fcgiapp_mt.hpp:136
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
#define NCBI_SBUILDINFO_DEFAULT()
Definition: version.hpp:119
#define NCBI_XFCGI_MT_EXPORT
Definition: ncbi_export.h:1105
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
#define strdup
Definition: ncbi_ansi_ext.h:70
This class allows to add build info (date and tag) to application version.
Definition: version_api.hpp:62
else result
Definition: token2.c:20
static CS_CONTEXT * context
Definition: will_convert.c:21
void free(voidpf ptr)
Modified on Sun Jun 23 05:20:33 2024 by modify_doxy.py rev. 669887