00001 /* Copyright 1999-2005 The Apache Software Foundation or its licensors, as 00002 * applicable. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * 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 00017 #ifndef AP_LISTEN_H 00018 #define AP_LISTEN_H 00019 00020 #include "apr_network_io.h" 00021 #include "httpd.h" 00022 #include "http_config.h" 00023 00024 /** 00025 * @package Apache Listeners Library 00026 */ 00027 00028 typedef struct ap_listen_rec ap_listen_rec; 00029 typedef apr_status_t (*accept_function)(void **csd, ap_listen_rec *lr, apr_pool_t *ptrans); 00030 00031 /** 00032 * Apache's listeners record. These are used in the Multi-Processing Modules 00033 * to setup all of the sockets for the MPM to listen to and accept on. 00034 */ 00035 struct ap_listen_rec { 00036 /** 00037 * The next listener in the list 00038 */ 00039 ap_listen_rec *next; 00040 /** 00041 * The actual socket 00042 */ 00043 apr_socket_t *sd; 00044 /** 00045 * The sockaddr the socket should bind to 00046 */ 00047 apr_sockaddr_t *bind_addr; 00048 /** 00049 * The accept function for this socket 00050 */ 00051 accept_function accept_func; 00052 /** 00053 * Is this socket currently active 00054 */ 00055 int active; 00056 /* more stuff here, like which protocol is bound to the port */ 00057 }; 00058 00059 /** 00060 * The global list of ap_listen_rec structures 00061 */ 00062 AP_DECLARE_DATA extern ap_listen_rec *ap_listeners; 00063 00064 /** 00065 * Setup all of the defaults for the listener list 00066 */ 00067 void ap_listen_pre_config(void); 00068 #if !defined(SPMT_OS2_MPM) 00069 /** 00070 * Loop through the global ap_listen_rec list and create all of the required 00071 * sockets. This executes the listen and bind on the sockets. 00072 * @param s The global server_rec 00073 * @return The number of open sockets. 00074 * @warning This function is not available to Windows platforms, or the 00075 * Prefork or SPMT_OS2 MPMs. 00076 */ 00077 int ap_setup_listeners(server_rec *s); 00078 #endif 00079 /* Split into two #if's to make the exports scripts easier. 00080 */ 00081 #if defined(SPMT_OS2_MPM) 00082 /** 00083 * Create and open a socket on the specified port. This includes listening 00084 * and binding the socket. 00085 * @param process The process record for the currently running server 00086 * @param port The port to open a socket on. 00087 * @return The number of open sockets 00088 * @warning This function is only available to Windows platforms, or the 00089 * Prefork or SPMT_OS2 MPMs. 00090 */ 00091 int ap_listen_open(process_rec *process, apr_port_t port); 00092 #endif 00093 00094 /* Although these functions are exported from libmain, they are not really 00095 * public functions. These functions are actually called while parsing the 00096 * config file, when one of the LISTEN_COMMANDS directives is read. These 00097 * should not ever be called by external modules. ALL MPMs should include 00098 * LISTEN_COMMANDS in their command_rec table so that these functions are 00099 * called. 00100 */ 00101 const char *ap_set_listenbacklog(cmd_parms *cmd, void *dummy, const char *arg); 00102 const char *ap_set_listener(cmd_parms *cmd, void *dummy, const char *ips); 00103 const char *ap_set_send_buffer_size(cmd_parms *cmd, void *dummy, 00104 const char *arg); 00105 00106 #define LISTEN_COMMANDS \ 00107 AP_INIT_TAKE1("ListenBacklog", ap_set_listenbacklog, NULL, RSRC_CONF, \ 00108 "Maximum length of the queue of pending connections, as used by listen(2)"), \ 00109 AP_INIT_TAKE1("Listen", ap_set_listener, NULL, RSRC_CONF, \ 00110 "A port number or a numeric IP address and a port number"), \ 00111 AP_INIT_TAKE1("SendBufferSize", ap_set_send_buffer_size, NULL, RSRC_CONF, \ 00112 "Send buffer size in bytes") 00113 00114 #endif