1
0

HttpServer.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. //private:
  12. int listenfd;
  13. #ifdef __cplusplus
  14. http_server_s() {
  15. strcpy(host, "0.0.0.0");
  16. port = DEFAULT_HTTP_PORT;
  17. ssl = 0;
  18. http_version = 1;
  19. service = NULL;
  20. worker_processes = 0;
  21. listenfd = -1;
  22. }
  23. #endif
  24. } http_server_t;
  25. /*
  26. #include "http_server.h"
  27. void http_api_hello(HttpRequest* req, HttpResponse* res) {
  28. res->body = "hello";
  29. }
  30. int main() {
  31. HttpService service;
  32. service.AddApi("/hello", http_api_hello);
  33. http_server_t server;
  34. server.port = 8080;
  35. server.worker_processes = 4;
  36. server.service = &service;
  37. http_server_run(&server);
  38. return 0;
  39. }
  40. */
  41. int http_server_run(http_server_t* server, int wait = 1);
  42. // for SDK, just use for singleton
  43. int http_server_stop(http_server_t* server);
  44. #endif