Main Page | Modules | Namespace List | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

ap_mpm.h

Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00026 #ifndef AP_MPM_H
00027 #define AP_MPM_H
00028 
00029 #include "apr_thread_proc.h"
00030 
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif
00034 
00035 /*
00036     The MPM, "multi-processing model" provides an abstraction of the
00037     interface with the OS for distributing incoming connections to
00038     threads/process for processing.  http_main invokes the MPM, and
00039     the MPM runs until a shutdown/restart has been indicated.
00040     The MPM calls out to the apache core via the ap_process_connection
00041     function when a connection arrives.
00042 
00043     The MPM may or may not be multithreaded.  In the event that it is
00044     multithreaded, at any instant it guarantees a 1:1 mapping of threads
00045     ap_process_connection invocations.  
00046 
00047     Note: In the future it will be possible for ap_process_connection
00048     to return to the MPM prior to finishing the entire connection; and
00049     the MPM will proceed with asynchronous handling for the connection;
00050     in the future the MPM may call ap_process_connection again -- but
00051     does not guarantee it will occur on the same thread as the first call.
00052 
00053     The MPM further guarantees that no asynchronous behaviour such as
00054     longjmps and signals will interfere with the user code that is
00055     invoked through ap_process_connection.  The MPM may reserve some
00056     signals for its use (i.e. SIGUSR1), but guarantees that these signals
00057     are ignored when executing outside the MPM code itself.  (This
00058     allows broken user code that does not handle EINTR to function
00059     properly.)
00060 
00061     The suggested server restart and stop behaviour will be "graceful".
00062     However the MPM may choose to terminate processes when the user
00063     requests a non-graceful restart/stop.  When this occurs, the MPM kills
00064     all threads with extreme prejudice, and destroys the pchild pool.
00065     User cleanups registered in the pchild apr_pool_t will be invoked at
00066     this point.  (This can pose some complications, the user cleanups
00067     are asynchronous behaviour not unlike longjmp/signal... but if the
00068     admin is asking for a non-graceful shutdown, how much effort should
00069     we put into doing it in a nice way?)
00070 
00071     unix/posix notes:
00072     - The MPM does not set a SIGALRM handler, user code may use SIGALRM.
00073         But the preferred method of handling timeouts is to use the
00074         timeouts provided by the BUFF abstraction.
00075     - The proper setting for SIGPIPE is SIG_IGN, if user code changes it
00076         for any of their own processing, it must be restored to SIG_IGN
00077         prior to executing or returning to any apache code.
00078     TODO: add SIGPIPE debugging check somewhere to make sure it's SIG_IGN
00079 */
00080 
00091 AP_DECLARE(int) ap_mpm_run(apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf);
00092 
00099 AP_DECLARE(int) ap_graceful_stop_signalled(void);
00100 
00114 AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
00115     const request_rec *r,
00116     apr_proc_t *newproc, 
00117     const char *progname,
00118     const char * const *args, 
00119     const char * const *env,
00120     apr_procattr_t *attr, 
00121     apr_pool_t *p);
00122 
00123 /* Subtypes/Values for AP_MPMQ_IS_THREADED and AP_MPMQ_IS_FORKED        */
00124 #define AP_MPMQ_NOT_SUPPORTED      0  /* This value specifies whether */
00125                                       /* an MPM is capable of         */
00126                                       /* threading or forking.        */
00127 #define AP_MPMQ_STATIC             1  /* This value specifies whether */
00128                                       /* an MPM is using a static #   */
00129                                       /* threads or daemons.          */
00130 #define AP_MPMQ_DYNAMIC            2  /* This value specifies whether */
00131                                       /* an MPM is using a dynamic #  */
00132                                       /* threads or daemons.          */
00133 
00134 /* Values returned for AP_MPMQ_MPM_STATE */
00135 #define AP_MPMQ_STARTING              0
00136 #define AP_MPMQ_RUNNING               1
00137 #define AP_MPMQ_STOPPING              2
00138 
00139 #define AP_MPMQ_MAX_DAEMON_USED       1  /* Max # of daemons used so far */
00140 #define AP_MPMQ_IS_THREADED           2  /* MPM can do threading         */
00141 #define AP_MPMQ_IS_FORKED             3  /* MPM can do forking           */
00142 #define AP_MPMQ_HARD_LIMIT_DAEMONS    4  /* The compiled max # daemons   */
00143 #define AP_MPMQ_HARD_LIMIT_THREADS    5  /* The compiled max # threads   */
00144 #define AP_MPMQ_MAX_THREADS           6  /* # of threads/child by config */
00145 #define AP_MPMQ_MIN_SPARE_DAEMONS     7  /* Min # of spare daemons       */
00146 #define AP_MPMQ_MIN_SPARE_THREADS     8  /* Min # of spare threads       */
00147 #define AP_MPMQ_MAX_SPARE_DAEMONS     9  /* Max # of spare daemons       */
00148 #define AP_MPMQ_MAX_SPARE_THREADS    10  /* Max # of spare threads       */
00149 #define AP_MPMQ_MAX_REQUESTS_DAEMON  11  /* Max # of requests per daemon */
00150 #define AP_MPMQ_MAX_DAEMONS          12  /* Max # of daemons by config   */
00151 #define AP_MPMQ_MPM_STATE            13  /* starting, running, stopping  */
00152 #define AP_MPMQ_IS_ASYNC             14  /* MPM can process async connections  */
00153 
00161 AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result);
00162 
00163 /* Defining GPROF when compiling uses the moncontrol() function to
00164  * disable gprof profiling in the parent, and enable it only for
00165  * request processing in children (or in one_process mode).  It's
00166  * absolutely required to get useful gprof results under linux
00167  * because the profile itimers and such are disabled across a
00168  * fork().  It's probably useful elsewhere as well.
00169  */
00170 #ifdef GPROF
00171 extern void moncontrol(int);
00172 #define AP_MONCONTROL(x) moncontrol(x)
00173 #else
00174 #define AP_MONCONTROL(x)
00175 #endif
00176 
00177 #if AP_ENABLE_EXCEPTION_HOOK
00178 typedef struct ap_exception_info_t {
00179     int sig;
00180     pid_t pid;
00181 } ap_exception_info_t;
00182 
00183 AP_DECLARE_HOOK(int,fatal_exception,(ap_exception_info_t *ei))
00184 #endif /*AP_ENABLE_EXCEPTION_HOOK*/
00185 
00186 #ifdef __cplusplus
00187 }
00188 #endif
00189 
00190 #endif
00191 

© sourcejam.com 2005-2008