da_core.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright [2021] JD.com, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef DA_CORE_H_
  17. #define DA_CORE_H_
  18. #include "da_array.h"
  19. #include "da_util.h"
  20. #ifdef HAVE_ASSERT_PANIC
  21. #define DA_ASSERT_PANIC 1
  22. #endif
  23. #ifdef HAVE_ASSERT_LOG
  24. #define DA_ASSERT_LOG 1
  25. #endif
  26. #define DA_STATS 1
  27. #define USE_COMPATIBLE_MODE
  28. #ifdef USE_COMPATIBLE_MODE
  29. #define DA_COMPATIBLE_MODE 1
  30. #else
  31. #define DA_COMPATIBLE_MODE 0
  32. #endif
  33. #define RESERVED_FDS 32
  34. #define NC_ENV_FDS "NC_ENV_FDS"
  35. #define DA_ADDR_LEN 32
  36. struct event_base;
  37. struct context;
  38. struct conn;
  39. struct instance;
  40. struct context {
  41. uint32_t id; /* unique context id */
  42. struct conf *cf; /* configuration */
  43. struct stats *stats; /* stats */
  44. struct array pool; /* server_pool[] */
  45. struct event_base *evb; /* event base */
  46. int max_timeout; /* max timeout in msec */
  47. int timeout; /* timeout in msec */
  48. uint32_t max_nfd; /* max # files */
  49. uint32_t max_ncconn; /* max # client connections */
  50. uint32_t max_nsconn; /* max # server connections */
  51. uint32_t sum_nconn; /* client connections and server connections sum*/
  52. };
  53. struct instance {
  54. struct context *ctx; /* active context */
  55. int log_level; /* log level */
  56. char *log_dir; /* log dir*/
  57. char *conf_filename; /* configuration filename */
  58. char hostname[DA_MAXHOSTNAMELEN]; /* hostname */
  59. size_t mbuf_chunk_size; /* mbuf chunk size */
  60. int event_max_timeout; /* epoll max time out*/
  61. int stats_interval; /* stats aggregation interval */
  62. pid_t pid; /* process id */
  63. char *pid_filename; /* pid filename */
  64. unsigned pidfile : 1; /* pid file created? */
  65. int cpumask; /*cpu mask for run*/
  66. char **argv; /* argv of main() */
  67. };
  68. // status for server
  69. enum core_status {
  70. NORMAL,
  71. RELOADING,
  72. EXITING,
  73. EXITED,
  74. };
  75. // extern struct conn *wait_send_queue[]; /*cached conn*/
  76. void cache_send_event(struct conn *conn);
  77. int core_core(void *arg, uint32_t events);
  78. struct context *core_start(struct instance *dai);
  79. void core_stop(struct context *ctx);
  80. int core_loop(struct context *ctx);
  81. int core_exec_new_binary(struct instance *dai);
  82. int core_inherited_socket(char *listen_address);
  83. void core_cleanup_inherited_socket(void);
  84. void core_setinst_status(enum core_status status);
  85. enum core_status core_getinst_status();
  86. #endif /* DA_CORE_H_ */