ab.c revision 16478631d2fd87116d7e41b3ed8748343b453d88
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl/* ====================================================================
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * The Apache Software License, Version 1.1
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl *
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu * reserved.
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl *
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * Redistribution and use in source and binary forms, with or without
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * modification, are permitted provided that the following conditions
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * are met:
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl *
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * 1. Redistributions of source code must retain the above copyright
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * notice, this list of conditions and the following disclaimer.
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco *
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * 2. Redistributions in binary form must reproduce the above copyright
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * notice, this list of conditions and the following disclaimer in
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * the documentation and/or other materials provided with the
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * distribution.
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco *
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * 3. The end-user documentation included with the redistribution,
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * if any, must include the following acknowledgment:
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * "This product includes software developed by the
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * Apache Software Foundation (http://www.apache.org/)."
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * Alternately, this acknowledgment may appear in the software itself,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * if and wherever such third-party acknowledgments normally appear.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco *
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * 4. The names "Apache" and "Apache Software Foundation" must
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * not be used to endorse or promote products derived from this
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * software without prior written permission. For written
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * permission, please contact apache@apache.org.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco *
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * 5. Products derived from this software may not be called "Apache",
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * nor may "Apache" appear in their name, without prior written
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * permission of the Apache Software Foundation.
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco *
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * SUCH DAMAGE.
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * ====================================================================
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco *
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * This software consists of voluntary contributions made by many
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco * individuals on behalf of the Apache Software Foundation. For more
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * information on the Apache Software Foundation, please see
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * <http://www.apache.org/>.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco *
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco * Portions of this software are based upon public domain software
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * originally written at the National Center for Supercomputing Applications,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * University of Illinois, Urbana-Champaign.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco */
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco
6e121321775373fe11161d23c541437456df19b4Adrián Riesco/*
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** This program is based on ZeusBench V1.0 written by Adam Twiss
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** which is Copyright (c) 1996 by Zeus Technology Ltd. http://www.zeustech.net/
6e121321775373fe11161d23c541437456df19b4Adrián Riesco **
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** This software is provided "as is" and any express or implied waranties,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** including but not limited to, the implied warranties of merchantability and
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** fitness for a particular purpose are disclaimed. In no event shall
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** Zeus Technology Ltd. be liable for any direct, indirect, incidental, special,
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco ** exemplary, or consequential damaged (including, but not limited to,
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco ** procurement of substitute good or services; loss of use, data, or profits;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** or business interruption) however caused and on theory of liability. Whether
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** in contract, strict liability or tort (including negligence or otherwise)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** arising in any way out of the use of this software, even if advised of the
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** possibility of such damage.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco **
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/*
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** HISTORY:
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** with input from Mike Belshe <mbelshe@netscape.com> and
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco ** Michael Campanella <campanella@stevms.enet.dec.com>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 1999
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** Version 1.3d
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Increased version number - as some of the socket/error handling has
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** fundamentally changed - and will give fundamentally different results
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** in situations where a server is dropping requests. Therefore you can
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco ** no longer compare results of AB as easily. Hence the inc of the version.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** They should be closer to the truth though. Sander & <dirkx@covalent.net>, End 2000.
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco ** - Fixed proxy functionality, added median/mean statistics, added gnuplot
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** output option, added _experimental/rudimentary_ SSL support. Added
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** confidence guestimators and warnings. Sander & <dirkx@covalent.net>, End 2000
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Fixed serious int overflow issues which would cause realistic (longer
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco ** than a few minutes) run's to have wrong (but believable) results. Added
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** trapping of connection errors which influenced measurements.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** Contributed by Sander Temme - <sctemme@covalent.net>, Early 2001
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** Version 1.3e
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Changed timeout behavour during write to work whilst the sockets
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** are filling up and apr_write() does writes a few - but not all.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** This will potentially change results. <dirkx@webweaving.org>, April 2001
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco **
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco/*
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * BUGS:
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco *
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * - uses strcpy/etc.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * - has various other poor buffer attacks related to the lazy parsing of
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * response headers from the server
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * - doesn't implement much of HTTP/1.x, only accepts certain forms of
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * responses
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * - (performance problem) heavy use of strstr shows up top in profile
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * only an issue for loopback usage
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#define AB_VERSION "1.3e"
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* -------------------------------------------------------------------- */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#if 'A' != 0x41
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* Hmmm... This source code isn't being compiled in ASCII.
6e121321775373fe11161d23c541437456df19b4Adrián Riesco * In order for data that flows over the network to make
6e121321775373fe11161d23c541437456df19b4Adrián Riesco * sense, we need to translate to/from ASCII.
6e121321775373fe11161d23c541437456df19b4Adrián Riesco */
6e121321775373fe11161d23c541437456df19b4Adrián Riesco#define NOT_ASCII
6e121321775373fe11161d23c541437456df19b4Adrián Riesco#endif
6e121321775373fe11161d23c541437456df19b4Adrián Riesco
6e121321775373fe11161d23c541437456df19b4Adrián Riesco/* affects include files on Solaris */
6e121321775373fe11161d23c541437456df19b4Adrián Riesco#define BSD_COMP
6e121321775373fe11161d23c541437456df19b4Adrián Riesco
6e121321775373fe11161d23c541437456df19b4Adrián Riesco#include "apr.h"
6e121321775373fe11161d23c541437456df19b4Adrián Riesco#include "apr_strings.h"
6e121321775373fe11161d23c541437456df19b4Adrián Riesco#include "apr_network_io.h"
6e121321775373fe11161d23c541437456df19b4Adrián Riesco#include "apr_file_io.h"
6e121321775373fe11161d23c541437456df19b4Adrián Riesco#include "apr_time.h"
6e121321775373fe11161d23c541437456df19b4Adrián Riesco#include "apr_getopt.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "apr_general.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <signal.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "apr_lib.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#define APR_WANT_STRFUNC
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "apr_want.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#if APR_HAVE_STDIO_H
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <stdio.h> /* for EOF */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#if APR_HAVE_STDLIB_H
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <stdlib.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco#include "apr_base64.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#ifdef NOT_ASCII
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include "apr_xlate.h"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#if APR_HAVE_STDIO_H
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <stdio.h>
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco#endif
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco#if APR_HAVE_STDLIB_H
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <stdlib.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco#ifdef USE_SSL
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco#if ((!(RSAREF)) && (!(SYSSSL)))
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* Libraries on most systems.. */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <openssl/rsa.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <openssl/crypto.h>
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco#include <openssl/x509.h>
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco#include <openssl/pem.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <openssl/err.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <openssl/ssl.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#else
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* Libraries for RSAref and SYSSSL */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <rsa.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <crypto.h>
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco#include <x509.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <pem.h>
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco#include <err.h>
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco#include <ssl.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#include <math.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco#if APR_HAVE_CTYPE_H
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco#include <ctype.h>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* ------------------- DEFINITIONS -------------------------- */
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco#ifndef LLONG_MAX
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco#define AB_MAX APR_INT64_C(0x7fffffffffffffff)
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco#else
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco#define AB_MAX LLONG_MAX
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco#endif
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco/* maximum number of requests on a time limited test */
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco#define MAX_REQUESTS 50000
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* good old state hostname */
ab9c6be005cb2af851307b7968c2baa16a76d6b1Adrián Riesco#define STATE_UNCONNECTED 0
5eb747ed1f9cb3d902d4277badfc2a42f9f98b0cAdrián Riesco#define STATE_CONNECTING 1
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco#define STATE_READ 2
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco#define CBUFFSIZE (2048)
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
3f8cdebaede9921402318d525b57a9af8f9279d3Adrián Riescostruct connection {
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco apr_socket_t *aprsock;
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco int state;
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco int read; /* amount of bytes read */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco int bread; /* amount of body read */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco int rwrite, rwrote; /* keep pointers in what we write - across
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco * EAGAINs */
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco int length; /* Content-Length value used for keep-alive */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco char cbuff[CBUFFSIZE]; /* a buffer to store server response header */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco int cbx; /* offset in cbuffer */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco int keepalive; /* non-zero if a keep-alive request */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco int gotheader; /* non-zero if we have the entire header in
8b389272b3312c6d3e3c0aee2e94bca6dbdade50Adrián Riesco * cbuff */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco apr_time_t start, /* Start of connection */
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco connect, /* Connected, start writing */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco endwrite, /* Request written */
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco beginread, /* First byte of input */
0f593bb6e3f0bc82abf3d6d3c76ef222a43d0476Adrián Riesco done; /* Connection closed */
0f593bb6e3f0bc82abf3d6d3c76ef222a43d0476Adrián Riesco
8b389272b3312c6d3e3c0aee2e94bca6dbdade50Adrián Riesco int socknum;
8b389272b3312c6d3e3c0aee2e94bca6dbdade50Adrián Riesco#ifdef USE_SSL
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco SSL *ssl;
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco#endif
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco};
8b389272b3312c6d3e3c0aee2e94bca6dbdade50Adrián Riesco
8b389272b3312c6d3e3c0aee2e94bca6dbdade50Adrián Riescostruct data {
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco#ifdef USE_SSL
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco /* XXXX insert SSL timings */
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco#endif
8b389272b3312c6d3e3c0aee2e94bca6dbdade50Adrián Riesco int read; /* number of bytes read */
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco apr_time_t starttime; /* start time of connection in seconds since
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco * Jan. 1, 1970 */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco apr_interval_time_t waittime; /* Between writing request and reading
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco * response */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco apr_interval_time_t ctime; /* time in ms to connect */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco apr_interval_time_t time; /* time in ms for connection */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco};
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco#define ap_min(a,b) ((a)<(b))?(a):(b)
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco#define ap_max(a,b) ((a)>(b))?(a):(b)
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco/* --------------------- GLOBALS ---------------------------- */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint verbosity = 0; /* no verbosity by default */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint posting = 0; /* GET by default */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint requests = 1; /* Number of requests to make */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint heartbeatres = 100; /* How often do we say we're alive */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint concurrency = 1; /* Number of multiple requests to make */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint percentile = 1; /* Show percentile served */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint confidence = 1; /* Show confidence estimator and warnings */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint tlimit = 0; /* time limit in cs */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint keepalive = 0; /* try and do keepalive connections */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar servername[1024]; /* name that server reports */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar *hostname; /* host name from URL */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar *host_field; /* value of "Host:" header field */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar path[1024]; /* path name */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar postfile[1024]; /* name of file containing post data */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar *postdata; /* *buffer containing data from postfile */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoapr_size_t postlen = 0; /* length of data to be POSTed */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar content_type[1024]; /* content type to put in POST header */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar cookie[1024], /* optional cookie line */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco auth[1024], /* optional (basic/uuencoded)
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco * authentification */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco hdrs[4096]; /* optional arbitrary headers */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoapr_port_t port; /* port number */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar proxyhost[1024]; /* proxy host name */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint proxyport = 0; /* proxy port */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar connecthost[1024];
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint connectport;
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar *gnuplot; /* GNUplot file */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar *csvperc; /* CSV Percentile file */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar url[1024];
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar fullurl[1024];
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint isproxy = 0;
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoapr_time_t aprtimeout = 30 * APR_USEC_PER_SEC; /* timeout value */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco /*
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco * XXX - this is now a per read/write transact type of value
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint use_html = 0; /* use html in the report */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoconst char *tablestring;
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoconst char *trstring;
223be434693e8c97e2522ac19155a284b3536035Adrián Riescoconst char *tdstring;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco
223be434693e8c97e2522ac19155a284b3536035Adrián Riescoint doclen = 0; /* the length the document should be */
223be434693e8c97e2522ac19155a284b3536035Adrián Riescolong started = 0; /* number of requests started, so no excess */
223be434693e8c97e2522ac19155a284b3536035Adrián Riescolong totalread = 0; /* total number of bytes read */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riescolong totalbread = 0; /* totoal amount of entity body read */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riescolong totalposted = 0; /* total number of bytes posted, inc. headers */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riescolong done = 0; /* number of requests we have done */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riescolong doneka = 0; /* number of keep alive connections done */
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riescolong good = 0, bad = 0; /* number of good and bad requests */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riescolong epipe = 0; /* number of broken pipe writes */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco#ifdef USE_SSL
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riescoint ssl = 0;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián RiescoSSL_CTX *ctx;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco#endif
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco/* store error cases */
223be434693e8c97e2522ac19155a284b3536035Adrián Riescoint err_length = 0, err_conn = 0, err_except = 0;
223be434693e8c97e2522ac19155a284b3536035Adrián Riescoint err_response = 0;
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco
223be434693e8c97e2522ac19155a284b3536035Adrián Riescoapr_time_t start, endtime;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco/* global request (and its length) */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riescochar _request[512];
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riescochar *request = _request;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riescoapr_size_t reqlen;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco/* one global throw-away buffer to read stuff into */
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riescochar buffer[8192];
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco
0be63c5d4b5e66cc600a0003081ae2bf85be9615Adrián Riesco/* interesting percentiles */
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riescoint percs[] = {50, 66, 75, 80, 90, 95, 98, 99, 100};
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco
0be63c5d4b5e66cc600a0003081ae2bf85be9615Adrián Riescostruct connection *con; /* connection array */
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riescostruct data *stats; /* date for each request */
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riescoapr_pool_t *cntxt;
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riescoapr_pollfd_t *readbits;
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco#ifdef NOT_ASCII
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riescoapr_xlate_t *from_ascii, *to_ascii;
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco#endif
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riescostatic void close_connection(struct connection * c);
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco/* --------------------------------------------------------- */
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco/* simple little function to write an error string and exit */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riescostatic void err(char *s)
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco{
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco fprintf(stderr, "%s", s);
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco exit(1);
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco}
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco/* simple little function to write an APR error string and exit */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riescostatic void apr_err(char *s, apr_status_t rv)
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco{
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco char buf[120];
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco fprintf(stderr,
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco "%s: %s (%d)\n",
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco s, apr_strerror(rv, buf, sizeof buf), rv);
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco exit(rv);
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco}
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco/* --------------------------------------------------------- */
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco/* write out request to a connection - assumes we can write
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco * (small) request out in one go into our new socket buffer
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco *
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco */
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riescostatic void write_request(struct connection * c)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco{
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco do {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_time_t tnow = apr_time_now();
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco apr_size_t l = c->rwrite;
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco apr_status_t e;
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco /*
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco * First time round ?
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco */
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco if (c->rwrite == 0) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_setsocketopt(c->aprsock, APR_SO_TIMEOUT, 0);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->connect = tnow;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->rwrite = reqlen;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->rwrote = 0;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco if (posting)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->rwrite += postlen;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco }
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco else if (tnow > c->connect + aprtimeout) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco printf("Send request timed out!\n");
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco close_connection(c);
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco return;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco }
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco e = apr_send(c->aprsock, request + c->rwrote, &l);
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco /*
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco * Bail early on the most common case
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco */
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if (l == c->rwrite)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco break;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if (e != APR_SUCCESS) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco /*
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco * Let's hope this traps EWOULDBLOCK too !
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco */
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if (!APR_STATUS_IS_EAGAIN(e)) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco epipe++;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco printf("Send request failed!\n");
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco close_connection(c);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco }
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco }
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->rwrote += l;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->rwrite -= l;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco } while (1);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco totalposted += c->rwrite;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco c->state = STATE_READ;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco c->endwrite = apr_time_now();
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_poll_socket_add(readbits, c->aprsock, APR_POLLIN);
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco}
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco/* --------------------------------------------------------- */
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco/* calculate and output results */
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riescostatic int compradre(struct data * a, struct data * b)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco{
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if ((a->ctime) < (b->ctime))
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return -1;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if ((a->ctime) > (b->ctime))
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return +1;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return 0;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco}
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riescostatic int comprando(struct data * a, struct data * b)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco{
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if ((a->time) < (b->time))
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return -1;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco if ((a->time) > (b->time))
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return +1;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return 0;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco}
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riescostatic int compri(struct data * a, struct data * b)
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco{
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco apr_interval_time_t p = a->time - a->ctime;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_interval_time_t q = b->time - b->ctime;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco if (p < q)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return -1;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if (p > q)
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco return +1;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco return 0;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco}
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riescostatic int compwait(struct data * a, struct data * b)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco{
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if ((a->waittime) < (b->waittime))
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return -1;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if ((a->waittime) > (b->waittime))
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return 1;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return 0;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco}
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riescostatic void output_results(void)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco{
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_interval_time_t timetakenusec;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco float timetaken;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco endtime = apr_time_now();
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco timetakenusec = endtime - start;
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco timetaken = (float) timetakenusec / APR_USEC_PER_SEC;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("\r \r");
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("Server Software: %s\n", servername);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("Server Hostname: %s\n", hostname);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("Server Port: %hd\n", port);
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco printf("\n");
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco printf("Document Path: %s\n", path);
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco printf("Document Length: %d bytes\n", doclen);
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco printf("\n");
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco printf("Concurrency Level: %d\n", concurrency);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("Time taken for tests: %" APR_TIME_T_FMT ".%03" APR_TIME_T_FMT " seconds\n",
71410be62420b321abb02ef1ac2b7f2141b3bc7fAdrián Riesco (apr_interval_time_t) timetakenusec / APR_USEC_PER_SEC,
71410be62420b321abb02ef1ac2b7f2141b3bc7fAdrián Riesco (apr_interval_time_t) timetakenusec % APR_USEC_PER_SEC);
71410be62420b321abb02ef1ac2b7f2141b3bc7fAdrián Riesco printf("Complete requests: %ld\n", done);
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco printf("Failed requests: %ld\n", bad);
71410be62420b321abb02ef1ac2b7f2141b3bc7fAdrián Riesco if (bad)
71410be62420b321abb02ef1ac2b7f2141b3bc7fAdrián Riesco printf(" (Connect: %d, Length: %d, Exceptions: %d)\n",
71410be62420b321abb02ef1ac2b7f2141b3bc7fAdrián Riesco err_conn, err_length, err_except);
71410be62420b321abb02ef1ac2b7f2141b3bc7fAdrián Riesco printf("Write errors: %ld\n", epipe);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (err_response)
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("Non-2xx responses: %d\n", err_response);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (keepalive)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("Keep-Alive requests: %ld\n", doneka);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("Total transferred: %ld bytes\n", totalread);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco if (posting > 0)
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("Total POSTed: %ld\n", totalposted);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("HTML transferred: %ld bytes\n", totalbread);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* avoid divide by zero */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco if (timetaken) {
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco printf("Requests per second: %.2f [#/sec] (mean)\n", done / timetaken);
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco printf("Time per request: %.3f [ms] (mean)\n", concurrency * timetaken / done);
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco printf("Time per request: %.3f [ms] (mean, across all concurrent requests)\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco timetaken / done);
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco printf("Transfer rate: %.2f [Kbytes/sec] received\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco totalread / 1024 / timetaken);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (posting > 0) {
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf(" %.2f kb/s sent\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (float) totalposted / timetaken / 1024);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf(" %.2f kb/s total\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (float) (totalread + totalposted) / timetaken / 1024);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco
172f4dfb4b858440fab545bac00d3ec4abd0cbe4Adrián Riesco if (requests) {
172f4dfb4b858440fab545bac00d3ec4abd0cbe4Adrián Riesco /* work out connection times */
172f4dfb4b858440fab545bac00d3ec4abd0cbe4Adrián Riesco long i;
172f4dfb4b858440fab545bac00d3ec4abd0cbe4Adrián Riesco double totalcon = 0, total = 0, totald = 0, totalwait = 0;
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco apr_interval_time_t mincon = AB_MAX, mintot = AB_MAX, mind = AB_MAX,
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco minwait = AB_MAX;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_interval_time_t maxcon = 0, maxtot = 0, maxd = 0, maxwait = 0;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_interval_time_t meancon = 0, meantot = 0, meand = 0, meanwait = 0;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco double sdtot = 0, sdcon = 0, sdd = 0, sdwait = 0;
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco for (i = 0; i < requests; i++) {
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco struct data s = stats[i];
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco mincon = ap_min(mincon, s.ctime);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco mintot = ap_min(mintot, s.time);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco mind = ap_min(mind, s.time - s.ctime);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco minwait = ap_min(minwait, s.waittime);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco maxcon = ap_max(maxcon, s.ctime);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco maxtot = ap_max(maxtot, s.time);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco maxd = ap_max(maxd, s.time - s.ctime);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco maxwait = ap_max(maxwait, s.waittime);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco totalcon += s.ctime;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco total += s.time;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco totald += s.time - s.ctime;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco totalwait += s.waittime;
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco totalcon /= requests;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco total /= requests;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco totald /= requests;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco totalwait /= requests;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco for (i = 0; i < requests; i++) {
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco struct data s = stats[i];
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_interval_time_t a;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco a = (s.time - total);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sdtot += a * a;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco a = (s.ctime - totalcon);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sdcon += a * a;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco a = (s.time - s.ctime - totald);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sdd += a * a;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco a = (s.waittime - totalwait);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sdwait += a * a;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco };
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sdtot = (requests > 1) ? sqrt(sdtot / (requests - 1)) : 0;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sdcon = (requests > 1) ? sqrt(sdcon / (requests - 1)) : 0;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sdd = (requests > 1) ? sqrt(sdd / (requests - 1)) : 0;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sdwait = (requests > 1) ? sqrt(sdwait / (requests - 1)) : 0;
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (gnuplot) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco FILE *out = fopen(gnuplot, "w");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco long i;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_time_t sttime;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco char tmstring[1024];/* XXXX */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (!out) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco perror("Cannot open gnuplot output file");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco exit(1);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco };
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco fprintf(out, "starttime\tseconds\tctime\tdtime\tttime\twait\n");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco for (i = 0; i < requests; i++) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sttime = stats[i].starttime;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (void) apr_ctime(tmstring, sttime);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco tmstring[strlen(tmstring) - 1] = '\0'; /* ctime returns a
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * string with a
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * trailing newline */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco fprintf(out, "%s\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT "\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco tmstring,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sttime,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco stats[i].ctime,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco stats[i].time - stats[i].ctime,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco stats[i].time,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco stats[i].waittime);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco fclose(out);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco };
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /*
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * XXX: what is better; this hideous cast of the copare function; or
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * the four warnings during compile ? dirkx just does not know and
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * hates both/
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco qsort(stats, requests, sizeof(struct data),
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco (int (*) (const void *, const void *)) compradre);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if ((requests > 1) && (requests % 2))
6f6549c13f912de12345850e4eb248ec358c1b43Adrián Riesco meancon = (stats[requests / 2].ctime + stats[requests / 2 + 1].ctime) / 2;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco meancon = stats[requests / 2].ctime;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
6f6549c13f912de12345850e4eb248ec358c1b43Adrián Riesco qsort(stats, requests, sizeof(struct data),
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (int (*) (const void *, const void *)) compri);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if ((requests > 1) && (requests % 2))
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco meand = (stats[requests / 2].time + stats[requests / 2 + 1].time \
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco -stats[requests / 2].ctime - stats[requests / 2 + 1].ctime) / 2;
172f4dfb4b858440fab545bac00d3ec4abd0cbe4Adrián Riesco else
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco meand = stats[requests / 2].time - stats[requests / 2].ctime;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco qsort(stats, requests, sizeof(struct data),
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (int (*) (const void *, const void *)) compwait);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if ((requests > 1) && (requests % 2))
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco meanwait = (stats[requests / 2].waittime + stats[requests / 2 + 1].waittime) / 2;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco meanwait = stats[requests / 2].waittime;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco qsort(stats, requests, sizeof(struct data),
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (int (*) (const void *, const void *)) comprando);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if ((requests > 1) && (requests % 2))
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco meantot = (stats[requests / 2].time + stats[requests / 2 + 1].time) / 2;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco meantot = stats[requests / 2].time;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("\nConnection Times (ms)\n");
3b1e33dd8d2de8301d7a31860dd1819bd3752718Adrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (confidence) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#define CONF_FMT_STRING "%" APR_TIME_T_FMT " %5d %6.1f %" APR_TIME_T_FMT " %" APR_TIME_T_FMT "\n"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf(" min mean[+/-sd] median max\n");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("Connect: " CONF_FMT_STRING,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco mincon, (int) (totalcon + 0.5), sdcon, meancon, maxcon);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("Processing: " CONF_FMT_STRING,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco mind, (int) (totald + 0.5), sdd, meand, maxd);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("Waiting: " CONF_FMT_STRING,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco minwait, (int) (totalwait + 0.5), sdwait, meanwait, maxwait);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("Total: " CONF_FMT_STRING,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco mintot, (int) (total + 0.5), sdtot, meantot, maxtot);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco#undef CONF_FMT_STRING
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco#define SANE(what,avg,mean,sd) \
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco { \
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco double d = avg - mean; \
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco if (d < 0) d = -d; \
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco if (d > 2 * sd ) \
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf("ERROR: The median and mean for " what " are more than twice the standard\n" \
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco " deviation apart. These results are NOT reliable.\n"); \
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else if (d > sd ) \
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("WARING: The median and mean for " what " are not within a normal deviation\n" \
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco " These results are propably not that reliable.\n"); \
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco }
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco SANE("the initial connection time", totalcon, meancon, sdcon);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco SANE("the processing time", totald, meand, sdd);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco SANE("the waiting time", totalwait, meanwait, sdwait);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco SANE("the total time", total, meantot, sdtot);
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco }
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco else {
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf(" min avg max\n");
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco#define CONF_FMT_STRING "%5" APR_TIME_T_FMT " %5e %5" APR_TIME_T_FMT "\n"
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf("Connect: " CONF_FMT_STRING, mincon, totalcon / requests,
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco maxcon);
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf("Processing: " CONF_FMT_STRING, mintot - mincon,
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco (total / requests) - (totalcon / requests), maxtot - maxcon);
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf("Total: " CONF_FMT_STRING, mintot, total / requests,
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco maxtot);
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco#undef CONF_FMT_STRING
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco }
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco /* Sorted on total connect times */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (percentile && (requests > 1)) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("\nPercentage of the requests served within a certain time (ms)\n");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco for (i = 0; i < sizeof(percs) / sizeof(int); i++)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (percs[i] <= 0)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf(" 0%% <0> (never)\n");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else if (percs[i] >= 100)
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf(" 100%% %5" APR_TIME_T_FMT " (longest request)\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco stats[requests - 1].time);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf(" %d%% %5" APR_TIME_T_FMT "\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco percs[i], stats[(int) (requests * percs[i] / 100)].time);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco };
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (csvperc) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco FILE *out = fopen(csvperc, "w");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco int i;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (!out) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco perror("Cannot open CSV output file");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco exit(1);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco };
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco fprintf(out, "" "Percentage served" "," "Time in ms" "\n");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco for (i = 0; i < 100; i++) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco double d;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (i == 0)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco d = stats[0].time;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else if (i == 100)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco d = stats[requests - 1].time;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco d = stats[(int) (0.5 + requests * i / 100.0)].time;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco fprintf(out, "%d,%e\n", i, d);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco fclose(out);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco };
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco}
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* --------------------------------------------------------- */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* calculate and output results in HTML */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riescostatic void output_html_results(void)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco{
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco long timetaken;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco endtime = apr_time_now();
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco timetaken = (endtime - start) / 1000;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("\n\n<table %s>\n", tablestring);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Server Software:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%s</td></tr>\n",
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco trstring, tdstring, tdstring, servername);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("<tr %s><th colspan=2 %s>Server Hostname:</th>"
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco "<td colspan=2 %s>%s</td></tr>\n",
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco trstring, tdstring, tdstring, hostname);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("<tr %s><th colspan=2 %s>Server Port:</th>"
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco "<td colspan=2 %s>%hd</td></tr>\n",
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco trstring, tdstring, tdstring, port);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("<tr %s><th colspan=2 %s>Document Path:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%s</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco trstring, tdstring, tdstring, path);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Document Length:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%d bytes</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco trstring, tdstring, tdstring, doclen);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Concurrency Level:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%d</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco trstring, tdstring, tdstring, concurrency);
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf("<tr %s><th colspan=2 %s>Time taken for tests:</th>"
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco "<td colspan=2 %s>%qd.%03qd seconds</td></tr>\n",
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco trstring, tdstring, tdstring, timetaken / APR_USEC_PER_SEC, timetaken % APR_USEC_PER_SEC);
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf("<tr %s><th colspan=2 %s>Complete requests:</th>"
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco "<td colspan=2 %s>%ld</td></tr>\n",
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco trstring, tdstring, tdstring, done);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Failed requests:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%ld</td></tr>\n",
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco trstring, tdstring, tdstring, bad);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (bad)
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco printf("<tr %s><td colspan=4 %s > (Connect: %d, Length: %d, Exceptions: %d)</td></tr>\n",
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco trstring, tdstring, err_conn, err_length, err_except);
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco if (err_response)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Non-2xx responses:</th>"
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco "<td colspan=2 %s>%d</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco trstring, tdstring, tdstring, err_response);
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco if (keepalive)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Keep-Alive requests:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%ld</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco trstring, tdstring, tdstring, doneka);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Total transferred:</th>"
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco "<td colspan=2 %s>%ld bytes</td></tr>\n",
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco trstring, tdstring, tdstring, totalread);
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco if (posting > 0)
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco printf("<tr %s><th colspan=2 %s>Total POSTed:</th>"
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco "<td colspan=2 %s>%ld</td></tr>\n",
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco trstring, tdstring, tdstring, totalposted);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>HTML transferred:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%ld bytes</td></tr>\n",
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco trstring, tdstring, tdstring, totalbread);
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco /* avoid divide by zero */
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco if (timetaken) {
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco printf("<tr %s><th colspan=2 %s>Requests per second:</th>"
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco "<td colspan=2 %s>%.2f</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco trstring, tdstring, tdstring, 1000 * (float) (done) / timetaken);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Transfer rate:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%.2f kb/s received</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco trstring, tdstring, tdstring, (float) (totalread) / timetaken);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (posting > 0) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><td colspan=2 %s>&nbsp;</td>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%.2f kb/s sent</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco trstring, tdstring, tdstring,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (float) (totalposted) / timetaken);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><td colspan=2 %s>&nbsp;</td>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%.2f kb/s total</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco trstring, tdstring, tdstring,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (float) (totalread + totalposted) / timetaken);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco } {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* work out connection times */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco long i;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_interval_time_t totalcon = 0, total = 0;
6f6549c13f912de12345850e4eb248ec358c1b43Adrián Riesco apr_interval_time_t mincon = AB_MAX, mintot = AB_MAX;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_interval_time_t maxcon = 0, maxtot = 0;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco for (i = 0; i < requests; i++) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco struct data s = stats[i];
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco mincon = ap_min(mincon, s.ctime);
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco mintot = ap_min(mintot, s.time);
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco maxcon = ap_max(maxcon, s.ctime);
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco maxtot = ap_max(maxtot, s.time);
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco totalcon += s.ctime;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco total += s.time;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco if (requests > 0) { /* avoid division by zero (if 0 requests) */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco printf("<tr %s><th %s colspan=4>Connnection Times (ms)</th></tr>\n",
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco trstring, tdstring);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th %s>&nbsp;</th> <th %s>min</th> <th %s>avg</th> <th %s>max</th></tr>\n",
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco trstring, tdstring, tdstring, tdstring, tdstring);
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco printf("<tr %s><th %s>Connect:</th>"
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco "<td %s>%5" APR_TIME_T_FMT "</td>"
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco "<td %s>%5" APR_TIME_T_FMT "</td>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td %s>%5" APR_TIME_T_FMT "</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco trstring, tdstring, tdstring, mincon, tdstring, totalcon / requests, tdstring, maxcon);
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco printf("<tr %s><th %s>Processing:</th>"
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco "<td %s>%5" APR_TIME_T_FMT "</td>"
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco "<td %s>%5" APR_TIME_T_FMT "</td>"
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco "<td %s>%5" APR_TIME_T_FMT "</td></tr>\n",
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco trstring, tdstring, tdstring, mintot - mincon, tdstring,
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco (total / requests) - (totalcon / requests), tdstring, maxtot - maxcon);
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco printf("<tr %s><th %s>Total:</th>"
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco "<td %s>%5" APR_TIME_T_FMT "</td>"
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco "<td %s>%5" APR_TIME_T_FMT "</td>"
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco "<td %s>%5" APR_TIME_T_FMT "</td></tr>\n",
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco trstring, tdstring, tdstring, mintot, tdstring, total / requests, tdstring, maxtot);
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco }
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco printf("</table>\n");
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco }
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco}
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco/* --------------------------------------------------------- */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco
6e121321775373fe11161d23c541437456df19b4Adrián Riesco/* start asnchronous non-blocking connection */
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riescostatic void start_connect(struct connection * c)
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco{
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco apr_status_t rv;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco apr_sockaddr_t *destsa;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco if (!(started < requests))
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco return;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco c->read = 0;
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco c->bread = 0;
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco c->keepalive = 0;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->cbx = 0;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->gotheader = 0;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->rwrite = 0;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if ((rv = apr_sockaddr_info_get(&destsa, connecthost, APR_UNSPEC, connectport, 0, cntxt))
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco != APR_SUCCESS) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco char buf[120];
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_snprintf(buf, sizeof(buf),
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco "apr_sockaddr_info_get() for %s", connecthost);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_err(buf, rv);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco }
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if ((rv = apr_socket_create(&c->aprsock, destsa->sa.sin.sin_family,
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco SOCK_STREAM, cntxt)) != APR_SUCCESS) {
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco apr_err("socket", rv);
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco }
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->start = apr_time_now();
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if ((rv = apr_connect(c->aprsock, destsa)) != APR_SUCCESS) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if (APR_STATUS_IS_EINPROGRESS(rv)) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->state = STATE_CONNECTING;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->rwrite = 0;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_poll_socket_add(readbits, c->aprsock, APR_POLLOUT);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco return;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco }
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco else {
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco apr_poll_socket_remove(readbits, c->aprsock);
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco apr_socket_close(c->aprsock);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco err_conn++;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if (bad++ > 10) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco fprintf(stderr,
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco "\nTest aborted after 10 failures\n\n");
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_err("apr_connect()", rv);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco }
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->state = STATE_UNCONNECTED;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco start_connect(c);
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco return;
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco }
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco }
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco /* connected first time */
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco started++;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco write_request(c);
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco}
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco/* --------------------------------------------------------- */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco/* close down connection and save stats */
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riescostatic void close_connection(struct connection * c)
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco{
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco if (c->read == 0 && c->keepalive) {
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco /*
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco * server has legitimately shut down an idle keep alive request
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco */
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if (good)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco good--; /* connection never happened */
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco }
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco else {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (good == 1) {
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco /* first time here */
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco doclen = c->bread;
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco }
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco else if (c->bread != doclen) {
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco bad++;
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco err_length++;
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco }
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco /* save out time */
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco if (done < requests) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco struct data s;
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco if ((done) && heartbeatres && !(done % heartbeatres)) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco fprintf(stderr, "Completed %ld requests\n", done);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco fflush(stderr);
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco }
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco c->done = apr_time_now();
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco s.read = c->read;
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco s.starttime = c->start;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco s.ctime = (c->connect - c->start) / 1000;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco s.time = (c->done - c->start) / 1000;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco s.waittime = (c->beginread - c->endwrite) / 1000;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco stats[done++] = s;
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco }
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco }
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_poll_socket_remove(readbits, c->aprsock);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_socket_close(c->aprsock);
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco c->state = STATE_UNCONNECTED;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco /* connect again */
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco start_connect(c);
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco return;
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco}
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco/* --------------------------------------------------------- */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* read data from connection */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riescostatic void read_connection(struct connection * c)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco{
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_size_t r;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco apr_status_t status;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco char *part;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco char respcode[4]; /* 3 digits and null */
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco r = sizeof(buffer);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_setsocketopt(c->aprsock, APR_SO_TIMEOUT, aprtimeout);
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco status = apr_recv(c->aprsock, buffer, &r);
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco if (r == 0 || (status != APR_SUCCESS && !APR_STATUS_IS_EAGAIN(status))) {
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco good++;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco close_connection(c);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (APR_STATUS_IS_EAGAIN(status))
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco totalread += r;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (c->read == 0) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco c->beginread = apr_time_now();
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco };
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco c->read += r;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (!c->gotheader) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco char *s;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco int l = 4;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco int space = CBUFFSIZE - c->cbx - 1; /* -1 to allow for 0
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * terminator */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco int tocopy = (space < r) ? space : r;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#ifdef NOT_ASCII
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_size_t inbytes_left = space, outbytes_left = space;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco status = apr_xlate_conv_buffer(from_ascii, buffer, &inbytes_left,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco c->cbuff + c->cbx, &outbytes_left);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (status || inbytes_left || outbytes_left) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco fprintf(stderr, "only simple translation is supported (%d/%u/%u)\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco status, inbytes_left, outbytes_left);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco exit(1);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#else
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco memcpy(c->cbuff + c->cbx, buffer, space);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif /* NOT_ASCII */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco c->cbx += tocopy;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco space -= tocopy;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco c->cbuff[c->cbx] = 0; /* terminate for benefit of strstr */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (verbosity >= 4) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("LOG: header received:\n%s\n", c->cbuff);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco s = strstr(c->cbuff, "\r\n\r\n");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /*
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * this next line is so that we talk to NCSA 1.5 which blatantly
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * breaks the http specifaction
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (!s) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco s = strstr(c->cbuff, "\n\n");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco l = 2;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (!s) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* read rest next time */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (space) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco return;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* header is in invalid or too big - close connection */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_poll_socket_remove(readbits, c->aprsock);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_socket_close(c->aprsock);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco err_response++;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (bad++ > 10) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco err("\nTest aborted after 10 failures\n\n");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco start_connect(c);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* have full header */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (!good) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /*
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * this is first time, extract some interesting info
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco char *p, *q;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco p = strstr(c->cbuff, "Server:");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco q = servername;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (p) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco p += 8;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco while (*p > 32)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco *q++ = *p++;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco *q = 0;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /*
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * XXX: this parsing isn't even remotely HTTP compliant... but in
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * the interest of speed it doesn't totally have to be, it just
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * needs to be extended to handle whatever servers folks want to
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * test against. -djg
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* check response code */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco part = strstr(c->cbuff, "HTTP"); /* really HTTP/1.x_ */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco strncpy(respcode, (part + strlen("HTTP/1.x_")), 3);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco respcode[3] = '\0';
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (respcode[0] != '2') {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco err_response++;
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco if (verbosity >= 2)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("WARNING: Response code not 2xx (%s)\n", respcode);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco }
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else if (verbosity >= 3) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("LOG: Response code = %s\n", respcode);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco }
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco c->gotheader = 1;
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco *s = 0; /* terminate at end of header */
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco if (keepalive &&
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco (strstr(c->cbuff, "Keep-Alive")
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco || strstr(c->cbuff, "keep-alive"))) { /* for benefit of MSIIS */
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco char *cl;
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco cl = strstr(c->cbuff, "Content-Length:");
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco /* handle NCSA, which sends Content-length: */
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco if (!cl)
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco cl = strstr(c->cbuff, "Content-length:");
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco if (cl) {
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco c->keepalive = 1;
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco c->length = atoi(cl + 16);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco }
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco }
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco c->bread += c->cbx - (s + l - c->cbuff) + r - tocopy;
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco totalbread += c->bread;
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco }
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco }
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco else {
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco /* outside header, everything we have read is entity body */
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco c->bread += r;
6e121321775373fe11161d23c541437456df19b4Adrián Riesco totalbread += r;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco }
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco if (c->keepalive && (c->bread >= c->length)) {
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco /* finished a keep-alive connection */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco good++;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco doneka++;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco /* save out time */
ebdb7b09e2ad2bb780d84c127d72c30dfcfb87b2Adrián Riesco if (good == 1) {
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco /* first time here */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco doclen = c->bread;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco }
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco else if (c->bread != doclen) {
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco bad++;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco err_length++;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco }
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco if (done < requests) {
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco struct data s;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco if (done && heartbeatres && !(done % heartbeatres)) {
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco fprintf(stderr, "Completed %ld requests\n", done);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco fflush(stderr);
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco }
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco c->done = apr_time_now();
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco s.read = c->read;
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco s.starttime = c->start;
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco s.ctime = (c->connect - c->start) / 1000;
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco s.waittime = (c->beginread - c->endwrite) / 1000;
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco s.time = (c->done - c->start) / 1000;
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco stats[done++] = s;
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco }
b3a8ae62887130fd41b91bf2ea1fd66360bd3c29Adrián Riesco c->keepalive = 0;
b3a8ae62887130fd41b91bf2ea1fd66360bd3c29Adrián Riesco c->length = 0;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco c->gotheader = 0;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco c->cbx = 0;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco c->read = c->bread = 0;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco write_request(c);
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco c->start = c->connect; /* zero connect time with keep-alive */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco }
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco}
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco/* --------------------------------------------------------- */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco/* run the tests */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riescostatic void test(void)
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco{
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco apr_time_t now;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco apr_int16_t rv;
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco long i;
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco apr_status_t status;
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco#ifdef NOT_ASCII
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco apr_size_t inbytes_left, outbytes_left;
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco#endif
8b389272b3312c6d3e3c0aee2e94bca6dbdade50Adrián Riesco
205d9bc0182b3e68e480c44806565362df2fcdcaAdrián Riesco if (isproxy) {
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco strcpy(connecthost, proxyhost);
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco connectport = proxyport;
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco }
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco else {
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco strcpy(connecthost, hostname);
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco connectport = port;
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco }
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco if (!use_html) {
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco printf("Benchmarking %s ", hostname);
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco if (isproxy)
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco printf("[through %s:%d] ", proxyhost, proxyport);
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco printf("(be patient)%s",
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco (heartbeatres ? "\n" : "..."));
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco fflush(stdout);
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco }
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco now = apr_time_now();
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco con = malloc(concurrency * sizeof(struct connection));
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco memset(con, 0, concurrency * sizeof(struct connection));
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco stats = malloc(requests * sizeof(struct data));
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco apr_poll_setup(&readbits, concurrency, cntxt);
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco /* setup request */
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco if (!posting) {
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco sprintf(request, "%s %s HTTP/1.0\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "User-Agent: ApacheBench/%s\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "%s" "%s" "%s"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "Host: %s\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "Accept: */*\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "%s" "\r\n",
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco (posting == 0) ? "GET" : "HEAD",
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco (isproxy) ? fullurl : path,
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco AB_VERSION,
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco keepalive ? "Connection: Keep-Alive\r\n" : "",
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco cookie, auth, host_field, hdrs);
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco }
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco else {
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco sprintf(request, "POST %s HTTP/1.0\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "User-Agent: ApacheBench/%s\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "%s" "%s" "%s"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "Host: %s\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "Accept: */*\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "Content-length: %" APR_SIZE_T_FMT "\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "Content-type: %s\r\n"
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco "%s"
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco "\r\n",
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco (isproxy) ? fullurl : path,
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco AB_VERSION,
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco keepalive ? "Connection: Keep-Alive\r\n" : "",
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco cookie, auth,
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco host_field, postlen,
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco (content_type[0]) ? content_type : "text/plain", hdrs);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco }
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco if (verbosity >= 2)
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco printf("INFO: POST header == \n---\n%s\n---\n", request);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco reqlen = strlen(request);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco /*
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco * Combine headers and (optional) post file into one contineous buffer
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco */
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco if (posting) {
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco char *buff = (char *) malloc(postlen + reqlen + 1);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco strcpy(buff, request);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco strcpy(buff + reqlen, postdata);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco request = buff;
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco }
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco#ifdef NOT_ASCII
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco inbytes_left = outbytes_left = reqlen;
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco status = apr_xlate_conv_buffer(to_ascii, request, &inbytes_left,
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco request, &outbytes_left);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco if (status || inbytes_left || outbytes_left) {
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco fprintf(stderr, "only simple translation is supported (%d/%u/%u)\n",
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco status, inbytes_left, outbytes_left);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco exit(1);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco }
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco#endif /* NOT_ASCII */
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco /* ok - lets start */
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco start = apr_time_now();
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco /* initialise lots of requests */
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco for (i = 0; i < concurrency; i++) {
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco con[i].socknum = i;
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco start_connect(&con[i]);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco }
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco while (done < requests) {
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco apr_int32_t n;
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco apr_int32_t timed;
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco /* check for time limit expiry */
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco now = apr_time_now();
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco 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 (heartbeatres)
fprintf(stderr, "Finished %ld requests\n", done);
else
printf("..done\n");
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.72 $> 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.72 $");
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"
#if USE_SSL
"[s]"
#endif
"://]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 containing 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, " -X proxy:port Proxyserver and port number to use\n");
fprintf(stderr, " -V Print version number and exit\n");
fprintf(stderr, " -k Use HTTP KeepAlive feature\n");
fprintf(stderr, " -d Do not show percentiles served table.\n");
fprintf(stderr, " -S Do not show confidence estimators and warnings.\n");
fprintf(stderr, " -g filename Output collected data to gnuplot format file.\n");
fprintf(stderr, " -e filename Output CSV file with percentages served\n");
#if USE_SSL
fprintf(stderr, " -s Use httpS instead of HTTP (SSL)\n");
#endif
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;
else
#if USE_SSL
if (strlen(url) > 8 && strncmp(url, "https://", 8) == 0) {
url += 8;
ssl = 1;
port = 443;
}
#else
if (strlen(url) > 8 && strncmp(url, "https://", 8) == 0) {
fprintf(stderr, "SSL not compiled in; no https support\n");
exit(1);
}
#endif
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;
}
/* ------------------------------------------------------- */
/* 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';
proxyhost[0] = '\0';
hdrs[0] = '\0';
apr_initialize();
atexit(apr_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:g:X:de:Sq"
#if USE_SSL
"s"
#endif
,&c, &optarg)) == APR_SUCCESS) {
switch (c) {
#if USE_SSL
case 's':
ssl = 1;
break;
#endif
case 'n':
requests = atoi(optarg);
if (!requests) {
err("Invalid number of requests\n");
}
break;
case 'k':
keepalive = 1;
break;
case 'q':
heartbeatres = 0;
break;
case 'c':
concurrency = atoi(optarg);
break;
case 'i':
if (posting == 1)
err("Cannot mix POST and HEAD\n");
posting = -1;
break;
case 'g':
gnuplot = strdup(optarg);
break;
case 'd':
percentile = 0;
break;
case 'e':
csvperc = strdup(optarg);
break;
case 'S':
confidence = 0;
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 'X':
{
char *p;
/*
* assume proxy-name[:port]
*/
if ((p = strchr(optarg, ':'))) {
*p = '\0';
p++;
proxyport = atoi(p);
};
strcpy(proxyhost, optarg);
isproxy = 1;
}
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]);
}
if ((heartbeatres) && (requests > 150)) {
heartbeatres = requests / 10; /* Print line every 10% of requests */
if (heartbeatres < 100)
heartbeatres = 100; /* but never more often than once every 100
* connections. */
}
else
heartbeatres = 0;
#ifdef USE_SSL
SSL_library_init();
if (!(ctx = SSL_CTX_new(SSLv2_client_method()))) {
fprintf(stderr, "Could not init SSL CTX");
ERR_print_errors_fp(stderr);
exit(1);
}
#endif
#if SIGPIPE
signal(SIGPIPE, SIG_IGN); /* Ignore writes to connections that
* have been closed at the other end. */
#endif
copyright();
test();
return 0;
}