ap_listen.h revision a742cbb3e85669473b3233f30e3978bb6a20083c
2N/A/* Licensed to the Apache Software Foundation (ASF) under one or more
2N/A * contributor license agreements. See the NOTICE file distributed with
2N/A * this work for additional information regarding copyright ownership.
2N/A * The ASF licenses this file to You under the Apache License, Version 2.0
2N/A * (the "License"); you may not use this file except in compliance with
2N/A * the License. You may obtain a copy of the License at
2N/A *
2N/A * http://www.apache.org/licenses/LICENSE-2.0
2N/A *
2N/A * Unless required by applicable law or agreed to in writing, software
2N/A * distributed under the License is distributed on an "AS IS" BASIS,
2N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2N/A * See the License for the specific language governing permissions and
2N/A * limitations under the License.
2N/A */
2N/A
2N/A/**
2N/A * @file ap_listen.h
2N/A * @brief Apache Listeners Library
2N/A *
2N/A * @defgroup APACHE_CORE_LISTEN Apache Listeners Library
2N/A * @ingroup APACHE_CORE
2N/A * @{
2N/A */
2N/A
2N/A#ifndef AP_LISTEN_H
2N/A#define AP_LISTEN_H
2N/A
2N/A#include "apr_network_io.h"
2N/A#include "httpd.h"
2N/A#include "http_config.h"
12N/A
12N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/Atypedef struct ap_slave_t ap_slave_t;
26N/Atypedef struct ap_listen_rec ap_listen_rec;
26N/Atypedef apr_status_t (*accept_function)(void **csd, ap_listen_rec *lr, apr_pool_t *ptrans);
2N/A
26N/A/**
38N/A * @brief Apache's listeners record.
26N/A *
26N/A * These are used in the Multi-Processing Modules
26N/A * to setup all of the sockets for the MPM to listen to and accept on.
26N/A */
26N/Astruct ap_listen_rec {
26N/A /**
26N/A * The next listener in the list
26N/A */
26N/A ap_listen_rec *next;
26N/A /**
26N/A * The actual socket
26N/A */
26N/A apr_socket_t *sd;
26N/A /**
26N/A * The sockaddr the socket should bind to
26N/A */
26N/A apr_sockaddr_t *bind_addr;
26N/A /**
26N/A * The accept function for this socket
26N/A */
2N/A accept_function accept_func;
26N/A /**
26N/A * Is this socket currently active
26N/A */
26N/A int active;
26N/A /**
26N/A * The default protocol for this listening socket.
26N/A */
26N/A const char* protocol;
26N/A
26N/A ap_slave_t *slave;
26N/A};
26N/A
26N/A/**
2N/A * The global list of ap_listen_rec structures
26N/A */
26N/AAP_DECLARE_DATA extern ap_listen_rec *ap_listeners;
27N/AAP_DECLARE_DATA extern int ap_num_listen_buckets;
27N/AAP_DECLARE_DATA extern int ap_have_so_reuseport;
27N/A
26N/A/**
26N/A * Setup all of the defaults for the listener list
12N/A */
30N/AAP_DECLARE(void) ap_listen_pre_config(void);
26N/A
26N/A/**
26N/A * Loop through the global ap_listen_rec list and create all of the required
2N/A * sockets. This executes the listen and bind on the sockets.
26N/A * @param s The global server_rec
30N/A * @return The number of open sockets.
26N/A */
2N/AAP_DECLARE(int) ap_setup_listeners(server_rec *s);
7N/A
27N/A/**
27N/A * This function duplicates ap_listeners into multiple buckets when configured
27N/A * to (see ListenCoresBucketsRatio) and the platform supports it (eg. number of
38N/A * online CPU cores and SO_REUSEPORT available).
38N/A * @param p The config pool
38N/A * @param s The global server_rec
21N/A * @param buckets The array of listeners buckets.
7N/A * @param num_buckets The total number of listeners buckets (array size).
26N/A * @remark If the given *num_buckets is 0 (input), it will be computed
26N/A * according to the platform capacities, otherwise (positive) it
38N/A * will be preserved. The number of listeners duplicated will
26N/A * always match *num_buckets, be it computed or given.
26N/A */
26N/AAP_DECLARE(apr_status_t) ap_duplicate_listeners(apr_pool_t *p, server_rec *s,
30N/A ap_listen_rec ***buckets,
26N/A int *num_buckets);
46N/A
46N/A/**
46N/A * Loop through the global ap_listen_rec list and close each of the sockets.
26N/A */
26N/AAP_DECLARE_NONSTD(void) ap_close_listeners(void);
46N/A
46N/A/**
46N/A * Loop through the given ap_listen_rec list and close each of the sockets.
2N/A * @param listener The listener to close.
46N/A */
53N/AAP_DECLARE_NONSTD(void) ap_close_listeners_ex(ap_listen_rec *listeners);
53N/A
46N/A/**
46N/A * FIXMEDOC
26N/A */
46N/AAP_DECLARE_NONSTD(int) ap_close_selected_listeners(ap_slave_t *);
46N/A
46N/A/* Although these functions are exported from libmain, they are not really
53N/A * public functions. These functions are actually called while parsing the
26N/A * config file, when one of the LISTEN_COMMANDS directives is read. These
46N/A * should not ever be called by external modules. ALL MPMs should include
46N/A * LISTEN_COMMANDS in their command_rec table so that these functions are
46N/A * called.
53N/A */
46N/AAP_DECLARE_NONSTD(const char *) ap_set_listenbacklog(cmd_parms *cmd, void *dummy, const char *arg);
53N/AAP_DECLARE_NONSTD(const char *) ap_set_listencbratio(cmd_parms *cmd, void *dummy, const char *arg);
53N/AAP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy,
2N/A int argc, char *const argv[]);
46N/AAP_DECLARE_NONSTD(const char *) ap_set_send_buffer_size(cmd_parms *cmd, void *dummy,
38N/A const char *arg);
46N/AAP_DECLARE_NONSTD(const char *) ap_set_receive_buffer_size(cmd_parms *cmd,
53N/A void *dummy,
53N/A const char *arg);
53N/A
46N/A#define LISTEN_COMMANDS \
38N/AAP_INIT_TAKE1("ListenBacklog", ap_set_listenbacklog, NULL, RSRC_CONF, \
46N/A "Maximum length of the queue of pending connections, as used by listen(2)"), \
46N/AAP_INIT_TAKE1("ListenCoresBucketsRatio", ap_set_listencbratio, NULL, RSRC_CONF, \
26N/A "Ratio between the number of CPU cores (online) and the number of listeners buckets"), \
48N/AAP_INIT_TAKE_ARGV("Listen", ap_set_listener, NULL, RSRC_CONF, \
46N/A "A port number or a numeric IP address and a port number, and an optional protocol"), \
2N/AAP_INIT_TAKE1("SendBufferSize", ap_set_send_buffer_size, NULL, RSRC_CONF, \
38N/A "Send buffer size in bytes"), \
26N/AAP_INIT_TAKE1("ReceiveBufferSize", ap_set_receive_buffer_size, NULL, \
2N/A RSRC_CONF, "Receive buffer size in bytes")
32N/A
32N/A#ifdef __cplusplus
32N/A}
32N/A#endif
32N/A
32N/A#endif
32N/A/** @} */
32N/A