listen.c revision ab5581cc78e9d865b0a6ab1404c53347b3276968
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance/* ====================================================================
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * Copyright (c) 1998-1999 The Apache Group. All rights reserved.
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * Redistribution and use in source and binary forms, with or without
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * modification, are permitted provided that the following conditions
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * are met:
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * 1. Redistributions of source code must retain the above copyright
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * notice, this list of conditions and the following disclaimer.
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * 2. Redistributions in binary form must reproduce the above copyright
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * notice, this list of conditions and the following disclaimer in
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * the documentation and/or other materials provided with the
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * distribution.
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * 3. All advertising materials mentioning features or use of this
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * software must display the following acknowledgment:
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * "This product includes software developed by the Apache Group
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * for use in the Apache HTTP server project (http://www.apache.org/)."
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * 4. The names "Apache Server" and "Apache Group" must not be used to
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * endorse or promote products derived from this software without
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * prior written permission. For written permission, please contact
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * apache@apache.org.
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * 5. Products derived from this software may not be called "Apache"
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * nor may "Apache" appear in their names without prior written
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * permission of the Apache Group.
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * 6. Redistributions of any form whatsoever must retain the following
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * acknowledgment:
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * "This product includes software developed by the Apache Group
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * for use in the Apache HTTP server project (http://www.apache.org/)."
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * OF THE POSSIBILITY OF SUCH DAMAGE.
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * ====================================================================
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * This software consists of voluntary contributions made by many
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * individuals on behalf of the Apache Group and was originally based
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * on public domain software written at the National Center for
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * Supercomputing Applications, University of Illinois, Urbana-Champaign.
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * For more information on the Apache Group and the Apache HTTP server
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * project, please see <http://www.apache.org/>.
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance */
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance#include "apr_network_io.h"
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance#include "httpd.h"
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance#include "http_config.h"
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance#include "ap_listen.h"
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance#include "http_log.h"
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Manceap_listen_rec *ap_listeners;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mancestatic ap_listen_rec *old_listeners;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mancestatic int ap_listenbacklog;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mancestatic int send_buffer_size;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance/* TODO: make_sock is just begging and screaming for APR abstraction */
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mancestatic ap_status_t make_sock(ap_context_t *p, ap_listen_rec *server)
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance{
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_socket_t *s = server->sd;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance int one = 1;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance char addr[512];
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_status_t stat;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance stat = ap_setsocketopt(s, APR_SO_REUSEADDR, one);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_log_error(APLOG_MARK, APLOG_CRIT, NULL,
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance "make_sock: for %s, setsockopt: (SO_REUSEADDR)", addr);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_close_socket(s);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance return stat;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance }
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance stat = ap_setsocketopt(s, APR_SO_KEEPALIVE, one);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_log_error(APLOG_MARK, APLOG_CRIT, NULL,
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance "make_sock: for %s, setsockopt: (SO_KEEPALIVE)", addr);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_close_socket(s);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance return stat;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance }
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance /*
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * To send data over high bandwidth-delay connections at full
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * speed we must force the TCP window to open wide enough to keep the
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * pipe full. The default window size on many systems
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * is only 4kB. Cross-country WAN connections of 100ms
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * at 1Mb/s are not impossible for well connected sites.
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * If we assume 100ms cross-country latency,
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * a 4kB buffer limits throughput to 40kB/s.
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * To avoid this problem I've added the SendBufferSize directive
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * to allow the web master to configure send buffer size.
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * The trade-off of larger buffers is that more kernel memory
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * is consumed. YMMV, know your customers and your network!
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *
a6526952d69bccd048c954eb920493a6a83e78faFelix Gabriel Mance * -John Heidemann <johnh@isi.edu> 25-Oct-96
a6526952d69bccd048c954eb920493a6a83e78faFelix Gabriel Mance *
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance * If no size is specified, use the kernel default.
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance */
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance if (send_buffer_size) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance stat = ap_setsocketopt(s, SO_SNDBUF, send_buffer_size);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_log_error(APLOG_MARK, APLOG_WARNING, NULL,
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance "make_sock: failed to set SendBufferSize for %s, "
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance "using default", addr);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance /* not a fatal error */
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance }
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance }
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance if ((stat = ap_bind(s)) != APR_SUCCESS) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_log_error(APLOG_MARK, APLOG_CRIT, NULL,
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance "make_sock: could not bind to %s", addr);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_close_socket(s);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance return stat;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance }
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance if ((stat = ap_listen(s, ap_listenbacklog)) != APR_SUCCESS) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_log_error(APLOG_MARK, APLOG_ERR, NULL,
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance "make_sock: unable to listen for connections on %s", addr);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_close_socket(s);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance return stat;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance }
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance server->sd = s;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance return APR_SUCCESS;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance}
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mancestatic ap_status_t close_listeners_on_exec(void *v)
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance{
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_listen_rec *lr;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance for (lr = ap_listeners; lr; lr = lr->next) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_close_socket(lr->sd);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance }
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance return APR_SUCCESS;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance}
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mancestatic void alloc_listener(char *addr, unsigned int port)
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance{
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_listen_rec **walk;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_listen_rec *new;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance char *oldaddr;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance unsigned int oldport;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance /* see if we've got an old listener for this address:port */
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance for (walk = &old_listeners; *walk; walk = &(*walk)->next) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_getport((*walk)->sd, &oldport);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_getipaddr((*walk)->sd, &oldaddr);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance if (!strcmp(oldaddr, addr) && port == oldport) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance /* re-use existing record */
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance new = *walk;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance *walk = new->next;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance new->next = ap_listeners;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_listeners = new;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance return;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance }
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance }
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance /* this has to survive restarts */
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance new = malloc(sizeof(ap_listen_rec));
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance if (ap_create_tcp_socket(NULL, &new->sd) != APR_SUCCESS) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_log_error(APLOG_MARK, APLOG_CRIT, NULL,
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance "make_sock: failed to get a socket for %s", addr);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance return;
c41f2d65ecbf5ad9d3233a21f406a7698338a04bFelix Gabriel Mance }
c41f2d65ecbf5ad9d3233a21f406a7698338a04bFelix Gabriel Mance ap_setport(new->sd, port);
c41f2d65ecbf5ad9d3233a21f406a7698338a04bFelix Gabriel Mance ap_setipaddr(new->sd, addr);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance new->next = ap_listeners;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_listeners = new;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance}
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Manceint ap_listen_open(ap_context_t *pconf, unsigned port)
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance{
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_listen_rec *lr;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_listen_rec *next;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance int num_open;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_status_t stat;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance /* allocate a default listener if necessary */
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance if (ap_listeners == NULL) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance alloc_listener(APR_ANYADDR, port ? port : DEFAULT_HTTP_PORT);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance }
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance num_open = 0;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance for (lr = ap_listeners; lr; lr = lr->next) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance stat = make_sock(pconf, lr);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance if (stat == APR_SUCCESS) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ++num_open;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance }
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance }
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance /* close the old listeners */
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance for (lr = old_listeners; lr; lr = next) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_close_socket(lr->sd);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance next = lr->next;
1341e758a8a0785dd7063b93aed3989f13b36f2aFelix Gabriel Mance/* free(lr);*/
1341e758a8a0785dd7063b93aed3989f13b36f2aFelix Gabriel Mance }
1341e758a8a0785dd7063b93aed3989f13b36f2aFelix Gabriel Mance old_listeners = NULL;
1341e758a8a0785dd7063b93aed3989f13b36f2aFelix Gabriel Mance
1341e758a8a0785dd7063b93aed3989f13b36f2aFelix Gabriel Mance ap_register_cleanup(pconf, NULL, ap_null_cleanup, close_listeners_on_exec);
1341e758a8a0785dd7063b93aed3989f13b36f2aFelix Gabriel Mance
1341e758a8a0785dd7063b93aed3989f13b36f2aFelix Gabriel Mance return num_open ? 0 : -1;
1341e758a8a0785dd7063b93aed3989f13b36f2aFelix Gabriel Mance}
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mancevoid ap_listen_pre_config(void)
c41f2d65ecbf5ad9d3233a21f406a7698338a04bFelix Gabriel Mance{
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance old_listeners = ap_listeners;
c41f2d65ecbf5ad9d3233a21f406a7698338a04bFelix Gabriel Mance ap_listeners = NULL;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ap_listenbacklog = DEFAULT_LISTENBACKLOG;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance}
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
1341e758a8a0785dd7063b93aed3989f13b36f2aFelix Gabriel Manceconst char *ap_set_listener(cmd_parms *cmd, void *dummy, char *ips)
1341e758a8a0785dd7063b93aed3989f13b36f2aFelix Gabriel Mance{
1341e758a8a0785dd7063b93aed3989f13b36f2aFelix Gabriel Mance char *ports;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance unsigned short port;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance if (err != NULL) {
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance return err;
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance }
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance ports = strchr(ips, ':');
137edd3944aacd150d60af8977de962113ead859Felix Gabriel Mance if (ports != NULL) {
if (ports == ips) {
return "Missing IP address";
}
else if (ports[1] == '\0') {
return "Address must end in :<port-number>";
}
*(ports++) = '\0';
}
else {
ports = ips;
}
port = atoi(ports);
if (!port) {
return "Port must be numeric";
}
if (ports == ips) { /* no address */
alloc_listener(APR_ANYADDR, port);
}
else {
ips[(ports - ips) - 1] = '\0';
alloc_listener(ips, port);
}
return NULL;
}
const char *ap_set_listenbacklog(cmd_parms *cmd, void *dummy, char *arg)
{
int b;
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
if (err != NULL) {
return err;
}
b = atoi(arg);
if (b < 1) {
return "ListenBacklog must be > 0";
}
ap_listenbacklog = b;
return NULL;
}
const char *ap_set_send_buffer_size(cmd_parms *cmd, void *dummy, char *arg)
{
int s = atoi(arg);
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
if (err != NULL) {
return err;
}
if (s < 512 && s != 0) {
return "SendBufferSize must be >= 512 bytes, or 0 for system default.";
}
send_buffer_size = s;
return NULL;
}