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

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