http_server.h 956 B

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