]> granicus.if.org Git - apache/blob - include/ap_listen.h
When a rewrite to proxy is configured in the server config, a check is made to make...
[apache] / include / ap_listen.h
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @file  ap_listen.h
19  * @brief Apache Listeners Library
20  *
21  * @defgroup APACHE_CORE_LISTEN Apache Listeners Library
22  * @ingroup  APACHE_CORE
23  * @{
24  */
25
26 #ifndef AP_LISTEN_H
27 #define AP_LISTEN_H
28
29 #include "apr_network_io.h"
30 #include "httpd.h"
31 #include "http_config.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 typedef struct ap_slave_t ap_slave_t;
38 typedef struct ap_listen_rec ap_listen_rec;
39 typedef apr_status_t (*accept_function)(void **csd, ap_listen_rec *lr, apr_pool_t *ptrans);
40
41 /**
42  * @brief Apache's listeners record.
43  *
44  * These are used in the Multi-Processing Modules
45  * to setup all of the sockets for the MPM to listen to and accept on.
46  */
47 struct ap_listen_rec {
48     /**
49      * The next listener in the list
50      */
51     ap_listen_rec *next;
52     /**
53      * The actual socket
54      */
55     apr_socket_t *sd;
56     /**
57      * The sockaddr the socket should bind to
58      */
59     apr_sockaddr_t *bind_addr;
60     /**
61      * The accept function for this socket
62      */
63     accept_function accept_func;
64     /**
65      * Is this socket currently active
66      */
67     int active;
68     /**
69      * The default protocol for this listening socket.
70      */
71     const char* protocol;
72
73     ap_slave_t *slave;
74
75     /**
76      * Allow the accept_func to return a wider set of return codes
77      */
78     int use_specific_errors;
79
80 };
81
82 /**
83  * The global list of ap_listen_rec structures
84  */
85 AP_DECLARE_DATA extern ap_listen_rec *ap_listeners;
86 AP_DECLARE_DATA extern int ap_num_listen_buckets;
87 AP_DECLARE_DATA extern int ap_have_so_reuseport;
88 AP_DECLARE_DATA extern int ap_accept_errors_nonfatal;
89
90 AP_DECLARE(int) ap_accept_error_is_nonfatal(apr_status_t rv);
91
92 /**
93  * Setup all of the defaults for the listener list
94  */
95 AP_DECLARE(void) ap_listen_pre_config(void);
96
97 /**
98  * Loop through the global ap_listen_rec list and create all of the required
99  * sockets.  This executes the listen and bind on the sockets.
100  * @param s The global server_rec
101  * @return The number of open sockets.
102  */
103 AP_DECLARE(int) ap_setup_listeners(server_rec *s);
104
105 /**
106  * This function duplicates ap_listeners into multiple buckets when configured
107  * to (see ListenCoresBucketsRatio) and the platform supports it (eg. number of
108  * online CPU cores and SO_REUSEPORT available).
109  * @param p The config pool
110  * @param s The global server_rec
111  * @param buckets The array of listeners buckets.
112  * @param num_buckets The total number of listeners buckets (array size).
113  * @remark If the given *num_buckets is 0 (input), it will be computed
114  *         according to the platform capacities, otherwise (positive) it
115  *         will be preserved. The number of listeners duplicated will
116  *         always match *num_buckets, be it computed or given.
117  */
118 AP_DECLARE(apr_status_t) ap_duplicate_listeners(apr_pool_t *p, server_rec *s,
119                                                 ap_listen_rec ***buckets,
120                                                 int *num_buckets);
121
122 /**
123  * Loop through the global ap_listen_rec list and close each of the sockets.
124  */
125 AP_DECLARE_NONSTD(void) ap_close_listeners(void);
126
127 /**
128  * Loop through the given ap_listen_rec list and close each of the sockets.
129  * @param listeners The listener to close.
130  */
131 AP_DECLARE_NONSTD(void) ap_close_listeners_ex(ap_listen_rec *listeners);
132
133 /**
134  * FIXMEDOC
135  */
136 AP_DECLARE_NONSTD(int) ap_close_selected_listeners(ap_slave_t *);
137
138 /* Although these functions are exported from libmain, they are not really
139  * public functions.  These functions are actually called while parsing the
140  * config file, when one of the LISTEN_COMMANDS directives is read.  These
141  * should not ever be called by external modules.  ALL MPMs should include
142  * LISTEN_COMMANDS in their command_rec table so that these functions are
143  * called.
144  */
145 AP_DECLARE_NONSTD(const char *) ap_set_listenbacklog(cmd_parms *cmd, void *dummy, const char *arg);
146 AP_DECLARE_NONSTD(const char *) ap_set_listencbratio(cmd_parms *cmd, void *dummy, const char *arg);
147 AP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy,
148                                                 int argc, char *const argv[]);
149 AP_DECLARE_NONSTD(const char *) ap_set_send_buffer_size(cmd_parms *cmd, void *dummy,
150                                                         const char *arg);
151 AP_DECLARE_NONSTD(const char *) ap_set_receive_buffer_size(cmd_parms *cmd,
152                                                            void *dummy,
153                                                            const char *arg);
154
155 AP_DECLARE_NONSTD(const char *) ap_set_accept_errors_nonfatal(cmd_parms *cmd,
156                                                            void *dummy,
157                                                            int flag);
158
159 #define LISTEN_COMMANDS \
160 AP_INIT_TAKE1("ListenBacklog", ap_set_listenbacklog, NULL, RSRC_CONF, \
161   "Maximum length of the queue of pending connections, as used by listen(2)"), \
162 AP_INIT_TAKE1("ListenCoresBucketsRatio", ap_set_listencbratio, NULL, RSRC_CONF, \
163   "Ratio between the number of CPU cores (online) and the number of listeners buckets"), \
164 AP_INIT_TAKE_ARGV("Listen", ap_set_listener, NULL, RSRC_CONF, \
165   "A port number or a numeric IP address and a port number, and an optional protocol"), \
166 AP_INIT_TAKE1("SendBufferSize", ap_set_send_buffer_size, NULL, RSRC_CONF, \
167   "Send buffer size in bytes"), \
168 AP_INIT_TAKE1("ReceiveBufferSize", ap_set_receive_buffer_size, NULL, \
169               RSRC_CONF, "Receive buffer size in bytes"), \
170 AP_INIT_FLAG("AcceptErrorsNonFatal", ap_set_accept_errors_nonfatal, NULL, \
171               RSRC_CONF, "Some accept() errors are not fatal to the process")
172 #ifdef __cplusplus
173 }
174 #endif
175
176 #endif
177 /** @} */