Tests about a simple python3 fastcgi runner using libfcgi and the Python-C API.
python
c
wsgi
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

responder.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 <fcgi_stdio.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. extern int pyfcgi_semid;
  57. void init_context();
  58. /**@brief The responder loop
  59. * @ingroup work_master_proc
  60. * The main function of the fcgi app fork child
  61. * @param int max_requests : exit normally after this number of requests. If
  62. * 0 given never exit.
  63. * @param char* python_entrymodule a python module name
  64. * @param char* python_entrymodule a python callable name from entry module
  65. * @param unsigned int max_requests before exiting worker
  66. * @param unsigned int minimum workers count
  67. * @param unsigned int maximum wrokers count
  68. * @return 0 on success
  69. */
  70. int responder_loop();
  71. /**@brief Spawn a worker given an entrypoint
  72. * @ingroup work_master_proc
  73. * Spawn a new worker process and prepare ENV & request forwarding
  74. * @param int worker uid
  75. * @param int semid for FCGI access
  76. * @return child PID
  77. */
  78. pid_t spawn(int, int);
  79. /**@brief Generate a new semaphore from given key
  80. * @ingroup work_master_proc
  81. * @note set pyfcgi_semid
  82. * @return int semid
  83. */
  84. int new_semaphore();
  85. /**@brief Exit after closing all stuff like semaphores
  86. * @ingroup work_master_proc
  87. */
  88. void clean_exit(int);
  89. #endif