listen.c revision 3c4f451140dd2ba70ee77274ed8155f451184917
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse/* ====================================================================
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * The Apache Software License, Version 1.1
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * reserved.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * Redistribution and use in source and binary forms, with or without
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * modification, are permitted provided that the following conditions
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * are met:
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * 1. Redistributions of source code must retain the above copyright
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * notice, this list of conditions and the following disclaimer.
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * 2. Redistributions in binary form must reproduce the above copyright
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * notice, this list of conditions and the following disclaimer in
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * the documentation and/or other materials provided with the
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * distribution.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * 3. The end-user documentation included with the redistribution,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * if any, must include the following acknowledgment:
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * "This product includes software developed by the
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * Apache Software Foundation (http://www.apache.org/)."
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * Alternately, this acknowledgment may appear in the software itself,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * if and wherever such third-party acknowledgments normally appear.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * 4. The names "Apache" and "Apache Software Foundation" must
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * not be used to endorse or promote products derived from this
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * software without prior written permission. For written
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * permission, please contact apache@apache.org.
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * 5. Products derived from this software may not be called "Apache",
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * nor may "Apache" appear in their name, without prior written
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * permission of the Apache Software Foundation.
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * SUCH DAMAGE.
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * ====================================================================
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * This software consists of voluntary contributions made by many
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * individuals on behalf of the Apache Software Foundation. For more
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * information on the Apache Software Foundation, please see
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * Portions of this software are based upon public domain software
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * originally written at the National Center for Supercomputing Applications,
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * University of Illinois, Urbana-Champaign.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse/* TODO: make_sock is just begging and screaming for APR abstraction */
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrsestatic apr_status_t make_sock(apr_pool_t *p, ap_listen_rec *server)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse "make_sock: for address %pI, setsockopt: (SO_REUSEADDR)",
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse "make_sock: for address %pI, setsockopt: (SO_KEEPALIVE)",
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * To send data over high bandwidth-delay connections at full
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * speed we must force the TCP window to open wide enough to keep the
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * pipe full. The default window size on many systems
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * is only 4kB. Cross-country WAN connections of 100ms
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * at 1Mb/s are not impossible for well connected sites.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * If we assume 100ms cross-country latency,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * a 4kB buffer limits throughput to 40kB/s.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * To avoid this problem I've added the SendBufferSize directive
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * to allow the web master to configure send buffer size.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * The trade-off of larger buffers is that more kernel memory
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * is consumed. YMMV, know your customers and your network!
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * -John Heidemann <johnh@isi.edu> 25-Oct-96
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * If no size is specified, use the kernel default.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse stat = apr_setsocketopt(s, APR_SO_SNDBUF, send_buffer_size);
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse "make_sock: failed to set SendBufferSize for "
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse "address %pI, using default",
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse /* not a fatal error */
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rse if ((stat = apr_bind(s, server->bind_addr)) != APR_SUCCESS) {
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rse "make_sock: could not bind to address %pI",
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rse if ((stat = apr_listen(s, ap_listenbacklog)) != APR_SUCCESS) {
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rse "make_sock: unable to listen for connections on address %pI",
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse /* We know the platform supports IPv6, but this particular
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * system may not have IPv6 enabled. See if we can get an
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * AF_INET6 socket.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if (apr_socket_create(&tmp_sock, APR_INET6, SOCK_STREAM, APR_INHERIT,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrsestatic void alloc_listener(process_rec *process, char *addr, apr_port_t port)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse /* see if we've got an old listener for this address:port */
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse for (walk = &old_listeners; *walk; walk = &(*walk)->next) {
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse /* re-use existing record */
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse /* this has to survive restarts */
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if ((status = apr_sockaddr_info_get(&new->bind_addr, addr, APR_UNSPEC, port, 0,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse ap_log_perror(APLOG_MARK, APLOG_CRIT, status, process->pool,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse "alloc_listener: failed to set up sockaddr for %s", addr);
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if ((status = apr_socket_create(&new->sd, new->bind_addr->sa.sin.sin_family,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse SOCK_STREAM, APR_INHERIT, process->pool)) != APR_SUCCESS) {
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse ap_log_perror(APLOG_MARK, APLOG_CRIT, status, process->pool,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse#if !defined(SPMT_OS2_MPM)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrseint ap_listen_open(process_rec *process, apr_port_t port)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse /* allocate a default listener if necessary */
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse alloc_listener(process, NULL, port ? port : DEFAULT_HTTP_PORT);
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse /* close the old listeners */
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse/* free(lr);*/
a943533fd4d91d114af622731a405407990c4fb1rse apr_pool_cleanup_register(pconf, NULL, apr_pool_cleanup_null, close_listeners_on_exec);
a943533fd4d91d114af622731a405407990c4fb1rseconst char *ap_set_listener(cmd_parms *cmd, void *dummy, const char *ips)
return err;
if (scope_id) {
if (!port) {
return NULL;
return err;
ap_listenbacklog = b;
return NULL;
return err;
send_buffer_size = s;
return NULL;