http_server.h 926 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef HTTP_SERVER_H_
  2. #define HTTP_SERVER_H_
  3. #include "HttpService.h"
  4. #define DEFAULT_HTTP_PORT 80
  5. typedef struct http_server_s {
  6. int port;
  7. HttpService* service;
  8. int worker_processes;
  9. //private:
  10. int listenfd;
  11. #ifdef __cplusplus
  12. http_server_s() {
  13. port = DEFAULT_HTTP_PORT;
  14. service = NULL;
  15. worker_processes = 0;
  16. listenfd = -1;
  17. }
  18. #endif
  19. } http_server_t;
  20. /*
  21. #include "http_server.h"
  22. void http_api_hello(HttpRequest* req, HttpResponse* res) {
  23. res->body = "hello";
  24. }
  25. int main() {
  26. HttpService service;
  27. service.AddApi("/hello", http_api_hello);
  28. http_server_t server;
  29. server.port = 8080;
  30. server.worker_processes = 4;
  31. server.service = &service;
  32. http_server_run(&server);
  33. return 0;
  34. }
  35. */
  36. int http_server_run(http_server_t* server, int wait = 1);
  37. // for SDK, just use for singleton
  38. int http_server_stop(http_server_t* server);
  39. #endif