Tests about a simple python3 fastcgi runner using libfcgi and the Python-C API.
python
c
wsgi
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

responder.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 processes
  36. * @ingroup main_proc
  37. */
  38. /**@file responder.h
  39. * @ingroup work_master_proc
  40. */
  41. #ifndef _RESPONDER__H___
  42. #define _RESPONDER__H___
  43. #include "config.h"
  44. #include <fcgiapp.h> /* fcgi library; put it first*/
  45. #include <stdlib.h>
  46. #include <unistd.h>
  47. #include <string.h>
  48. #include <syslog.h>
  49. #include <errno.h>
  50. #include <time.h>
  51. #include <sys/types.h>
  52. #include <sys/ipc.h>
  53. #include <sys/sem.h>
  54. #include "logger.h"
  55. #include "pyworker.h"
  56. void init_context();
  57. /**@brief The responder loop
  58. * @ingroup work_master_proc
  59. * The main function of the fcgi app fork child
  60. * @param int max_requests : exit normally after this number of requests. If
  61. * 0 given never exit.
  62. * @param char* python_entrymodule a python module name
  63. * @param char* python_entrymodule a python callable name from entry module
  64. * @param unsigned int max_requests before exiting worker
  65. * @param unsigned int minimum workers count
  66. * @param unsigned int maximum wrokers count
  67. * @return 0 on success
  68. */
  69. int responder_loop();
  70. /**@brief Spawn a worker given an entrypoint
  71. * @ingroup work_master_proc
  72. * Spawn a new worker process and prepare ENV & request forwarding
  73. * @param int worker uid
  74. * @return child PID
  75. */
  76. pid_t spawn(int);
  77. /**@deprecated Not used */
  78. int pyfcgi_pool_state();
  79. /**@brief Check if the pool is idle : if not able to timedwait the pool is busy
  80. * @param const struct timespec timeout
  81. * @return 1 if busy else 0
  82. * @note exit on error
  83. */
  84. int pyfcgi_pool_idle(const struct timespec *timeout);
  85. /**@brief Exit after closing all stuff like semaphores
  86. * @ingroup work_master_proc
  87. */
  88. void clean_exit(int);
  89. /**@brief Handle signals and forward it to workers */
  90. void pool_sighandler(int signum);
  91. /**@brief Handle watchdog alarm signal */
  92. void pool_wd_sighandler(int signum);
  93. #endif