12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- /*
- * Copyright (C) 2019 Weber Yann
- *
- * This file is part of PyFCGI.
- *
- * PyFCGI is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * any later version.
- *
- * PyFCGI is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with PyFCGI. If not, see <http://www.gnu.org/licenses/>.
- */
- /**@defgroup IPC Inter process communication mechanism
- */
- /**@file ipc.h
- * @ingroup IPC */
- #ifndef __IPC_H___
- #define __IPC_H___
-
- #include <fcgiapp.h>
- #include <fcgi_stdio.h> /* fcgi library; put it first*/
-
- #include <fcntl.h>
- #include <semaphore.h>
- #include <sys/stat.h>
-
- /**@brief Format for sem and shm */
- #define PYFCGI_IPCNAME_FMT "/PyFCGI-%d_%s"
- /**@brief Number of semaphores */
- #define PYFCGI_NSEM 3
-
- #define SEM_WSTATE 0
- #define SEM_WREQS 1
- #define SEM_STATS 2
- /**@brief Semaphore uniq name */
- #define PYFCGI_SEMNAMES {"WState", "WReqs", "SHMStats"}
-
- #define PyFCGI_SEM(i) (PyFCGI_conf.sems[i])
-
- /**@defgroup IPC_flags IPC component flags
- * @ingroup IPC
- * @brief For IPC component selection */
- /**@brief Worker state semaphore
- * @ingroup IPC_flags */
- #define IPC_WSTATE 2
- /**@brief Worker state semaphore
- * @ingroup IPC_flags */
- #define IPC_WREQS 4
- /**@brief Worker state semaphore
- * @ingroup IPC_flags */
- #define IPC_SEMST 8
- /**@brief Worker state semaphore
- * @ingroup IPC_flags */
- #define IPC_SHMST 16
-
- typedef unsigned short pyfcgi_ipc_flag_t;
-
- #include "conf.h"
-
- /**@brief Set semaphore names using master process PID as uniq key
- * @param pid_t master process PID
- */
- void pyfcgi_name_sems(pid_t master_pid);
-
- /**@brief Do shm_open & sem_open given component indicated by flag
- * @param pyfcgi_ipc_flah_t flag a binary or combination of component flags
- * @return 0 if no error else -1
- * @note Stores the flag in configuration context
- * @see IPC_flags
- */
- int pyfcgi_IPC_init(pyfcgi_ipc_flag_t flag);
- /**@brief Same than @ref pyfchi_IPC_init but with O_CREAT flag set */
- int pyfcgi_IPC_create(pyfcgi_ipc_flag_t flag);
-
- /**@brief Close previously opened IPC component (from conf context stored flag)
- * @return 0 if no error else -1
- */
- int pyfcgi_IPC_close();
- /**@brief IPC ressources cleanup */
- int pyfcgi_IPC_destroy(pyfcgi_ipc_flag_t flag);
-
- #endif
|