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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "pyworker.h"
  55. extern int pyfcgi_semid;
  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_entrypoint a path to a python entrypoint
  63. * @param unsigned int max_requests before exiting worker
  64. * @param unsigned int minimum workers count
  65. * @param unsigned int maximum wrokers count
  66. * @return 0 on success
  67. */
  68. int responder_loop(char *py_entrypoint, unsigned int max_reqs,
  69. unsigned int min_wrk, unsigned int max_wrk);
  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 char* python_entrypoint a path to a python entrypoint
  74. * @param int worker uid
  75. * @param int semid for FCGI access
  76. * @param int max request before worker restart
  77. * @return child PID
  78. */
  79. pid_t spawn(char*, int, int, int);
  80. /**@brief Generate a new semaphore from given key
  81. * @ingroup work_master_proc
  82. * @note set pyfcgi_semid
  83. * @return int semid
  84. */
  85. int new_semaphore();
  86. /**@brief Exit after closing all stuff like semaphores
  87. * @ingroup work_master_proc
  88. */
  89. void clean_exit(int);
  90. #endif