Tests about a simple python3 fastcgi runner using libfcgi and the Python-C API.
python
c
wsgi
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

responder.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C) 2019 Weber Yann
  3. *
  4. * This file is part of PyFCGI.
  5. *
  6. * PyFCGI is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * PyFCGI is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PyFCGI. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**@defgroup work_master_proc Worker handler process
  20. * @brief This process use the @ref responder_loop() function as "main" function
  21. *
  22. * @section work_master_spawn Spawning workers
  23. * This subprocess handle worker spawning using @ref spawn(). A POSIX semaphore
  24. * allow to know when the worker pool is idle or not :
  25. *
  26. * @subsection work_master_spawn_sem Semaphore idle & busy detection
  27. * When a new worker is ready (idle) it add 1 to the semaphore, when processing
  28. * a request it substract 1 to the semaphore (done in @ref work() function in
  29. * @ref worker_process )
  30. *
  31. * When semtimedop blocks on wait_for_zero operation it means that the pool is
  32. * idle. Instead, if the semtimedop returns imediately it means a new worker
  33. * can be spawned.
  34. *
  35. * @ingroup main_proc
  36. */
  37. /**@file responder.h
  38. * @ingroup work_master_proc
  39. */
  40. #ifndef _RESPONDER__H___
  41. #define _RESPONDER__H___
  42. #include "config.h"
  43. #include <fcgiapp.h> /* fcgi library; put it first*/
  44. //#include <fcgios.h> /* OS_IpcClose() but includes fcgi_config.h... */
  45. extern int OS_IpcClose(int ipcFd);
  46. #include <stdlib.h>
  47. #include <unistd.h>
  48. #include <string.h>
  49. #include <syslog.h>
  50. #include <errno.h>
  51. #include <time.h>
  52. #include <sys/types.h>
  53. #include <sys/ipc.h>
  54. #include <sys/sem.h>
  55. #include "logger.h"
  56. #include "pyworker.h"
  57. void init_context();
  58. /**@brief Start a new pool_handler process
  59. * @return the new PID or -1 if error */
  60. pid_t spawn_pool_handler();
  61. /**@brief The responder loop
  62. * @ingroup work_master_proc
  63. * The main function of the fcgi app fork child
  64. * @return 0 on success
  65. */
  66. int responder_loop();
  67. /**@brief Spawn a worker given an entrypoint
  68. * @ingroup work_master_proc
  69. * Spawn a new worker process and prepare ENV & request forwarding
  70. * @param wrk_id worker id
  71. * @return child PID
  72. */
  73. pid_t spawn(int wrk_id);
  74. /**@deprecated Not used */
  75. int pyfcgi_pool_state();
  76. /**@brief Check if the pool is idle : if not able to timedwait the pool is busy
  77. * @param timeout
  78. * @return 1 if busy else 0
  79. * @note exit on error
  80. */
  81. int pyfcgi_pool_idle(const struct timespec *timeout);
  82. /**@brief Handle signals and forward it to workers */
  83. void pool_sighandler(int signum);
  84. /**@brief Handle watchdog alarm signal */
  85. void pool_wd_sighandler(int signum);
  86. /**@brief Update SHM data */
  87. void pyfcgi_pool_shm_update(int nworker);
  88. #endif