ab.c revision 23b4e2f556ce39696c4e31c6e72893f7489ff8d9
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* ====================================================================
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * The Apache Software License, Version 1.1
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding *
bc8fd1b0b1afdf89b8d28eefa8cd74e26ba97986fielding * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * reserved.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Redistribution and use in source and binary forms, with or without
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * modification, are permitted provided that the following conditions
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * are met:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 1. Redistributions of source code must retain the above copyright
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * notice, this list of conditions and the following disclaimer.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 2. Redistributions in binary form must reproduce the above copyright
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * notice, this list of conditions and the following disclaimer in
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the documentation and/or other materials provided with the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * distribution.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * 3. The end-user documentation included with the redistribution,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * if any, must include the following acknowledgment:
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * "This product includes software developed by the
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * Apache Software Foundation (http://www.apache.org/)."
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * Alternately, this acknowledgment may appear in the software itself,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * if and wherever such third-party acknowledgments normally appear.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * 4. The names "Apache" and "Apache Software Foundation" must
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * not be used to endorse or promote products derived from this
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * software without prior written permission. For written
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * permission, please contact apache@apache.org.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * 5. Products derived from this software may not be called "Apache",
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * nor may "Apache" appear in their name, without prior written
64185f9824e42f21ca7b9ae6c004484215c031a7rbb * permission of the Apache Software Foundation.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * SUCH DAMAGE.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ====================================================================
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * This software consists of voluntary contributions made by many
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * individuals on behalf of the Apache Software Foundation. For more
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * information on the Apache Software Foundation, please see
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * <http://www.apache.org/>.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * Portions of this software are based upon public domain software
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * originally written at the National Center for Supercomputing Applications,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * University of Illinois, Urbana-Champaign.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
3568de757bac0b47256647504c186d17ca272f85rbb/*
3568de757bac0b47256647504c186d17ca272f85rbb ** This program is based on ZeusBench V1.0 written by Adam Twiss
3568de757bac0b47256647504c186d17ca272f85rbb ** which is Copyright (c) 1996 by Zeus Technology Ltd. http://www.zeustech.net/
3568de757bac0b47256647504c186d17ca272f85rbb **
3568de757bac0b47256647504c186d17ca272f85rbb ** This software is provided "as is" and any express or implied waranties,
3568de757bac0b47256647504c186d17ca272f85rbb ** including but not limited to, the implied warranties of merchantability and
3568de757bac0b47256647504c186d17ca272f85rbb ** fitness for a particular purpose are disclaimed. In no event shall
3568de757bac0b47256647504c186d17ca272f85rbb ** Zeus Technology Ltd. be liable for any direct, indirect, incidental, special,
3568de757bac0b47256647504c186d17ca272f85rbb ** exemplary, or consequential damaged (including, but not limited to,
3568de757bac0b47256647504c186d17ca272f85rbb ** procurement of substitute good or services; loss of use, data, or profits;
3568de757bac0b47256647504c186d17ca272f85rbb ** or business interruption) however caused and on theory of liability. Whether
3568de757bac0b47256647504c186d17ca272f85rbb ** in contract, strict liability or tort (including negligence or otherwise)
3568de757bac0b47256647504c186d17ca272f85rbb ** arising in any way out of the use of this software, even if advised of the
3568de757bac0b47256647504c186d17ca272f85rbb ** possibility of such damage.
3568de757bac0b47256647504c186d17ca272f85rbb **
3568de757bac0b47256647504c186d17ca272f85rbb */
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/*
3568de757bac0b47256647504c186d17ca272f85rbb ** HISTORY:
3568de757bac0b47256647504c186d17ca272f85rbb ** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996
3568de757bac0b47256647504c186d17ca272f85rbb ** with input from Mike Belshe <mbelshe@netscape.com> and
3568de757bac0b47256647504c186d17ca272f85rbb ** Michael Campanella <campanella@stevms.enet.dec.com>
3568de757bac0b47256647504c186d17ca272f85rbb ** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997
3568de757bac0b47256647504c186d17ca272f85rbb ** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998
3568de757bac0b47256647504c186d17ca272f85rbb ** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998
3568de757bac0b47256647504c186d17ca272f85rbb ** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999
3568de757bac0b47256647504c186d17ca272f85rbb ** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 1999
3568de757bac0b47256647504c186d17ca272f85rbb **
3568de757bac0b47256647504c186d17ca272f85rbb */
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/*
3568de757bac0b47256647504c186d17ca272f85rbb * BUGS:
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * - uses strcpy/etc.
3568de757bac0b47256647504c186d17ca272f85rbb * - has various other poor buffer attacks related to the lazy parsing of
3568de757bac0b47256647504c186d17ca272f85rbb * response headers from the server
3568de757bac0b47256647504c186d17ca272f85rbb * - doesn't implement much of HTTP/1.x, only accepts certain forms of
3568de757bac0b47256647504c186d17ca272f85rbb * responses
3568de757bac0b47256647504c186d17ca272f85rbb * - (performance problem) heavy use of strstr shows up top in profile
3568de757bac0b47256647504c186d17ca272f85rbb * only an issue for loopback usage
3568de757bac0b47256647504c186d17ca272f85rbb */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define AB_VERSION "1.3c"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* -------------------------------------------------------------------- */
3568de757bac0b47256647504c186d17ca272f85rbb
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick#if 'A' != 0x41
3568de757bac0b47256647504c186d17ca272f85rbb/* Hmmm... This source code isn't being compiled in ASCII.
3568de757bac0b47256647504c186d17ca272f85rbb * In order for data that flows over the network to make
3568de757bac0b47256647504c186d17ca272f85rbb * sense, we need to translate to/from ASCII.
3568de757bac0b47256647504c186d17ca272f85rbb */
db12cd62083041bf90945eeb90cc40fbd2340797trawick#define NOT_ASCII
db12cd62083041bf90945eeb90cc40fbd2340797trawick#endif
db12cd62083041bf90945eeb90cc40fbd2340797trawick
333eac96e4fb7d6901cb75e6ca7bb22b2ccb84cetrawick/* affects include files on Solaris */
333eac96e4fb7d6901cb75e6ca7bb22b2ccb84cetrawick#define BSD_COMP
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb#include "apr.h"
3568de757bac0b47256647504c186d17ca272f85rbb#include "apr_strings.h"
3568de757bac0b47256647504c186d17ca272f85rbb#include "apr_network_io.h"
3568de757bac0b47256647504c186d17ca272f85rbb#include "apr_file_io.h"
3568de757bac0b47256647504c186d17ca272f85rbb#include "apr_time.h"
3568de757bac0b47256647504c186d17ca272f85rbb#include "apr_getopt.h"
3568de757bac0b47256647504c186d17ca272f85rbb#include "apr_general.h"
3568de757bac0b47256647504c186d17ca272f85rbb#include "apr_lib.h"
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb#if APR_HAVE_STDIO_H
3568de757bac0b47256647504c186d17ca272f85rbb#include <stdio.h> /* for EOF */
3568de757bac0b47256647504c186d17ca272f85rbb#endif
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#if APR_HAVE_STDLIB_H
3568de757bac0b47256647504c186d17ca272f85rbb#include <stdlib.h>
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#endif
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#include "apr_base64.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef NOT_ASCII
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#include "apr_xlate.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#if APR_HAVE_STRING_H
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include <string.h>
8f3ec4772d2aeb347cf40e87c77627bb784dd018rbb#endif
8f3ec4772d2aeb347cf40e87c77627bb784dd018rbb#if APR_HAVE_STDIO_H
3d96ee83babeec32482c9082c9426340cee8c44dwrowe#include <stdio.h>
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick#if APR_HAVE_STDLIB_H
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick#include <stdlib.h>
3568de757bac0b47256647504c186d17ca272f85rbb#endif
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#if APR_HAVE_CTYPE_H
3568de757bac0b47256647504c186d17ca272f85rbb#include <ctype.h>
3568de757bac0b47256647504c186d17ca272f85rbb#endif
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
3568de757bac0b47256647504c186d17ca272f85rbb/* ------------------- DEFINITIONS -------------------------- */
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/* maximum number of requests on a time limited test */
3568de757bac0b47256647504c186d17ca272f85rbb#define MAX_REQUESTS 50000
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/* good old state hostname */
3568de757bac0b47256647504c186d17ca272f85rbb#define STATE_UNCONNECTED 0
3568de757bac0b47256647504c186d17ca272f85rbb#define STATE_CONNECTING 1
3568de757bac0b47256647504c186d17ca272f85rbb#define STATE_READ 2
3568de757bac0b47256647504c186d17ca272f85rbb
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define CBUFFSIZE 2048
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbbstruct connection {
3568de757bac0b47256647504c186d17ca272f85rbb apr_socket_t *aprsock;
3568de757bac0b47256647504c186d17ca272f85rbb int state;
3568de757bac0b47256647504c186d17ca272f85rbb int read; /* amount of bytes read */
3568de757bac0b47256647504c186d17ca272f85rbb int bread; /* amount of body read */
41634f717c623556a16b27b25d7d909a66fe20f8wrowe int length; /* Content-Length value used for keep-alive */
3568de757bac0b47256647504c186d17ca272f85rbb char cbuff[CBUFFSIZE]; /* a buffer to store server response header */
3568de757bac0b47256647504c186d17ca272f85rbb int cbx; /* offset in cbuffer */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz int keepalive; /* non-zero if a keep-alive request */
3568de757bac0b47256647504c186d17ca272f85rbb int gotheader; /* non-zero if we have the entire header in
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * cbuff */
3568de757bac0b47256647504c186d17ca272f85rbb apr_time_t start, connect, done;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz int socknum;
3568de757bac0b47256647504c186d17ca272f85rbb};
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
3568de757bac0b47256647504c186d17ca272f85rbbstruct data {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int read; /* number of bytes read */
41634f717c623556a16b27b25d7d909a66fe20f8wrowe int ctime; /* time in ms to connect */
3568de757bac0b47256647504c186d17ca272f85rbb int time; /* time in ms for connection */
3568de757bac0b47256647504c186d17ca272f85rbb};
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
3568de757bac0b47256647504c186d17ca272f85rbb#define ap_min(a,b) ((a)<(b))?(a):(b)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#define ap_max(a,b) ((a)>(b))?(a):(b)
3568de757bac0b47256647504c186d17ca272f85rbb
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* --------------------- GLOBALS ---------------------------- */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingint verbosity = 0; /* no verbosity by default */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzint posting = 0; /* GET by default */
3568de757bac0b47256647504c186d17ca272f85rbbint requests = 1; /* Number of requests to make */
fc1efab92032301e317f07e1b3a00082d9d71f3frbbint concurrency = 1; /* Number of multiple requests to make */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzint tlimit = 0; /* time limit in cs */
24b534291150023e6b68eca89ddd33e475ccddc0wroweint keepalive = 0; /* try and do keepalive connections */
3568de757bac0b47256647504c186d17ca272f85rbbchar servername[1024]; /* name that server reports */
24b534291150023e6b68eca89ddd33e475ccddc0wrowechar *hostname; /* host name from URL */
3568de757bac0b47256647504c186d17ca272f85rbbchar *host_field; /* value of "Host:" header field */
24b534291150023e6b68eca89ddd33e475ccddc0wrowechar path[1024]; /* path name */
24b534291150023e6b68eca89ddd33e475ccddc0wrowechar postfile[1024]; /* name of file containing post data */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzchar *postdata; /* *buffer containing data from postfile */
3568de757bac0b47256647504c186d17ca272f85rbbapr_size_t postlen = 0; /* length of data to be POSTed */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzchar content_type[1024]; /* content type to put in POST header */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzchar cookie[1024], /* optional cookie line */
3568de757bac0b47256647504c186d17ca272f85rbb auth[1024], /* optional (basic/uuencoded)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * authentification */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz hdrs[4096]; /* optional arbitrary headers */
3568de757bac0b47256647504c186d17ca272f85rbbapr_port_t port; /* port number */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzapr_time_t aprtimeout = 30 * APR_USEC_PER_SEC; /* timeout value */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
3568de757bac0b47256647504c186d17ca272f85rbbint use_html = 0; /* use html in the report */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzconst char *tablestring;
3568de757bac0b47256647504c186d17ca272f85rbbconst char *trstring;
3568de757bac0b47256647504c186d17ca272f85rbbconst char *tdstring;
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbbint doclen = 0; /* the length the document should be */
3568de757bac0b47256647504c186d17ca272f85rbbint totalread = 0; /* total number of bytes read */
3568de757bac0b47256647504c186d17ca272f85rbbint totalbread = 0; /* totoal amount of entity body read */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzint totalposted = 0; /* total number of bytes posted, inc. headers */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzint done = 0; /* number of requests we have done */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzint doneka = 0; /* number of keep alive connections done */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzint started = 0; /* number of requests started, so no excess */
3568de757bac0b47256647504c186d17ca272f85rbbint good = 0, bad = 0; /* number of good and bad requests */
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/* store error cases */
3568de757bac0b47256647504c186d17ca272f85rbbint err_length = 0, err_conn = 0, err_except = 0;
3568de757bac0b47256647504c186d17ca272f85rbbint err_response = 0;
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbbapr_time_t start, endtime;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
3568de757bac0b47256647504c186d17ca272f85rbb/* global request (and its length) */
3568de757bac0b47256647504c186d17ca272f85rbbchar request[512];
3568de757bac0b47256647504c186d17ca272f85rbbapr_size_t reqlen;
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/* one global throw-away buffer to read stuff into */
3568de757bac0b47256647504c186d17ca272f85rbbchar buffer[8192];
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbbstruct connection *con; /* connection array */
3568de757bac0b47256647504c186d17ca272f85rbbstruct data *stats; /* date for each request */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingapr_pool_t *cntxt;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
3568de757bac0b47256647504c186d17ca272f85rbbapr_pollfd_t *readbits;
239f998fbee5ac5b114b965bb76e217cce0003edstoddard
78ae889ffe0fdfab72f56c6993b0f302cb48da55rbb#ifdef NOT_ASCII
3568de757bac0b47256647504c186d17ca272f85rbbapr_xlate_t *from_ascii, *to_ascii;
3568de757bac0b47256647504c186d17ca272f85rbb#endif
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/* --------------------------------------------------------- */
41634f717c623556a16b27b25d7d909a66fe20f8wrowe
41634f717c623556a16b27b25d7d909a66fe20f8wrowe/* simple little function to write an error string and exit */
41634f717c623556a16b27b25d7d909a66fe20f8wrowe
3568de757bac0b47256647504c186d17ca272f85rbbstatic void err(char *s)
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard{
3568de757bac0b47256647504c186d17ca272f85rbb fprintf(stderr, "%s", s);
3568de757bac0b47256647504c186d17ca272f85rbb exit(1);
3568de757bac0b47256647504c186d17ca272f85rbb}
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/* simple little function to write an APR error string and exit */
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbbstatic void apr_err(char *s, apr_status_t rv)
3568de757bac0b47256647504c186d17ca272f85rbb{
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm char buf[120];
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick fprintf(stderr,
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick "%s: %s (%d)\n",
3568de757bac0b47256647504c186d17ca272f85rbb s, apr_strerror(rv, buf, sizeof buf), rv);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding exit(rv);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz}
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
ca53a74f4012a45cbad48e940eddf27d866981f9dougm/* --------------------------------------------------------- */
ca53a74f4012a45cbad48e940eddf27d866981f9dougm
ca53a74f4012a45cbad48e940eddf27d866981f9dougm/* write out request to a connection - assumes we can write
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick (small) request out in one go into our new socket buffer */
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawickstatic void write_request(struct connection * c)
239f998fbee5ac5b114b965bb76e217cce0003edstoddard{
3568de757bac0b47256647504c186d17ca272f85rbb apr_size_t len = reqlen;
3568de757bac0b47256647504c186d17ca272f85rbb c->connect = apr_time_now();
3568de757bac0b47256647504c186d17ca272f85rbb apr_setsocketopt(c->aprsock, APR_SO_TIMEOUT, aprtimeout);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (apr_send(c->aprsock, request, &len) != APR_SUCCESS ||
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard reqlen != len) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Send request failed!\n");
3568de757bac0b47256647504c186d17ca272f85rbb close_connection(c);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz return;
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (posting) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard len = postlen;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (apr_send(c->aprsock, postdata, &len) != APR_SUCCESS ||
e0d102c882a7ed34d3eec24b36da49f097066a36stoddard reqlen != len) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding printf("Send post request failed!\n");
3568de757bac0b47256647504c186d17ca272f85rbb close_connection(c);
3568de757bac0b47256647504c186d17ca272f85rbb return;
3568de757bac0b47256647504c186d17ca272f85rbb }
3568de757bac0b47256647504c186d17ca272f85rbb totalposted += postlen + reqlen;
3568de757bac0b47256647504c186d17ca272f85rbb }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard c->state = STATE_READ;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard apr_poll_socket_add(readbits, c->aprsock, APR_POLLIN);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz}
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/* --------------------------------------------------------- */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/* calculate and output results */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddardstatic void output_results(void)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard{
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard int timetaken;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz endtime = apr_time_now();
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz timetaken = (endtime - start) / 1000;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("\r \r");
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Server Software: %s\n", servername);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Server Hostname: %s\n", hostname);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Server Port: %hd\n", port);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("\n");
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Document Path: %s\n", path);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Document Length: %d bytes\n", doclen);
e0d102c882a7ed34d3eec24b36da49f097066a36stoddard printf("\n");
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Concurrency Level: %d\n", concurrency);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Time taken for tests: %d.%03d seconds\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard timetaken / 1000, timetaken % 1000);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Complete requests: %d\n", done);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("Failed requests: %d\n", bad);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (bad)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf(" (Connect: %d, Length: %d, Exceptions: %d)\n",
3568de757bac0b47256647504c186d17ca272f85rbb err_conn, err_length, err_except);
3568de757bac0b47256647504c186d17ca272f85rbb if (err_response)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding printf("Non-2xx responses: %d\n", err_response);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (keepalive)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding printf("Keep-Alive requests: %d\n", doneka);
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick printf("Total transferred: %d bytes\n", totalread);
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick if (posting)
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick printf("Total POSTed: %d\n", totalposted);
3568de757bac0b47256647504c186d17ca272f85rbb printf("HTML transferred: %d bytes\n", totalbread);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /* avoid divide by zero */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm if (timetaken) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Requests per second: %.2f\n", 1000 * (float) (done) / timetaken);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("Transfer rate: %.2f kb/s received\n",
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm (float) (totalread) / timetaken);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm if (posting > 0) {
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm printf(" %.2f kb/s sent\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard (float) (totalposted) / timetaken);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf(" %.2f kb/s total\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard (float) (totalread + totalposted) / timetaken);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames }
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames {
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames /* work out connection times */
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames int i;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard int totalcon = 0, total = 0;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm int mincon = 9999999, mintot = 999999;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm int maxcon = 0, maxtot = 0;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard for (i = 0; i < requests; i++) {
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard struct data s = stats[i];
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm mincon = ap_min(mincon, s.ctime);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm mintot = ap_min(mintot, s.time);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm maxcon = ap_max(maxcon, s.ctime);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm maxtot = ap_max(maxtot, s.time);
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard totalcon += s.ctime;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz total += s.time;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (requests > 0) { /* avoid division by zero (if 0 requests) */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("\nConnnection Times (ms)\n");
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf(" min avg max\n");
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Connect: %5d %5d %5d\n", mincon, totalcon / requests, maxcon);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Processing: %5d %5d %5d\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard mintot - mincon, (total / requests) - (totalcon / requests),
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard maxtot - maxcon);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Total: %5d %5d %5d\n", mintot, total / requests, maxtot);
3568de757bac0b47256647504c186d17ca272f85rbb }
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz }
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm}
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/* --------------------------------------------------------- */
74fd6d9aeadb9022086259c5c1ae00bc0dda9c9astoddard
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* calculate and output results in HTML */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzstatic void output_html_results(void)
3568de757bac0b47256647504c186d17ca272f85rbb{
3568de757bac0b47256647504c186d17ca272f85rbb int timetaken;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard endtime = apr_time_now();
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard timetaken = (endtime - start) / 1000;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("\n\n<table %s>\n", tablestring);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Server Software:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%s</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, servername);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Server Hostname:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%s</td></tr>\n",
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz trstring, tdstring, tdstring, hostname);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("<tr %s><th colspan=2 %s>Server Port:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%hd</td></tr>\n",
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz trstring, tdstring, tdstring, port);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("<tr %s><th colspan=2 %s>Document Path:</th>"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz "<td colspan=2 %s>%s</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, path);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("<tr %s><th colspan=2 %s>Document Length:</th>"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz "<td colspan=2 %s>%d bytes</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, doclen);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Concurrency Level:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%d</td></tr>\n",
3568de757bac0b47256647504c186d17ca272f85rbb trstring, tdstring, tdstring, concurrency);
3568de757bac0b47256647504c186d17ca272f85rbb printf("<tr %s><th colspan=2 %s>Time taken for tests:</th>"
3568de757bac0b47256647504c186d17ca272f85rbb "<td colspan=2 %s>%d.%03d seconds</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, timetaken / 1000, timetaken % 1000);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("<tr %s><th colspan=2 %s>Complete requests:</th>"
f714f1a7002928d785e53e70349700a7f595fee3trawick "<td colspan=2 %s>%d</td></tr>\n",
f714f1a7002928d785e53e70349700a7f595fee3trawick trstring, tdstring, tdstring, done);
3568de757bac0b47256647504c186d17ca272f85rbb printf("<tr %s><th colspan=2 %s>Failed requests:</th>"
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard "<td colspan=2 %s>%d</td></tr>\n",
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz trstring, tdstring, tdstring, bad);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (bad)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("<tr %s><td colspan=4 %s > (Connect: %d, Length: %d, Exceptions: %d)</td></tr>\n",
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz trstring, tdstring, err_conn, err_length, err_except);
3568de757bac0b47256647504c186d17ca272f85rbb if (err_response)
3568de757bac0b47256647504c186d17ca272f85rbb printf("<tr %s><th colspan=2 %s>Non-2xx responses:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%d</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, err_response);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (keepalive)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Keep-Alive requests:</th>"
3568de757bac0b47256647504c186d17ca272f85rbb "<td colspan=2 %s>%d</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, doneka);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Total transferred:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%d bytes</td></tr>\n",
3568de757bac0b47256647504c186d17ca272f85rbb trstring, tdstring, tdstring, totalread);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (posting > 0)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Total POSTed:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%d</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, totalposted);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("<tr %s><th colspan=2 %s>HTML transferred:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%d bytes</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, totalbread);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
3568de757bac0b47256647504c186d17ca272f85rbb /* avoid divide by zero */
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard if (timetaken) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Requests per second:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%.2f</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, 1000 * (float) (done) / timetaken);
3568de757bac0b47256647504c186d17ca272f85rbb printf("<tr %s><th colspan=2 %s>Transfer rate:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%.2f kb/s received</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, (float) (totalread) / timetaken);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (posting > 0) {
3568de757bac0b47256647504c186d17ca272f85rbb printf("<tr %s><td colspan=2 %s>&nbsp;</td>"
3568de757bac0b47256647504c186d17ca272f85rbb "<td colspan=2 %s>%.2f kb/s sent</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring,
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard (float) (totalposted) / timetaken);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><td colspan=2 %s>&nbsp;</td>"
3568de757bac0b47256647504c186d17ca272f85rbb "<td colspan=2 %s>%.2f kb/s total</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring,
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz (float) (totalread + totalposted) / timetaken);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
3568de757bac0b47256647504c186d17ca272f85rbb {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /* work out connection times */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz int i;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard int totalcon = 0, total = 0;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard int mincon = 9999999, mintot = 999999;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard int maxcon = 0, maxtot = 0;
3568de757bac0b47256647504c186d17ca272f85rbb
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard for (i = 0; i < requests; i++) {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz struct data s = stats[i];
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz mincon = ap_min(mincon, s.ctime);
3568de757bac0b47256647504c186d17ca272f85rbb mintot = ap_min(mintot, s.time);
3568de757bac0b47256647504c186d17ca272f85rbb maxcon = ap_max(maxcon, s.ctime);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz maxtot = ap_max(maxtot, s.time);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz totalcon += s.ctime;
3568de757bac0b47256647504c186d17ca272f85rbb total += s.time;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb if (requests > 0) { /* avoid division by zero (if 0 requests) */
3568de757bac0b47256647504c186d17ca272f85rbb printf("<tr %s><th %s colspan=4>Connnection Times (ms)</th></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring);
3568de757bac0b47256647504c186d17ca272f85rbb printf("<tr %s><th %s>&nbsp;</th> <th %s>min</th> <th %s>avg</th> <th %s>max</th></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, tdstring, tdstring);
3568de757bac0b47256647504c186d17ca272f85rbb printf("<tr %s><th %s>Connect:</th>"
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick "<td %s>%5d</td>"
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick "<td %s>%5d</td>"
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick "<td %s>%5d</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, mincon, tdstring, totalcon / requests, tdstring, maxcon);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("<tr %s><th %s>Processing:</th>"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz "<td %s>%5d</td>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td %s>%5d</td>"
beb70d51e435dc36c56a72b6cd83556c04db9283wrowe "<td %s>%5d</td></tr>\n",
fe6baec9bbcd36f932b71a355120cd7b5a685d6cfielding trstring, tdstring, tdstring, mintot - mincon, tdstring,
3568de757bac0b47256647504c186d17ca272f85rbb (total / requests) - (totalcon / requests), tdstring, maxtot - maxcon);
3568de757bac0b47256647504c186d17ca272f85rbb printf("<tr %s><th %s>Total:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td %s>%5d</td>"
3568de757bac0b47256647504c186d17ca272f85rbb "<td %s>%5d</td>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td %s>%5d</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, mintot, tdstring, total / requests, tdstring, maxtot);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("</table>\n");
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard}
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/* --------------------------------------------------------- */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/* start asnchronous non-blocking connection */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowestatic void start_connect(struct connection * c)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard{
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard apr_status_t rv;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard apr_sockaddr_t *destsa;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
8e9734d1a4af74c141e2a0f880bb51bb061fa03atrawick if (!(started < requests))
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard return;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard c->read = 0;
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick c->bread = 0;
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick c->keepalive = 0;
3568de757bac0b47256647504c186d17ca272f85rbb c->cbx = 0;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard c->gotheader = 0;
cb97ae2ff6969c2789b8e03f1bc4187fa73b6bafwrowe
0f113d7123e8bd3e3e2e9b6373461a1a773bfccatrawick if ((rv = apr_sockaddr_info_get(&destsa, hostname, APR_UNSPEC, port, 0, cntxt))
0f113d7123e8bd3e3e2e9b6373461a1a773bfccatrawick != APR_SUCCESS) {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz char buf[120];
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard apr_snprintf(buf, sizeof(buf),
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "apr_sockaddr_info_get() for %s", hostname);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard apr_err(buf, rv);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if ((rv = apr_socket_create(&c->aprsock, destsa->sa.sin.sin_family,
3568de757bac0b47256647504c186d17ca272f85rbb SOCK_STREAM, cntxt)) != APR_SUCCESS) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard apr_err("socket", rv);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard c->start = apr_time_now();
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if ((rv = apr_connect(c->aprsock, destsa)) != APR_SUCCESS) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (APR_STATUS_IS_EINPROGRESS(rv)) {
3568de757bac0b47256647504c186d17ca272f85rbb c->state = STATE_CONNECTING;
3568de757bac0b47256647504c186d17ca272f85rbb apr_poll_socket_add(readbits, c->aprsock, APR_POLLOUT);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick else {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_poll_socket_remove(readbits, c->aprsock);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_socket_close(c->aprsock);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick err_conn++;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (bad++ > 10) {
f886987cd0bd4220c14043c4d9be77ec22902e73trawick fprintf(stderr,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick "\nTest aborted after 10 failures\n\n");
f886987cd0bd4220c14043c4d9be77ec22902e73trawick apr_err("apr_connect()", rv);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick c->state = STATE_UNCONNECTED;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick start_connect(c);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz }
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz }
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /* connected first time */
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick started++;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm write_request(c);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm}
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick/* --------------------------------------------------------- */
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick/* close down connection and save stats */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
3568de757bac0b47256647504c186d17ca272f85rbbstatic void close_connection(struct connection * c)
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm{
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (c->read == 0 && c->keepalive) {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz /* server has legitimately shut down an idle keep alive request */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (good)
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm good--; /* connection never happened */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm }
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz else {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (good == 1) {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz /* first time here */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm doclen = c->bread;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm }
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm else if (c->bread != doclen) {
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm bad++;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm err_length++;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm }
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz /* save out time */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (done < requests) {
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm struct data s;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick c->done = apr_time_now();
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick s.read = c->read;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm s.ctime = (c->connect - c->start) / 1000;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick s.time = (c->done - c->start) / 1000;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick stats[done++] = s;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
cb97ae2ff6969c2789b8e03f1bc4187fa73b6bafwrowe
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm apr_poll_socket_remove(readbits, c->aprsock);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm apr_socket_close(c->aprsock);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick c->state = STATE_UNCONNECTED;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /* connect again */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick start_connect(c);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick}
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/* --------------------------------------------------------- */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/* read data from connection */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickstatic void read_connection(struct connection * c)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick{
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_size_t r;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_status_t status;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick char *part;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick char respcode[4]; /* 3 digits and null */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick r = sizeof(buffer);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_setsocketopt(c->aprsock, APR_SO_TIMEOUT, aprtimeout);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick status = apr_recv(c->aprsock, buffer, &r);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (r == 0 || (status != APR_SUCCESS && !APR_STATUS_IS_EAGAIN(status))) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick good++;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick close_connection(c);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (APR_STATUS_IS_EAGAIN(status))
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick c->read += r;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick totalread += r;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (!c->gotheader) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick char *s;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick int l = 4;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick int space = CBUFFSIZE - c->cbx - 1; /* -1 to allow for 0
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * terminator */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick int tocopy = (space < r) ? space : r;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick#ifdef NOT_ASCII
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_size_t inbytes_left = space, outbytes_left = space;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
f886987cd0bd4220c14043c4d9be77ec22902e73trawick status = apr_xlate_conv_buffer(from_ascii, buffer, &inbytes_left,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick c->cbuff + c->cbx, &outbytes_left);
f886987cd0bd4220c14043c4d9be77ec22902e73trawick if (status || inbytes_left || outbytes_left) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick fprintf(stderr, "only simple translation is supported (%d/%u/%u)\n",
f886987cd0bd4220c14043c4d9be77ec22902e73trawick status, inbytes_left, outbytes_left);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm exit(1);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm }
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm#else
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm memcpy(c->cbuff + c->cbx, buffer, space);
3568de757bac0b47256647504c186d17ca272f85rbb#endif /* NOT_ASCII */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm c->cbx += tocopy;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick space -= tocopy;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick c->cbuff[c->cbx] = 0; /* terminate for benefit of strstr */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (verbosity >= 4) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick printf("LOG: header received:\n%s\n", c->cbuff);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick s = strstr(c->cbuff, "\r\n\r\n");
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * this next line is so that we talk to NCSA 1.5 which blatantly
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * breaks the http specifaction
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (!s) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick s = strstr(c->cbuff, "\n\n");
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm l = 2;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (!s) {
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /* read rest next time */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (space) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm }
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick else {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* header is in invalid or too big - close connection */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm apr_poll_socket_remove(readbits, c->aprsock);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_socket_close(c->aprsock);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick err_response++;
f886987cd0bd4220c14043c4d9be77ec22902e73trawick if (bad++ > 10) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick err("\nTest aborted after 10 failures\n\n");
cb97ae2ff6969c2789b8e03f1bc4187fa73b6bafwrowe }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick start_connect(c);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm }
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick else {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* have full header */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm if (!good) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* this is first time, extract some interesting info */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick char *p, *q;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick p = strstr(c->cbuff, "Server:");
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick q = servername;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (p) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick p += 8;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick while (*p > 32)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick *q++ = *p++;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick *q = 0;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * XXX: this parsing isn't even remotely HTTP compliant... but in
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * the interest of speed it doesn't totally have to be, it just
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * needs to be extended to handle whatever servers folks want to
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * test against. -djg
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* check response code */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick part = strstr(c->cbuff, "HTTP"); /* really HTTP/1.x_ */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick strncpy(respcode, (part + strlen("HTTP/1.x_")), 3);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick respcode[3] = '\0';
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (respcode[0] != '2') {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick err_response++;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (verbosity >= 2)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick printf("WARNING: Response code not 2xx (%s)\n", respcode);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick else if (verbosity >= 3) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick printf("LOG: Response code = %s\n", respcode);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick c->gotheader = 1;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick *s = 0; /* terminate at end of header */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (keepalive &&
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick (strstr(c->cbuff, "Keep-Alive")
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick || strstr(c->cbuff, "keep-alive"))) { /* for benefit of MSIIS */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick char *cl;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick cl = strstr(c->cbuff, "Content-Length:");
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* handle NCSA, which sends Content-length: */
f886987cd0bd4220c14043c4d9be77ec22902e73trawick if (!cl)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick cl = strstr(c->cbuff, "Content-length:");
f886987cd0bd4220c14043c4d9be77ec22902e73trawick if (cl) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick c->keepalive = 1;
f886987cd0bd4220c14043c4d9be77ec22902e73trawick c->length = atoi(cl + 16);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm }
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm }
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm c->bread += c->cbx - (s + l - c->cbuff) + r - tocopy;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm totalbread += c->bread;
3568de757bac0b47256647504c186d17ca272f85rbb }
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick else {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* outside header, everything we have read is entity body */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick c->bread += r;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick totalbread += r;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (c->keepalive && (c->bread >= c->length)) {
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /* finished a keep-alive connection */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick good++;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick doneka++;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* save out time */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (good == 1) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* first time here */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick doclen = c->bread;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick else if (c->bread != doclen) {
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm bad++;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick err_length++;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (done < requests) {
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick struct data s;
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick c->done = apr_time_now();
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz s.read = c->read;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick s.ctime = (c->connect - c->start) / 1000;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz s.time = (c->done - c->start) / 1000;
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe stats[done++] = s;
3568de757bac0b47256647504c186d17ca272f85rbb }
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe c->keepalive = 0;
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe c->length = 0;
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe c->gotheader = 0;
f886987cd0bd4220c14043c4d9be77ec22902e73trawick c->cbx = 0;
f886987cd0bd4220c14043c4d9be77ec22902e73trawick c->read = c->bread = 0;
f886987cd0bd4220c14043c4d9be77ec22902e73trawick write_request(c);
f886987cd0bd4220c14043c4d9be77ec22902e73trawick c->start = c->connect; /* zero connect time with keep-alive */
f886987cd0bd4220c14043c4d9be77ec22902e73trawick }
f886987cd0bd4220c14043c4d9be77ec22902e73trawick}
f886987cd0bd4220c14043c4d9be77ec22902e73trawick
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe/* --------------------------------------------------------- */
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe/* run the tests */
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe
3568de757bac0b47256647504c186d17ca272f85rbbstatic void test(void)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz{
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_time_t now;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz apr_int16_t rv;
3568de757bac0b47256647504c186d17ca272f85rbb int i;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz apr_status_t status;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#ifdef NOT_ASCII
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz apr_size_t inbytes_left, outbytes_left;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#endif
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
3568de757bac0b47256647504c186d17ca272f85rbb if (!use_html) {
3568de757bac0b47256647504c186d17ca272f85rbb printf("Benchmarking %s (be patient)...", hostname);
3568de757bac0b47256647504c186d17ca272f85rbb fflush(stdout);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz }
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
3568de757bac0b47256647504c186d17ca272f85rbb now = apr_time_now();
3568de757bac0b47256647504c186d17ca272f85rbb
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding con = malloc(concurrency * sizeof(struct connection));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memset(con, 0, concurrency * sizeof(struct connection));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
3568de757bac0b47256647504c186d17ca272f85rbb stats = malloc(requests * sizeof(struct data));
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz apr_poll_setup(&readbits, concurrency, cntxt);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
3568de757bac0b47256647504c186d17ca272f85rbb /* setup request */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (!posting) {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz sprintf(request, "%s %s HTTP/1.0\r\n"
3568de757bac0b47256647504c186d17ca272f85rbb "User-Agent: ApacheBench/%s\r\n"
3568de757bac0b47256647504c186d17ca272f85rbb "%s" "%s" "%s"
3568de757bac0b47256647504c186d17ca272f85rbb "Host: %s\r\n"
3568de757bac0b47256647504c186d17ca272f85rbb "Accept: */*\r\n"
3568de757bac0b47256647504c186d17ca272f85rbb "%s" "\r\n",
3568de757bac0b47256647504c186d17ca272f85rbb (posting == 0) ? "GET" : "HEAD",
ec020ca384efb30d501a5af796ddc3bb237d7b8fgregames path,
3568de757bac0b47256647504c186d17ca272f85rbb AB_VERSION,
ce03576b2434cec77f2921db9d5b6a0510581c23rederpj keepalive ? "Connection: Keep-Alive\r\n" : "",
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick cookie, auth, host_field, hdrs);
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick }
9d0665da83d1e22c0ea0e5f6f940f70f75bf5237ianh else {
3568de757bac0b47256647504c186d17ca272f85rbb sprintf(request, "POST %s HTTP/1.0\r\n"
3568de757bac0b47256647504c186d17ca272f85rbb "User-Agent: ApacheBench/%s\r\n"
73e8b26287de5c06fa470d36162e103dbac9c7e5wrowe "%s" "%s" "%s"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Host: %s\r\n"
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe "Accept: */*\r\n"
3568de757bac0b47256647504c186d17ca272f85rbb "Content-length: %" APR_SIZE_T_FMT "\r\n"
ca53a74f4012a45cbad48e940eddf27d866981f9dougm "Content-type: %s\r\n"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "%s"
3d96ee83babeec32482c9082c9426340cee8c44dwrowe "\r\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding path,
302dc1f7b3feee23a91ad8f3cf3cb2edd95a557bmanoj AB_VERSION,
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz keepalive ? "Connection: Keep-Alive\r\n" : "",
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz cookie, auth,
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz host_field, postlen,
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz (content_type[0]) ? content_type : "text/plain", hdrs);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz }
3568de757bac0b47256647504c186d17ca272f85rbb
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (verbosity >= 2)
3568de757bac0b47256647504c186d17ca272f85rbb printf("INFO: POST header == \n---\n%s\n---\n", request);
reqlen = strlen(request);
#ifdef NOT_ASCII
inbytes_left = outbytes_left = reqlen;
status = apr_xlate_conv_buffer(to_ascii, request, &inbytes_left,
request, &outbytes_left);
if (status || inbytes_left || outbytes_left) {
fprintf(stderr, "only simple translation is supported (%d/%u/%u)\n",
status, inbytes_left, outbytes_left);
exit(1);
}
#endif /* NOT_ASCII */
/* ok - lets start */
start = apr_time_now();
/* initialise lots of requests */
for (i = 0; i < concurrency; i++) {
con[i].socknum = i;
start_connect(&con[i]);
}
while (done < requests) {
apr_int32_t n;
apr_int32_t timed;
/* check for time limit expiry */
now = apr_time_now();
timed = (now - start) / APR_USEC_PER_SEC;
if (tlimit && timed > (tlimit * 1000)) {
requests = done; /* so stats are correct */
}
n = concurrency;
status = apr_poll(readbits, &n, aprtimeout);
if (status != APR_SUCCESS)
apr_err("apr_poll", status);
if (!n) {
err("\nServer timed out\n\n");
}
for (i = 0; i < concurrency; i++) {
/*
* If the connection isn't connected how can we check it?
*/
if (con[i].state == STATE_UNCONNECTED)
continue;
apr_poll_revents_get(&rv, con[i].aprsock, readbits);
/*
* Notes: APR_POLLHUP is set after FIN is received on some
* systems, so treat that like APR_POLLIN so that we try to read
* again.
*
* Some systems return APR_POLLERR with APR_POLLHUP. We need to
* call read_connection() for APR_POLLHUP, so check for
* APR_POLLHUP first so that a closed connection isn't treated
* like an I/O error. If it is, we never figure out that the
* connection is done and we loop here endlessly calling
* apr_poll().
*/
if ((rv & APR_POLLIN) || (rv & APR_POLLPRI) || (rv & APR_POLLHUP))
read_connection(&con[i]);
if ((rv & APR_POLLERR) || (rv & APR_POLLNVAL)) {
bad++;
err_except++;
start_connect(&con[i]);
continue;
}
if (rv & APR_POLLOUT)
write_request(&con[i]);
/*
* When using a select based poll every time we check the bits
* are reset. In 1.3's ab we copied the FD_SET's each time
* through, but here we're going to check the state and if the
* connection is in STATE_READ or STATE_CONNECTING we'll add the
* socket back in as APR_POLLIN.
*/
if (con[i].state == STATE_READ || con[i].state == STATE_CONNECTING)
apr_poll_socket_add(readbits, con[i].aprsock, APR_POLLIN);
}
}
if (use_html)
output_html_results();
else
output_results();
}
/* ------------------------------------------------------- */
/* display copyright information */
static void copyright(void)
{
if (!use_html) {
printf("This is ApacheBench, Version %s\n", AB_VERSION " <$Revision: 1.58 $> apache-2.0");
printf("Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\n");
printf("Copyright (c) 1998-2001 The Apache Software Foundation, http://www.apache.org/\n");
printf("\n");
}
else {
printf("<p>\n");
printf(" This is ApacheBench, Version %s <i>&lt;%s&gt;</i> apache-2.0<br>\n", AB_VERSION, "$Revision: 1.58 $");
printf(" Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/<br>\n");
printf(" Copyright (c) 1998-2001 The Apache Software Foundation, http://www.apache.org/<br>\n");
printf("</p>\n<p>\n");
}
}
/* display usage information */
static void usage(const char *progname)
{
fprintf(stderr, "Usage: %s [options] [http://]hostname[:port]/path\n", progname);
fprintf(stderr, "Options are:\n");
fprintf(stderr, " -n requests Number of requests to perform\n");
fprintf(stderr, " -c concurrency Number of multiple requests to make\n");
fprintf(stderr, " -t timelimit Seconds to max. wait for responses\n");
fprintf(stderr, " -p postfile File containg data to POST\n");
fprintf(stderr, " -T content-type Content-type header for POSTing\n");
fprintf(stderr, " -v verbosity How much troubleshooting info to print\n");
fprintf(stderr, " -w Print out results in HTML tables\n");
fprintf(stderr, " -i Use HEAD instead of GET\n");
fprintf(stderr, " -x attributes String to insert as table attributes\n");
fprintf(stderr, " -y attributes String to insert as tr attributes\n");
fprintf(stderr, " -z attributes String to insert as td or th attributes\n");
fprintf(stderr, " -C attribute Add cookie, eg. 'Apache=1234. (repeatable)\n");
fprintf(stderr, " -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: zop'\n");
fprintf(stderr, " Inserted after all normal header lines. (repeatable)\n");
fprintf(stderr, " -A attribute Add Basic WWW Authentication, the attributes\n");
fprintf(stderr, " are a colon separated username and password.\n");
fprintf(stderr, " -p attribute Add Basic Proxy Authentication, the attributes\n");
fprintf(stderr, " are a colon separated username and password.\n");
fprintf(stderr, " -V Print version number and exit\n");
fprintf(stderr, " -k Use HTTP KeepAlive feature\n");
fprintf(stderr, " -h Display usage information (this message)\n");
exit(EINVAL);
}
/* ------------------------------------------------------- */
/* split URL into parts */
static int parse_url(char *url)
{
char *cp;
char *h;
char *scope_id;
apr_status_t rv;
if (strlen(url) > 7 && strncmp(url, "http://", 7) == 0)
url += 7;
if ((cp = strchr(url, '/')) == NULL)
return 1;
h = apr_palloc(cntxt, cp - url + 1);
memcpy(h, url, cp - url);
h[cp - url] = '\0';
rv = apr_parse_addr_port(&hostname, &scope_id, &port, h, cntxt);
if (rv != APR_SUCCESS || !hostname || scope_id) {
return 1;
}
strcpy(path, cp);
*cp = '\0';
if (*url == '[') { /* IPv6 numeric address string */
host_field = apr_psprintf(cntxt, "[%s]", hostname);
}
else {
host_field = hostname;
}
if (port == 0) { /* no port specified */
port = 80;
}
return 0;
}
/* ------------------------------------------------------- */
/* read data to POST from file, save contents and length */
static int open_postfile(const char *pfile)
{
apr_file_t *postfd = NULL;
apr_finfo_t finfo;
apr_fileperms_t mode = APR_OS_DEFAULT;
apr_size_t length;
apr_status_t rv;
char errmsg[120];
rv = apr_file_open(&postfd, pfile, APR_READ, mode, cntxt);
if (rv != APR_SUCCESS) {
printf("Invalid postfile name (%s): %s\n", pfile,
apr_strerror(rv, errmsg, sizeof errmsg));
return rv;
}
apr_file_info_get(&finfo, APR_FINFO_NORM, postfd);
postlen = finfo.size;
postdata = (char *) malloc(postlen);
if (!postdata) {
printf("Can\'t alloc postfile buffer\n");
return APR_ENOMEM;
}
length = postlen;
rv = apr_file_read(postfd, postdata, &length);
if (rv != APR_SUCCESS) {
printf("error reading postfile: %s\n",
apr_strerror(rv, errmsg, sizeof errmsg));
return rv;
}
if (length != postlen) {
printf("error reading postfile: read only %"
APR_SIZE_T_FMT " bytes",
length);
return APR_EINVAL;
}
apr_file_close(postfd);
return 0;
}
static void terminate(void)
{
apr_terminate();
}
/* ------------------------------------------------------- */
/* sort out command-line args and call test */
int main(int argc, const char *const argv[])
{
int r, l;
char tmp[1024];
apr_status_t status;
apr_getopt_t *opt;
const char *optarg;
char c;
/* table defaults */
tablestring = "";
trstring = "";
tdstring = "bgcolor=white";
cookie[0] = '\0';
auth[0] = '\0';
hdrs[0] = '\0';
apr_initialize();
atexit(terminate);
apr_pool_create(&cntxt, NULL);
#ifdef NOT_ASCII
status = apr_xlate_open(&to_ascii, "ISO8859-1", APR_DEFAULT_CHARSET, cntxt);
if (status) {
fprintf(stderr, "apr_xlate_open(to ASCII)->%d\n", status);
exit(1);
}
status = apr_xlate_open(&from_ascii, APR_DEFAULT_CHARSET, "ISO8859-1", cntxt);
if (status) {
fprintf(stderr, "apr_xlate_open(from ASCII)->%d\n", status);
exit(1);
}
status = apr_base64init_ebcdic(to_ascii, from_ascii);
if (status) {
fprintf(stderr, "apr_base64init_ebcdic()->%d\n", status);
exit(1);
}
#endif
apr_getopt_init(&opt, cntxt, argc, argv);
while ((status = apr_getopt(opt, "n:c:t:T:p:v:kVhwix:y:z:C:H:P:A:", &c, &optarg)) == APR_SUCCESS) {
switch (c) {
case 'n':
requests = atoi(optarg);
if (!requests) {
err("Invalid number of requests\n");
}
break;
case 'k':
keepalive = 1;
break;
case 'c':
concurrency = atoi(optarg);
break;
case 'i':
if (posting == 1)
err("Cannot mix POST and HEAD\n");
posting = -1;
break;
case 'p':
if (posting != 0)
err("Cannot mix POST and HEAD\n");
if (0 == (r = open_postfile(optarg))) {
posting = 1;
}
else if (postdata) {
exit(r);
}
break;
case 'v':
verbosity = atoi(optarg);
break;
case 't':
tlimit = atoi(optarg);
requests = MAX_REQUESTS; /* need to size data array on
* something */
break;
case 'T':
strcpy(content_type, optarg);
break;
case 'C':
strncat(cookie, "Cookie: ", sizeof(cookie));
strncat(cookie, optarg, sizeof(cookie));
strncat(cookie, "\r\n", sizeof(cookie));
break;
case 'A':
/*
* assume username passwd already to be in colon separated form.
* Ready to be uu-encoded.
*/
while (apr_isspace(*optarg))
optarg++;
l = apr_base64_encode(tmp, optarg, strlen(optarg));
tmp[l] = '\0';
strncat(auth, "Authorization: Basic ", sizeof(auth));
strncat(auth, tmp, sizeof(auth));
strncat(auth, "\r\n", sizeof(auth));
break;
case 'P':
/*
* assume username passwd already to be in colon separated form.
*/
while (apr_isspace(*optarg))
optarg++;
l = apr_base64_encode(tmp, optarg, strlen(optarg));
tmp[l] = '\0';
strncat(auth, "Proxy-Authorization: Basic ", sizeof(auth));
strncat(auth, tmp, sizeof(auth));
strncat(auth, "\r\n", sizeof(auth));
break;
case 'H':
strncat(hdrs, optarg, sizeof(hdrs));
strncat(hdrs, "\r\n", sizeof(hdrs));
break;
case 'w':
use_html = 1;
break;
/*
* if any of the following three are used, turn on html output
* automatically
*/
case 'x':
use_html = 1;
tablestring = optarg;
break;
case 'y':
use_html = 1;
trstring = optarg;
break;
case 'z':
use_html = 1;
tdstring = optarg;
break;
case 'h':
usage(argv[0]);
break;
case 'V':
copyright();
return 0;
}
}
if (opt->ind != argc - 1) {
fprintf(stderr, "%s: wrong number of arguments\n", argv[0]);
usage(argv[0]);
}
if (parse_url(apr_pstrdup(cntxt, opt->argv[opt->ind++]))) {
fprintf(stderr, "%s: invalid URL\n", argv[0]);
usage(argv[0]);
}
copyright();
test();
return 0;
}