http_server.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #include "http_define.h"
  3. #if USE_NET_HTTP_WEBSITE
  4. #include <string>
  5. #include <vector>
  6. #include <map>
  7. #include <functional>
  8. #include <map>
  9. #include "http_interface.h"
  10. #include "qps.hpp"
  11. namespace ylib
  12. {
  13. namespace network
  14. {
  15. namespace http
  16. {
  17. class http_server_lst;
  18. class host;
  19. /*************************************************************************
  20. * class:HTTP服务器
  21. *************************************************************************/
  22. class server :public ylib::error_base, public network::http::interface_
  23. {
  24. public:
  25. server();
  26. ~server();
  27. bool create(server_config config);
  28. /******************************************************************
  29. * Function:启动
  30. * Param:
  31. * ipaddress : 监听地址
  32. * port : 监听端口
  33. ******************************************************************/
  34. bool start();
  35. /******************************************************************
  36. * Function:关闭
  37. ******************************************************************/
  38. bool close();
  39. /******************************************************************
  40. * Function:取远程信息
  41. * Param:
  42. * connid : 连接ID
  43. * ipaddress : 远程地址
  44. * port : 远程端口
  45. ******************************************************************/
  46. bool remote(uint64 connid, std::string& ipaddress, ushort& port);
  47. /******************************************************************
  48. * Function:HP服务指针
  49. ******************************************************************/
  50. void* hpserver();
  51. /******************************************************************
  52. * Function:每秒请求数
  53. ******************************************************************/
  54. network::qps* qps();
  55. /// <summary>
  56. /// 取配置
  57. /// </summary>
  58. /// <returns></returns>
  59. const server_config& config() { return m_config; }
  60. #if USE_NET_HTTP_AGENT == 1
  61. inline network::http::agent* agent() { return m_agent; }
  62. #endif
  63. public:
  64. bool m_init_ssl = false;
  65. private:
  66. friend class http_server_lst;
  67. private:
  68. // HP HttpServer 指针
  69. void* m_server;
  70. // HP Listener 指针
  71. network::http::http_server_lst* m_listener;
  72. // 配置
  73. server_config m_config;
  74. // QPS
  75. network::qps m_qps;
  76. #if USE_NET_HTTP_AGENT == 1
  77. // 代理指针
  78. network::http::agent* m_agent;
  79. #endif
  80. };
  81. }
  82. }
  83. }
  84. #endif