1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "apr_portable.h"
19 #include "apr_strings.h"
20 #include "apr_thread_proc.h"
21 #include "apr_signal.h"
23 #define APR_WANT_STDIO
24 #define APR_WANT_STRFUNC
30 #if APR_HAVE_SYS_TYPES_H
31 #include <sys/types.h>
34 #include "ap_config.h"
36 #include "mpm_default.h"
37 #include "http_main.h"
39 #include "http_config.h"
40 #include "http_core.h" /* for get_remote_host */
41 #include "http_connection.h"
42 #include "scoreboard.h"
44 #include "util_mutex.h"
46 #include "http_vhost.h"
47 #include "mpm_common.h"
48 #include "ap_listen.h"
51 #include "apr_skiplist.h"
52 #include "apr_thread_pool.h"
53 #include "util_time.h"
60 #ifdef HAVE_SYS_PROCESSOR_H
61 #include <sys/processor.h> /* for bindprocessor() */
65 #include <sys/times.h>
67 /* Limit on the total --- clients will be locked out if more servers than
68 * this are needed. It is intended solely to keep the server from crashing
69 * when things get out of hand.
71 * We keep a hard maximum number of servers, for two reasons --- first off,
72 * in case something goes seriously wrong, we want to stop the fork bomb
73 * short of actually crashing the machine we're running on by filling some
74 * kernel table. Secondly, it keeps the size of the scoreboard file small
75 * enough that we can read the whole thing without worrying too much about
78 #ifndef DEFAULT_SERVER_LIMIT
79 #define DEFAULT_SERVER_LIMIT 256
82 /* Admin can't tune ServerLimit beyond MAX_SERVER_LIMIT. We want
83 * some sort of compile-time limit to help catch typos.
85 #ifndef MAX_SERVER_LIMIT
86 #define MAX_SERVER_LIMIT 200000
89 /* Limit on the threads per process. Clients will be locked out if more than
92 * We keep this for one reason it keeps the size of the scoreboard file small
93 * enough that we can read the whole thing without worrying too much about
96 #ifndef DEFAULT_THREAD_LIMIT
97 #define DEFAULT_THREAD_LIMIT 64
100 /* Admin can't tune ThreadLimit beyond MAX_THREAD_LIMIT. We want
101 * some sort of compile-time limit to help catch typos.
103 #ifndef MAX_THREAD_LIMIT
104 #define MAX_THREAD_LIMIT 100000
107 #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
112 /* data retained by prefork across load/unload of the module
113 * allocated on first call to pre-config hook; located on
114 * subsequent calls to pre-config hook
116 typedef struct motorz_core_t motorz_core_t;
117 struct motorz_core_t {
118 ap_unixd_mpm_retained_data *mpm;
120 int first_server_limit;
121 int maxclients_reported;
123 * The max child slot ever assigned, preserved across restarts. Necessary
124 * to deal with MaxRequestWorkers changes across AP_SIG_GRACEFUL restarts. We
125 * use this value to optimize routines that have to scan the entire scoreboard.
127 int max_daemons_limit;
129 apr_thread_mutex_t *mtx;
130 apr_pollset_t *pollset;
131 apr_skiplist *timeout_ring;
132 apr_thread_pool_t *workers;
135 typedef struct motorz_child_bucket motorz_child_bucket;
136 struct motorz_child_bucket {
138 ap_listen_rec *listeners;
139 apr_proc_mutex_t *mutex;
147 } motorz_poll_type_e;
149 typedef struct motorz_sb_t motorz_sb_t;
152 motorz_poll_type_e type;
156 typedef void (*motorz_timer_cb) (motorz_core_t *mz, void *baton);
157 typedef void (*motorz_io_sock_cb) (motorz_core_t *mz, apr_socket_t *sock,
158 int flags, void *baton);
159 typedef void (*motorz_io_file_cb) (motorz_core_t *mz, apr_socket_t *sock,
160 int flags, void *baton);
163 typedef struct motorz_timer_t motorz_timer_t;
164 struct motorz_timer_t
173 typedef struct motorz_conn_t motorz_conn_t;
179 apr_bucket_alloc_t *ba;
181 /** connection record this struct refers to */
183 /** request record (if any) this struct refers to */
185 /** is the current conn_rec suspended? */
187 /** poll file descriptor information */
189 /** public parts of the connection state */
191 /** timer associated with the connection */
192 motorz_timer_t timer;