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

Go to the SVN repository for this file.

1 #ifndef HTTPSERVERTRANSPORT__HPP
2 #define HTTPSERVERTRANSPORT__HPP
3 
4 /* $Id: http_daemon.hpp 97718 2022-08-18 15:57:26Z satskyse $
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  * Authors: Dmitri Dmitrienko
30  *
31  * File Description:
32  *
33  */
34 
35 #include <string>
36 #include <vector>
37 
38 #include <h2o.h>
39 
40 #include "http_proto.hpp"
41 
42 
43 class CHttpRequestParser;
44 class CHttpPostParser;
45 
47 {
48  CHttpHandler(const std::string & path,
50  CHttpRequestParser * get_parser,
51  CHttpPostParser * post_parser) :
52  m_Path(path),
53  m_Handler(std::move(handler)),
54  m_GetParser(get_parser),
55  m_PostParser(post_parser)
56  {}
57 
62 };
63 
64 
66 {
67 public:
68  const unsigned short kAnyPort = 65535;
69 
70  CHttpDaemon(const std::vector<CHttpHandler> & handlers,
71  const std::string & tcp_address, unsigned short tcp_port,
72  unsigned short tcp_workers, unsigned short tcp_backlog,
73  unsigned short tcp_max_connections);
74  ~CHttpDaemon();
75 
76  void Run(std::function<void(CTcpDaemon &)> on_watch_dog = nullptr);
77  h2o_globalconf_t * HttpCfg(void);
78  uint16_t NumOfConnections(void) const;
79 
80 private:
81  std::unique_ptr<CTcpDaemon> m_TcpDaemon;
82  h2o_globalconf_t m_HttpCfg;
84  std::vector<CHttpHandler> m_Handlers;
85  static const char * sm_CdUid;
86 
87  static int s_OnHttpRequest(h2o_handler_t * self, h2o_req_t * req);
88 };
89 
90 #endif
91 
uint16_t NumOfConnections(void) const
h2o_globalconf_t * HttpCfg(void)
std::unique_ptr< CTcpDaemon > m_TcpDaemon
Definition: http_daemon.hpp:81
std::vector< CHttpHandler > m_Handlers
Definition: http_daemon.hpp:84
CHttpDaemon(const std::vector< CHttpHandler > &handlers, const std::string &tcp_address, unsigned short tcp_port, unsigned short tcp_workers, unsigned short tcp_backlog, unsigned short tcp_max_connections)
Definition: http_daemon.cpp:54
static const char * sm_CdUid
Definition: http_daemon.hpp:85
static int s_OnHttpRequest(h2o_handler_t *self, h2o_req_t *req)
bool m_HttpCfgInitialized
Definition: http_daemon.hpp:83
h2o_globalconf_t m_HttpCfg
Definition: http_daemon.hpp:82
const unsigned short kAnyPort
Definition: http_daemon.hpp:68
void Run(std::function< void(CTcpDaemon &)> on_watch_dog=nullptr)
Definition: http_daemon.cpp:87
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
Uint2 uint16_t
string
Definition: cgiapp.hpp:687
std::function< void(CHttpRequest &req, shared_ptr< CPSGS_Reply > reply)> HttpHandlerFunction_t
Definition: http_proto.hpp:65
CHttpPostParser * m_PostParser
Definition: http_daemon.hpp:61
HttpHandlerFunction_t m_Handler
Definition: http_daemon.hpp:59
CHttpHandler(const std::string &path, HttpHandlerFunction_t &&handler, CHttpRequestParser *get_parser, CHttpPostParser *post_parser)
Definition: http_daemon.hpp:48
CHttpRequestParser * m_GetParser
Definition: http_daemon.hpp:60
std::string m_Path
Definition: http_daemon.hpp:58
Modified on Sun Apr 21 03:41:54 2024 by modify_doxy.py rev. 669887