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

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