HttpServer.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef HTTP_SERVER_H_
  2. #define HTTP_SERVER_H_
  3. #include "HttpService.h"
  4. typedef struct http_server_s {
  5. char host[64];
  6. int port;
  7. int ssl;
  8. int http_version;
  9. HttpService* service;
  10. int worker_processes;
  11. void* userdata;
  12. //private:
  13. int listenfd;
  14. void* privdata;
  15. #ifdef __cplusplus
  16. http_server_s() {
  17. strcpy(host, "0.0.0.0");
  18. port = DEFAULT_HTTP_PORT;
  19. ssl = 0;
  20. http_version = 1;
  21. service = NULL;
  22. worker_processes = 0;
  23. listenfd = -1;
  24. userdata = NULL;
  25. privdata = NULL;
  26. }
  27. #endif
  28. } http_server_t;
  29. /*
  30. #include "http_server.h"
  31. void http_api_hello(HttpRequest* req, HttpResponse* res) {
  32. res->body = "hello";
  33. }
  34. int main() {
  35. HttpService service;
  36. service.AddApi("/hello", http_api_hello);
  37. http_server_t server;
  38. server.port = 8080;
  39. server.worker_processes = 4;
  40. server.service = &service;
  41. http_server_run(&server);
  42. return 0;
  43. }
  44. */
  45. int http_server_run(http_server_t* server, int wait = 1);
  46. // for SDK
  47. int http_server_stop(http_server_t* server);
  48. #endif