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.

ipc.h 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 IPC Inter process communication mechanism
  20. */
  21. /**@file ipc.h
  22. * @ingroup IPC */
  23. #ifndef __IPC_H___
  24. #define __IPC_H___
  25. #include <fcgiapp.h>
  26. #include <fcgi_stdio.h> /* fcgi library; put it first*/
  27. #include <fcntl.h>
  28. #include <semaphore.h>
  29. #include <sys/stat.h>
  30. /**@brief Format for sem and shm */
  31. #define PYFCGI_IPCNAME_FMT "/PyFCGI-%d_%s"
  32. /**@brief Number of semaphores */
  33. #define PYFCGI_NSEM 3
  34. #define SEM_WSTATE 0
  35. #define SEM_WREQS 1
  36. #define SEM_STATS 2
  37. /**@brief Semaphore uniq name */
  38. #define PYFCGI_SEMNAMES {"WState", "WReqs", "SHMStats"}
  39. #define PyFCGI_SEM(i) (PyFCGI_conf.sems[i])
  40. #define PyFCGI_SEM_OPEN(i) (PyFCGI_conf.sems[i].sem != NULL)
  41. /**@defgroup IPC_flags IPC component flags
  42. * @ingroup IPC
  43. * @brief For IPC component selection */
  44. /**@brief Worker state semaphore
  45. * @ingroup IPC_flags */
  46. #define IPC_WSTATE 2
  47. /**@brief Request counter semaphore
  48. * @ingroup IPC_flags */
  49. #define IPC_WREQS 4
  50. /**@brief Monitor <-> pool semaphore
  51. * @ingroup IPC_flags */
  52. #define IPC_SEMST 8
  53. /**@brief Monitor <-> pool SHM flag
  54. * @ingroup IPC_flags */
  55. #define IPC_SHMST 16
  56. typedef unsigned short pyfcgi_ipc_flag_t;
  57. #include "conf.h"
  58. /**@brief Set semaphore names using master process PID as uniq key
  59. * @param pid_t master process PID
  60. */
  61. void pyfcgi_name_sems(pid_t master_pid);
  62. /**@brief Do shm_open & sem_open given component indicated by flag
  63. * @param pyfcgi_ipc_flah_t flag a binary or combination of component flags
  64. * @return 0 if no error else -1
  65. * @note Stores the flag in configuration context
  66. * @see IPC_flags
  67. */
  68. int pyfcgi_IPC_init(pyfcgi_ipc_flag_t flag);
  69. /**@brief Same than @ref pyfchi_IPC_init but with O_CREAT flag set */
  70. int pyfcgi_IPC_create(pyfcgi_ipc_flag_t flag);
  71. /**@brief Close previously opened IPC component (from conf context stored flag)
  72. * @return 0 if no error else -1
  73. */
  74. int pyfcgi_IPC_close();
  75. /**@brief IPC ressources cleanup */
  76. int pyfcgi_IPC_destroy(pyfcgi_ipc_flag_t flag);
  77. #endif