1
0

HttpServer.h 1.2 KB

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