ab.c revision 23b4e2f556ce39696c4e31c6e72893f7489ff8d9
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* ====================================================================
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * The Apache Software License, Version 1.1
bc8fd1b0b1afdf89b8d28eefa8cd74e26ba97986fielding * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * reserved.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Redistribution and use in source and binary forms, with or without
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * modification, are permitted provided that the following conditions
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 1. Redistributions of source code must retain the above copyright
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * notice, this list of conditions and the following disclaimer.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 2. Redistributions in binary form must reproduce the above copyright
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * notice, this list of conditions and the following disclaimer in
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the documentation and/or other materials provided with the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * distribution.
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * 3. The end-user documentation included with the redistribution,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * if any, must include the following acknowledgment:
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * "This product includes software developed by the
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * Apache Software Foundation (http://www.apache.org/)."
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * Alternately, this acknowledgment may appear in the software itself,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * if and wherever such third-party acknowledgments normally appear.
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * 4. The names "Apache" and "Apache Software Foundation" must
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * not be used to endorse or promote products derived from this
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * software without prior written permission. For written
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * permission, please contact apache@apache.org.
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * 5. Products derived from this software may not be called "Apache",
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * nor may "Apache" appear in their name, without prior written
64185f9824e42f21ca7b9ae6c004484215c031a7rbb * permission of the Apache Software Foundation.
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * SUCH DAMAGE.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ====================================================================
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * This software consists of voluntary contributions made by many
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * individuals on behalf of the Apache Software Foundation. For more
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * information on the Apache Software Foundation, please see
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * Portions of this software are based upon public domain software
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * originally written at the National Center for Supercomputing Applications,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * University of Illinois, Urbana-Champaign.
3568de757bac0b47256647504c186d17ca272f85rbb ** This program is based on ZeusBench V1.0 written by Adam Twiss
3568de757bac0b47256647504c186d17ca272f85rbb ** which is Copyright (c) 1996 by Zeus Technology Ltd. http://www.zeustech.net/
3568de757bac0b47256647504c186d17ca272f85rbb ** This software is provided "as is" and any express or implied waranties,
3568de757bac0b47256647504c186d17ca272f85rbb ** including but not limited to, the implied warranties of merchantability and
3568de757bac0b47256647504c186d17ca272f85rbb ** fitness for a particular purpose are disclaimed. In no event shall
3568de757bac0b47256647504c186d17ca272f85rbb ** Zeus Technology Ltd. be liable for any direct, indirect, incidental, special,
3568de757bac0b47256647504c186d17ca272f85rbb ** exemplary, or consequential damaged (including, but not limited to,
3568de757bac0b47256647504c186d17ca272f85rbb ** procurement of substitute good or services; loss of use, data, or profits;
3568de757bac0b47256647504c186d17ca272f85rbb ** or business interruption) however caused and on theory of liability. Whether
3568de757bac0b47256647504c186d17ca272f85rbb ** in contract, strict liability or tort (including negligence or otherwise)
3568de757bac0b47256647504c186d17ca272f85rbb ** arising in any way out of the use of this software, even if advised of the
3568de757bac0b47256647504c186d17ca272f85rbb ** possibility of such damage.
3568de757bac0b47256647504c186d17ca272f85rbb ** HISTORY:
3568de757bac0b47256647504c186d17ca272f85rbb ** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996
3568de757bac0b47256647504c186d17ca272f85rbb ** with input from Mike Belshe <mbelshe@netscape.com> and
3568de757bac0b47256647504c186d17ca272f85rbb ** Michael Campanella <campanella@stevms.enet.dec.com>
3568de757bac0b47256647504c186d17ca272f85rbb ** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997
3568de757bac0b47256647504c186d17ca272f85rbb ** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998
3568de757bac0b47256647504c186d17ca272f85rbb ** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998
3568de757bac0b47256647504c186d17ca272f85rbb ** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999
3568de757bac0b47256647504c186d17ca272f85rbb ** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 1999
3568de757bac0b47256647504c186d17ca272f85rbb * - has various other poor buffer attacks related to the lazy parsing of
3568de757bac0b47256647504c186d17ca272f85rbb * response headers from the server
3568de757bac0b47256647504c186d17ca272f85rbb * - doesn't implement much of HTTP/1.x, only accepts certain forms of
3568de757bac0b47256647504c186d17ca272f85rbb * responses
3568de757bac0b47256647504c186d17ca272f85rbb * - (performance problem) heavy use of strstr shows up top in profile
3568de757bac0b47256647504c186d17ca272f85rbb * only an issue for loopback usage
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* -------------------------------------------------------------------- */
3568de757bac0b47256647504c186d17ca272f85rbb/* Hmmm... This source code isn't being compiled in ASCII.
3568de757bac0b47256647504c186d17ca272f85rbb * In order for data that flows over the network to make
3568de757bac0b47256647504c186d17ca272f85rbb * sense, we need to translate to/from ASCII.
333eac96e4fb7d6901cb75e6ca7bb22b2ccb84cetrawick/* affects include files on Solaris */
3568de757bac0b47256647504c186d17ca272f85rbb/* ------------------- DEFINITIONS -------------------------- */
3568de757bac0b47256647504c186d17ca272f85rbb/* maximum number of requests on a time limited test */
3568de757bac0b47256647504c186d17ca272f85rbb/* good old state hostname */
41634f717c623556a16b27b25d7d909a66fe20f8wrowe int length; /* Content-Length value used for keep-alive */
3568de757bac0b47256647504c186d17ca272f85rbb char cbuff[CBUFFSIZE]; /* a buffer to store server response header */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz int keepalive; /* non-zero if a keep-alive request */
3568de757bac0b47256647504c186d17ca272f85rbb int gotheader; /* non-zero if we have the entire header in
3568de757bac0b47256647504c186d17ca272f85rbb#define ap_min(a,b) ((a)<(b))?(a):(b)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#define ap_max(a,b) ((a)>(b))?(a):(b)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* --------------------- GLOBALS ---------------------------- */
fc1efab92032301e317f07e1b3a00082d9d71f3frbbint concurrency = 1; /* Number of multiple requests to make */
24b534291150023e6b68eca89ddd33e475ccddc0wroweint keepalive = 0; /* try and do keepalive connections */
24b534291150023e6b68eca89ddd33e475ccddc0wrowechar postfile[1024]; /* name of file containing post data */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzchar *postdata; /* *buffer containing data from postfile */
3568de757bac0b47256647504c186d17ca272f85rbbapr_size_t postlen = 0; /* length of data to be POSTed */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzchar content_type[1024]; /* content type to put in POST header */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * authentification */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzapr_time_t aprtimeout = 30 * APR_USEC_PER_SEC; /* timeout value */
3568de757bac0b47256647504c186d17ca272f85rbbconst char *trstring;
3568de757bac0b47256647504c186d17ca272f85rbbconst char *tdstring;
3568de757bac0b47256647504c186d17ca272f85rbbint totalbread = 0; /* totoal amount of entity body read */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzint totalposted = 0; /* total number of bytes posted, inc. headers */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzint done = 0; /* number of requests we have done */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzint doneka = 0; /* number of keep alive connections done */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzint started = 0; /* number of requests started, so no excess */
3568de757bac0b47256647504c186d17ca272f85rbbint good = 0, bad = 0; /* number of good and bad requests */
3568de757bac0b47256647504c186d17ca272f85rbb/* store error cases */
3568de757bac0b47256647504c186d17ca272f85rbb/* global request (and its length) */
3568de757bac0b47256647504c186d17ca272f85rbb/* one global throw-away buffer to read stuff into */
3568de757bac0b47256647504c186d17ca272f85rbb/* --------------------------------------------------------- */
41634f717c623556a16b27b25d7d909a66fe20f8wrowe/* simple little function to write an error string and exit */
3568de757bac0b47256647504c186d17ca272f85rbbstatic void err(char *s)
3568de757bac0b47256647504c186d17ca272f85rbb/* simple little function to write an APR error string and exit */
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick "%s: %s (%d)\n",
ca53a74f4012a45cbad48e940eddf27d866981f9dougm/* --------------------------------------------------------- */
ca53a74f4012a45cbad48e940eddf27d866981f9dougm/* write out request to a connection - assumes we can write
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick (small) request out in one go into our new socket buffer */
3568de757bac0b47256647504c186d17ca272f85rbb apr_setsocketopt(c->aprsock, APR_SO_TIMEOUT, aprtimeout);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (apr_send(c->aprsock, request, &len) != APR_SUCCESS ||
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (apr_send(c->aprsock, postdata, &len) != APR_SUCCESS ||
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard apr_poll_socket_add(readbits, c->aprsock, APR_POLLIN);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/* --------------------------------------------------------- */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/* calculate and output results */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddardstatic void output_results(void)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf(" (Connect: %d, Length: %d, Exceptions: %d)\n",
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /* avoid divide by zero */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Requests per second: %.2f\n", 1000 * (float) (done) / timetaken);
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames /* work out connection times */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard for (i = 0; i < requests; i++) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (requests > 0) { /* avoid division by zero (if 0 requests) */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Connect: %5d %5d %5d\n", mincon, totalcon / requests, maxcon);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard mintot - mincon, (total / requests) - (totalcon / requests),
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("Total: %5d %5d %5d\n", mintot, total / requests, maxtot);
3568de757bac0b47256647504c186d17ca272f85rbb/* --------------------------------------------------------- */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* calculate and output results in HTML */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzstatic void output_html_results(void)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Server Software:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%s</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Server Hostname:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%s</td></tr>\n",
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("<tr %s><th colspan=2 %s>Server Port:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%hd</td></tr>\n",
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("<tr %s><th colspan=2 %s>Document Path:</th>"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz "<td colspan=2 %s>%s</td></tr>\n",
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("<tr %s><th colspan=2 %s>Document Length:</th>"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz "<td colspan=2 %s>%d bytes</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Concurrency Level:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%d</td></tr>\n",
3568de757bac0b47256647504c186d17ca272f85rbb printf("<tr %s><th colspan=2 %s>Time taken for tests:</th>"
3568de757bac0b47256647504c186d17ca272f85rbb "<td colspan=2 %s>%d.%03d seconds</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, timetaken / 1000, timetaken % 1000);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("<tr %s><th colspan=2 %s>Complete requests:</th>"
f714f1a7002928d785e53e70349700a7f595fee3trawick "<td colspan=2 %s>%d</td></tr>\n",
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard "<td colspan=2 %s>%d</td></tr>\n",
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("<tr %s><td colspan=4 %s > (Connect: %d, Length: %d, Exceptions: %d)</td></tr>\n",
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz trstring, tdstring, err_conn, err_length, err_except);
3568de757bac0b47256647504c186d17ca272f85rbb printf("<tr %s><th colspan=2 %s>Non-2xx responses:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%d</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Keep-Alive requests:</th>"
3568de757bac0b47256647504c186d17ca272f85rbb "<td colspan=2 %s>%d</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Total transferred:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%d bytes</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Total POSTed:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%d</td></tr>\n",
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz printf("<tr %s><th colspan=2 %s>HTML transferred:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%d bytes</td></tr>\n",
3568de757bac0b47256647504c186d17ca272f85rbb /* avoid divide by zero */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard printf("<tr %s><th colspan=2 %s>Requests per second:</th>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%.2f</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, 1000 * (float) (done) / timetaken);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td colspan=2 %s>%.2f kb/s received</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, (float) (totalread) / timetaken);
3568de757bac0b47256647504c186d17ca272f85rbb "<td colspan=2 %s>%.2f kb/s sent</td></tr>\n",
3568de757bac0b47256647504c186d17ca272f85rbb "<td colspan=2 %s>%.2f kb/s total</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /* work out connection times */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard for (i = 0; i < requests; i++) {
3568de757bac0b47256647504c186d17ca272f85rbb if (requests > 0) { /* avoid division by zero (if 0 requests) */
3568de757bac0b47256647504c186d17ca272f85rbb printf("<tr %s><th %s colspan=4>Connnection Times (ms)</th></tr>\n",
3568de757bac0b47256647504c186d17ca272f85rbb printf("<tr %s><th %s> </th> <th %s>min</th> <th %s>avg</th> <th %s>max</th></tr>\n",
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick "<td %s>%5d</td>"
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick "<td %s>%5d</td>"
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick "<td %s>%5d</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, mincon, tdstring, totalcon / requests, tdstring, maxcon);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz "<td %s>%5d</td>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td %s>%5d</td>"
beb70d51e435dc36c56a72b6cd83556c04db9283wrowe "<td %s>%5d</td></tr>\n",
fe6baec9bbcd36f932b71a355120cd7b5a685d6cfielding trstring, tdstring, tdstring, mintot - mincon, tdstring,
3568de757bac0b47256647504c186d17ca272f85rbb (total / requests) - (totalcon / requests), tdstring, maxtot - maxcon);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td %s>%5d</td>"
3568de757bac0b47256647504c186d17ca272f85rbb "<td %s>%5d</td>"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "<td %s>%5d</td></tr>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trstring, tdstring, tdstring, mintot, tdstring, total / requests, tdstring, maxtot);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/* --------------------------------------------------------- */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/* start asnchronous non-blocking connection */
0f113d7123e8bd3e3e2e9b6373461a1a773bfccatrawick if ((rv = apr_sockaddr_info_get(&destsa, hostname, APR_UNSPEC, port, 0, cntxt))
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if ((rv = apr_socket_create(&c->aprsock, destsa->sa.sin.sin_family,
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if ((rv = apr_connect(c->aprsock, destsa)) != APR_SUCCESS) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick "\nTest aborted after 10 failures\n\n");
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /* connected first time */
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick/* --------------------------------------------------------- */
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick/* close down connection and save stats */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz /* server has legitimately shut down an idle keep alive request */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz /* first time here */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz /* save out time */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /* connect again */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/* --------------------------------------------------------- */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/* read data from connection */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick r = sizeof(buffer);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_setsocketopt(c->aprsock, APR_SO_TIMEOUT, aprtimeout);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (r == 0 || (status != APR_SUCCESS && !APR_STATUS_IS_EAGAIN(status))) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick int space = CBUFFSIZE - c->cbx - 1; /* -1 to allow for 0
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * terminator */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_size_t inbytes_left = space, outbytes_left = space;
f886987cd0bd4220c14043c4d9be77ec22902e73trawick status = apr_xlate_conv_buffer(from_ascii, buffer, &inbytes_left,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick fprintf(stderr, "only simple translation is supported (%d/%u/%u)\n",
3568de757bac0b47256647504c186d17ca272f85rbb#endif /* NOT_ASCII */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick c->cbuff[c->cbx] = 0; /* terminate for benefit of strstr */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * this next line is so that we talk to NCSA 1.5 which blatantly
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * breaks the http specifaction
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /* read rest next time */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* header is in invalid or too big - close connection */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* have full header */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* this is first time, extract some interesting info */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick char *p, *q;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick while (*p > 32)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick *q++ = *p++;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * XXX: this parsing isn't even remotely HTTP compliant... but in
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * the interest of speed it doesn't totally have to be, it just
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * needs to be extended to handle whatever servers folks want to
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * test against. -djg
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* check response code */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick part = strstr(c->cbuff, "HTTP"); /* really HTTP/1.x_ */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick printf("WARNING: Response code not 2xx (%s)\n", respcode);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick *s = 0; /* terminate at end of header */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick || strstr(c->cbuff, "keep-alive"))) { /* for benefit of MSIIS */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* handle NCSA, which sends Content-length: */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* outside header, everything we have read is entity body */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /* finished a keep-alive connection */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* save out time */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* first time here */
f886987cd0bd4220c14043c4d9be77ec22902e73trawick c->start = c->connect; /* zero connect time with keep-alive */
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe/* --------------------------------------------------------- */
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe/* run the tests */
3568de757bac0b47256647504c186d17ca272f85rbbstatic void test(void)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding con = malloc(concurrency * sizeof(struct connection));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memset(con, 0, concurrency * sizeof(struct connection));
3568de757bac0b47256647504c186d17ca272f85rbb /* setup request */
3568de757bac0b47256647504c186d17ca272f85rbb "User-Agent: ApacheBench/%s\r\n"
3568de757bac0b47256647504c186d17ca272f85rbb "%s" "%s" "%s"
3568de757bac0b47256647504c186d17ca272f85rbb "Host: %s\r\n"
3568de757bac0b47256647504c186d17ca272f85rbb "Accept: */*\r\n"
3568de757bac0b47256647504c186d17ca272f85rbb "%s" "\r\n",
3568de757bac0b47256647504c186d17ca272f85rbb "User-Agent: ApacheBench/%s\r\n"
73e8b26287de5c06fa470d36162e103dbac9c7e5wrowe "%s" "%s" "%s"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Host: %s\r\n"
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe "Accept: */*\r\n"
ca53a74f4012a45cbad48e940eddf27d866981f9dougm "Content-type: %s\r\n"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz (content_type[0]) ? content_type : "text/plain", hdrs);
3568de757bac0b47256647504c186d17ca272f85rbb printf("INFO: POST header == \n---\n%s\n---\n", request);
#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.58 $");
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();