ab.c revision 0906f649b3d720299e47ed1148e79051e8941b2a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ====================================================================
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The Apache Software License, Version 1.1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Redistribution and use in source and binary forms, with or without
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * modification, are permitted provided that the following conditions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1. Redistributions of source code must retain the above copyright
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * notice, this list of conditions and the following disclaimer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 2. Redistributions in binary form must reproduce the above copyright
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * notice, this list of conditions and the following disclaimer in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the documentation and/or other materials provided with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * distribution.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 3. The end-user documentation included with the redistribution,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if any, must include the following acknowledgment:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "This product includes software developed by the
cd3e933325e68e23516a196a8fea7f49b1e497c3Ali Bahrami * Apache Software Foundation (http://www.apache.org/)."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Alternately, this acknowledgment may appear in the software itself,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if and wherever such third-party acknowledgments normally appear.
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * 4. The names "Apache" and "Apache Software Foundation" must
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * not be used to endorse or promote products derived from this
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * software without prior written permission. For written
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * permission, please contact apache@apache.org.
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * 5. Products derived from this software may not be called "Apache",
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * nor may "Apache" appear in their name, without prior written
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * permission of the Apache Software Foundation.
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
cd3e933325e68e23516a196a8fea7f49b1e497c3Ali Bahrami * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
cd3e933325e68e23516a196a8fea7f49b1e497c3Ali Bahrami * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
cd3e933325e68e23516a196a8fea7f49b1e497c3Ali Bahrami * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SUCH DAMAGE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ====================================================================
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This software consists of voluntary contributions made by many
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * individuals on behalf of the Apache Software Foundation. For more
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information on the Apache Software Foundation, please see
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Portions of this software are based upon public domain software
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * originally written at the National Center for Supercomputing Applications,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * University of Illinois, Urbana-Champaign.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** This program is based on ZeusBench V1.0 written by Adam Twiss
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** which is Copyright (c) 1996 by Zeus Technology Ltd. http://www.zeustech.net/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** This software is provided "as is" and any express or implied waranties,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** including but not limited to, the implied warranties of merchantability and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** fitness for a particular purpose are disclaimed. In no event shall
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** Zeus Technology Ltd. be liable for any direct, indirect, incidental, special,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** exemplary, or consequential damaged (including, but not limited to,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** procurement of substitute good or services; loss of use, data, or profits;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** or business interruption) however caused and on theory of liability. Whether
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** in contract, strict liability or tort (including negligence or otherwise)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** arising in any way out of the use of this software, even if advised of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** possibility of such damage.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** with input from Mike Belshe <mbelshe@netscape.com> and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** Michael Campanella <campanella@stevms.enet.dec.com>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 1999
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - has various other poor buffer attacks related to the lazy parsing of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * response headers from the server
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - doesn't implement much of HTTP/1.x, only accepts certain forms of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - (performance problem) heavy use of strstr shows up top in profile
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * only an issue for loopback usage
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* -------------------------------------------------------------------- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Hmmm... This source code isn't being compiled in ASCII.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * In order for data that flows over the network to make
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sense, we need to translate to/from ASCII.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* affects include files on Solaris */
#include "apr_strings.h"
#include "apr_network_io.h"
#include "apr_file_io.h"
#include "apr_time.h"
#include "apr_getopt.h"
#include "apr_general.h"
#include "apr_lib.h"
#if APR_HAVE_STDIO_H
#include <stdlib.h>
#include "apr_base64.h"
#ifdef NOT_ASCII
#include "apr_xlate.h"
#include <string.h>
#if APR_HAVE_STDIO_H
#include <stdio.h>
#include <stdlib.h>
#if APR_HAVE_CTYPE_H
#include <ctype.h>
#define STATE_UNCONNECTED 0
struct connection {
int state;
int socknum;
struct data {
#define ap_min(a,b) ((a)<(b))?(a):(b)
#define ap_max(a,b) ((a)>(b))?(a):(b)
const char *tablestring;
const char *trstring;
const char *tdstring;
int err_response = 0;
#ifdef NOT_ASCII
static void err(char *s)
apr_status_t e;
if (c->rwrite == 0) {
c->rwrote = 0;
if (posting)
close_connection(c);
if (l == c->rwrite)
if (e != APR_SUCCESS) {
if (!APR_STATUS_IS_EAGAIN(e)) {
close_connection(c);
c->rwrote += l;
c->rwrite -= l;
if (posting)
static void output_results(void)
int timetaken;
if (bad)
if (err_response)
if (keepalive)
if (posting)
if (timetaken) {
if (posting > 0) {
for (i = 0; i < requests; i++) {
static void output_html_results(void)
int timetaken;
if (bad)
if (err_response)
if (keepalive)
if (posting > 0)
if (timetaken) {
if (posting > 0) {
for (i = 0; i < requests; i++) {
c->read = 0;
c->bread = 0;
c->keepalive = 0;
c->cbx = 0;
c->gotheader = 0;
c->rwrite = 0;
!= APR_SUCCESS) {
c->rwrite = 0;
err_conn++;
start_connect(c);
started++;
write_request(c);
if (good)
bad++;
err_length++;
struct data s;
start_connect(c);
apr_size_t r;
char *part;
r = sizeof(buffer);
good++;
close_connection(c);
c->read += r;
totalread += r;
if (!c->gotheader) {
#ifdef NOT_ASCII
if (space) {
err_response++;
start_connect(c);
if (!good) {
q = servername;
err_response++;
if (keepalive &&
char *cl;
if (!cl)
if (cl) {
c->bread += r;
totalbread += r;
good++;
doneka++;
bad++;
err_length++;
struct data s;
c->keepalive = 0;
c->length = 0;
c->gotheader = 0;
c->cbx = 0;
write_request(c);
static void test(void)
#ifdef NOT_ASCII
if (!use_html) {
if (!posting) {
path,
path,
if (posting) {
#ifdef NOT_ASCII
for (i = 0; i < concurrency; i++) {
apr_int32_t n;
n = concurrency;
for (i = 0; i < concurrency; i++) {
bad++;
err_except++;
if (use_html)
static void copyright(void)
if (!use_html) {
printf(" This is ApacheBench, Version %s <i><%s></i> apache-2.0<br>\n", AB_VERSION, "$Revision: 1.60 $");
char *cp;
char *scope_id;
return rv;
if (!postdata) {
return APR_ENOMEM;
return rv;
length);
return APR_EINVAL;
static void terminate(void)
const char *optarg;
#ifdef NOT_ASCII
if (status) {
if (status) {
if (status) {
if (!requests) {
if (posting != 0)
else if (postdata) {
exit(r);
optarg++;
optarg++;
copyright();
copyright();
test();