123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /*
- * 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 work_master_proc Worker handler process
- * @brief This process use the @ref responder_loop() function as "main" function
- *
- * @section work_master_spawn Spawning workers
- * This subprocess handle worker spawning using @ref spawn(). A POSIX semaphore
- * allow to know when the worker pool is idle or not :
- *
- * @subsection work_master_spawn_sem Semaphore idle & busy detection
- * When a new worker is ready (idle) it add 1 to the semaphore, when processing
- * a request it substract 1 to the semaphore (done in @ref work() function in
- * @ref worker_process )
- *
- * When semtimedop blocks on wait_for_zero operation it means that the pool is
- * idle. Instead, if the semtimedop returns imediately it means a new worker
- * can be spawned.
- *
- * @ingroup processes
- * @ingroup main_proc
- */
- /**@file responder.h
- * @ingroup work_master_proc
- */
- #ifndef _RESPONDER__H___
- #define _RESPONDER__H___
- #include "config.h"
-
- #include <fcgiapp.h> /* fcgi library; put it first*/
-
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <syslog.h>
- #include <errno.h>
- #include <time.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/sem.h>
-
- #include "logger.h"
- #include "pyworker.h"
-
-
- void init_context();
-
- /**@brief The responder loop
- * @ingroup work_master_proc
- * The main function of the fcgi app fork child
- * @param int max_requests : exit normally after this number of requests. If
- * 0 given never exit.
- * @param char* python_entrymodule a python module name
- * @param char* python_entrymodule a python callable name from entry module
- * @param unsigned int max_requests before exiting worker
- * @param unsigned int minimum workers count
- * @param unsigned int maximum wrokers count
- * @return 0 on success
- */
- int responder_loop();
-
-
- /**@brief Spawn a worker given an entrypoint
- * @ingroup work_master_proc
- * Spawn a new worker process and prepare ENV & request forwarding
- * @param int worker uid
- * @return child PID
- */
- pid_t spawn(int);
-
-
- /**@deprecated Not used */
- int pyfcgi_pool_state();
- /**@brief Check if the pool is idle : if not able to timedwait the pool is busy
- * @param const struct timespec timeout
- * @return 1 if busy else 0
- * @note exit on error
- */
- int pyfcgi_pool_idle(const struct timespec *timeout);
-
- /**@brief Exit after closing all stuff like semaphores
- * @ingroup work_master_proc
- */
- void clean_exit(int);
-
- /**@brief Handle signals and forward it to workers */
- void pool_sighandler(int signum);
-
- /**@brief Handle watchdog alarm signal */
- void pool_wd_sighandler(int signum);
-
- #endif
|