|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
** This program is based on ZeusBench V1.0 written by Adam Twiss
|
|
Packit |
90a5c9 |
** which is Copyright (c) 1996 by Zeus Technology Ltd. http://www.zeustech.net/
|
|
Packit |
90a5c9 |
**
|
|
Packit |
90a5c9 |
** This software is provided "as is" and any express or implied waranties,
|
|
Packit |
90a5c9 |
** including but not limited to, the implied warranties of merchantability and
|
|
Packit |
90a5c9 |
** fitness for a particular purpose are disclaimed. In no event shall
|
|
Packit |
90a5c9 |
** Zeus Technology Ltd. be liable for any direct, indirect, incidental, special,
|
|
Packit |
90a5c9 |
** exemplary, or consequential damaged (including, but not limited to,
|
|
Packit |
90a5c9 |
** procurement of substitute good or services; loss of use, data, or profits;
|
|
Packit |
90a5c9 |
** or business interruption) however caused and on theory of liability. Whether
|
|
Packit |
90a5c9 |
** in contract, strict liability or tort (including negligence or otherwise)
|
|
Packit |
90a5c9 |
** arising in any way out of the use of this software, even if advised of the
|
|
Packit |
90a5c9 |
** possibility of such damage.
|
|
Packit |
90a5c9 |
**
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
** HISTORY:
|
|
Packit |
90a5c9 |
** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996
|
|
Packit |
90a5c9 |
** with input from Mike Belshe <mbelshe@netscape.com> and
|
|
Packit |
90a5c9 |
** Michael Campanella <campanella@stevms.enet.dec.com>
|
|
Packit |
90a5c9 |
** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997
|
|
Packit |
90a5c9 |
** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998
|
|
Packit |
90a5c9 |
** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998
|
|
Packit |
90a5c9 |
** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999
|
|
Packit |
90a5c9 |
** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 1999
|
|
Packit |
90a5c9 |
** Version 1.3d
|
|
Packit |
90a5c9 |
** - Increased version number - as some of the socket/error handling has
|
|
Packit |
90a5c9 |
** fundamentally changed - and will give fundamentally different results
|
|
Packit |
90a5c9 |
** in situations where a server is dropping requests. Therefore you can
|
|
Packit |
90a5c9 |
** no longer compare results of AB as easily. Hence the inc of the version.
|
|
Packit |
90a5c9 |
** They should be closer to the truth though. Sander & <dirkx@covalent.net>, End 2000.
|
|
Packit |
90a5c9 |
** - Fixed proxy functionality, added median/mean statistics, added gnuplot
|
|
Packit |
90a5c9 |
** output option, added _experimental/rudimentary_ SSL support. Added
|
|
Packit |
90a5c9 |
** confidence guestimators and warnings. Sander & <dirkx@covalent.net>, End 2000
|
|
Packit |
90a5c9 |
** - Fixed serious int overflow issues which would cause realistic (longer
|
|
Packit |
90a5c9 |
** than a few minutes) run's to have wrong (but believable) results. Added
|
|
Packit |
90a5c9 |
** trapping of connection errors which influenced measurements.
|
|
Packit |
90a5c9 |
** Contributed by Sander Temme, Early 2001
|
|
Packit |
90a5c9 |
** Version 1.3e
|
|
Packit |
90a5c9 |
** - Changed timeout behavour during write to work whilst the sockets
|
|
Packit |
90a5c9 |
** are filling up and apr_write() does writes a few - but not all.
|
|
Packit |
90a5c9 |
** This will potentially change results. <dirkx@webweaving.org>, April 2001
|
|
Packit |
90a5c9 |
** Version 2.0.36-dev
|
|
Packit |
90a5c9 |
** Improvements to concurrent processing:
|
|
Packit |
90a5c9 |
** - Enabled non-blocking connect()s.
|
|
Packit |
90a5c9 |
** - Prevent blocking calls to apr_socket_recv() (thereby allowing AB to
|
|
Packit |
90a5c9 |
** manage its entire set of socket descriptors).
|
|
Packit |
90a5c9 |
** - Any error returned from apr_socket_recv() that is not EAGAIN or EOF
|
|
Packit |
90a5c9 |
** is now treated as fatal.
|
|
Packit |
90a5c9 |
** Contributed by Aaron Bannert, April 24, 2002
|
|
Packit |
90a5c9 |
**
|
|
Packit |
90a5c9 |
** Version 2.0.36-2
|
|
Packit |
90a5c9 |
** Internalized the version string - this string is part
|
|
Packit |
90a5c9 |
** of the Agent: header and the result output.
|
|
Packit |
90a5c9 |
**
|
|
Packit |
90a5c9 |
** Version 2.0.37-dev
|
|
Packit |
90a5c9 |
** Adopted SSL code by Madhu Mathihalli <madhusudan_mathihalli@hp.com>
|
|
Packit |
90a5c9 |
** [PATCH] ab with SSL support Posted Wed, 15 Aug 2001 20:55:06 GMT
|
|
Packit |
90a5c9 |
** Introduces four 'if (int == value)' tests per non-ssl request.
|
|
Packit |
90a5c9 |
**
|
|
Packit |
90a5c9 |
** Version 2.0.40-dev
|
|
Packit |
90a5c9 |
** Switched to the new abstract pollset API, allowing ab to
|
|
Packit |
90a5c9 |
** take advantage of future apr_pollset_t scalability improvements.
|
|
Packit |
90a5c9 |
** Contributed by Brian Pane, August 31, 2002
|
|
Packit |
90a5c9 |
**
|
|
Packit |
90a5c9 |
** Version 2.3
|
|
Packit |
90a5c9 |
** SIGINT now triggers output_results().
|
|
Packit |
90a5c9 |
** Contributed by colm, March 30, 2006
|
|
Packit |
90a5c9 |
**/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Note: this version string should start with \d+[\d\.]* and be a valid
|
|
Packit |
90a5c9 |
* string for an HTTP Agent: header when prefixed with 'ApacheBench/'.
|
|
Packit |
90a5c9 |
* It should reflect the version of AB - and not that of the apache server
|
|
Packit |
90a5c9 |
* it happens to accompany. And it should be updated or changed whenever
|
|
Packit |
90a5c9 |
* the results are no longer fundamentally comparable to the results of
|
|
Packit |
90a5c9 |
* a previous version of ab. Either due to a change in the logic of
|
|
Packit |
90a5c9 |
* ab - or to due to a change in the distribution it is compiled with
|
|
Packit |
90a5c9 |
* (such as an APR change in for example blocking).
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define AP_AB_BASEREVISION "2.3"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* BUGS:
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* - uses strcpy/etc.
|
|
Packit |
90a5c9 |
* - has various other poor buffer attacks related to the lazy parsing of
|
|
Packit |
90a5c9 |
* response headers from the server
|
|
Packit |
90a5c9 |
* - doesn't implement much of HTTP/1.x, only accepts certain forms of
|
|
Packit |
90a5c9 |
* responses
|
|
Packit |
90a5c9 |
* - (performance problem) heavy use of strstr shows up top in profile
|
|
Packit |
90a5c9 |
* only an issue for loopback usage
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* -------------------------------------------------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if 'A' != 0x41
|
|
Packit |
90a5c9 |
/* Hmmm... This source code isn't being compiled in ASCII.
|
|
Packit |
90a5c9 |
* In order for data that flows over the network to make
|
|
Packit |
90a5c9 |
* sense, we need to translate to/from ASCII.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define NOT_ASCII
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* affects include files on Solaris */
|
|
Packit |
90a5c9 |
#define BSD_COMP
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "apr.h"
|
|
Packit |
90a5c9 |
#include "apr_signal.h"
|
|
Packit |
90a5c9 |
#include "apr_strings.h"
|
|
Packit |
90a5c9 |
#include "apr_network_io.h"
|
|
Packit |
90a5c9 |
#include "apr_file_io.h"
|
|
Packit |
90a5c9 |
#include "apr_time.h"
|
|
Packit |
90a5c9 |
#include "apr_getopt.h"
|
|
Packit |
90a5c9 |
#include "apr_general.h"
|
|
Packit |
90a5c9 |
#include "apr_lib.h"
|
|
Packit |
90a5c9 |
#include "apr_portable.h"
|
|
Packit |
90a5c9 |
#include "ap_release.h"
|
|
Packit |
90a5c9 |
#include "apr_poll.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define APR_WANT_STRFUNC
|
|
Packit |
90a5c9 |
#include "apr_want.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "apr_base64.h"
|
|
Packit |
90a5c9 |
#ifdef NOT_ASCII
|
|
Packit |
90a5c9 |
#include "apr_xlate.h"
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#if APR_HAVE_STDIO_H
|
|
Packit |
90a5c9 |
#include <stdio.h>
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#if APR_HAVE_STDLIB_H
|
|
Packit |
90a5c9 |
#include <stdlib.h>
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#if APR_HAVE_UNISTD_H
|
|
Packit |
90a5c9 |
#include <unistd.h> /* for getpid() */
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if !defined(WIN32) && !defined(NETWARE)
|
|
Packit |
90a5c9 |
#include "ap_config_auto.h"
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if defined(HAVE_OPENSSL)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <openssl/rsa.h>
|
|
Packit |
90a5c9 |
#include <openssl/crypto.h>
|
|
Packit |
90a5c9 |
#include <openssl/x509.h>
|
|
Packit |
90a5c9 |
#include <openssl/pem.h>
|
|
Packit |
90a5c9 |
#include <openssl/err.h>
|
|
Packit |
90a5c9 |
#include <openssl/ssl.h>
|
|
Packit |
90a5c9 |
#include <openssl/rand.h>
|
|
Packit |
90a5c9 |
#define USE_SSL
|
|
Packit |
90a5c9 |
#define SK_NUM(x) sk_X509_num(x)
|
|
Packit |
90a5c9 |
#define SK_VALUE(x,y) sk_X509_value(x,y)
|
|
Packit |
90a5c9 |
typedef STACK_OF(X509) X509_STACK_TYPE;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if defined(_MSC_VER) && !defined(LIBRESSL_VERSION_NUMBER)
|
|
Packit |
90a5c9 |
/* The following logic ensures we correctly glue FILE* within one CRT used
|
|
Packit |
90a5c9 |
* by the OpenSSL library build to another CRT used by the ab.exe build.
|
|
Packit |
90a5c9 |
* This became especially problematic with Visual Studio 2015.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#include <openssl/applink.c>
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if defined(USE_SSL)
|
|
Packit |
90a5c9 |
#if (OPENSSL_VERSION_NUMBER >= 0x00909000)
|
|
Packit |
90a5c9 |
#define AB_SSL_METHOD_CONST const
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
#define AB_SSL_METHOD_CONST
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#if (OPENSSL_VERSION_NUMBER >= 0x0090707f)
|
|
Packit |
90a5c9 |
#define AB_SSL_CIPHER_CONST const
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
#define AB_SSL_CIPHER_CONST
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#ifdef SSL_OP_NO_TLSv1_2
|
|
Packit |
90a5c9 |
#define HAVE_TLSV1_X
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#if !defined(OPENSSL_NO_TLSEXT) && defined(SSL_set_tlsext_host_name)
|
|
Packit |
90a5c9 |
#define HAVE_TLSEXT
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2060000f
|
|
Packit |
90a5c9 |
#define SSL_CTRL_SET_MIN_PROTO_VERSION 123
|
|
Packit |
90a5c9 |
#define SSL_CTRL_SET_MAX_PROTO_VERSION 124
|
|
Packit |
90a5c9 |
#define SSL_CTX_set_min_proto_version(ctx, version) \
|
|
Packit |
90a5c9 |
SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL)
|
|
Packit |
90a5c9 |
#define SSL_CTX_set_max_proto_version(ctx, version) \
|
|
Packit |
90a5c9 |
SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL)
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <math.h>
|
|
Packit |
90a5c9 |
#if APR_HAVE_CTYPE_H
|
|
Packit |
90a5c9 |
#include <ctype.h>
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#if APR_HAVE_LIMITS_H
|
|
Packit |
90a5c9 |
#include <limits.h>
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* ------------------- DEFINITIONS -------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef LLONG_MAX
|
|
Packit |
90a5c9 |
#define AB_MAX APR_INT64_C(0x7fffffffffffffff)
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
#define AB_MAX LLONG_MAX
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* maximum number of requests on a time limited test */
|
|
Packit |
90a5c9 |
#define MAX_REQUESTS (INT_MAX > 50000 ? 50000 : INT_MAX)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* connection state
|
|
Packit |
90a5c9 |
* don't add enums or rearrange or otherwise change values without
|
|
Packit |
90a5c9 |
* visiting set_conn_state()
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
typedef enum {
|
|
Packit |
90a5c9 |
STATE_UNCONNECTED = 0,
|
|
Packit |
90a5c9 |
STATE_CONNECTING, /* TCP connect initiated, but we don't
|
|
Packit |
90a5c9 |
* know if it worked yet
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
STATE_CONNECTED, /* we know TCP connect completed */
|
|
Packit |
90a5c9 |
STATE_READ
|
|
Packit |
90a5c9 |
} connect_state_e;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define CBUFFSIZE (8192)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct connection {
|
|
Packit |
90a5c9 |
apr_pool_t *ctx;
|
|
Packit |
90a5c9 |
apr_socket_t *aprsock;
|
|
Packit |
90a5c9 |
apr_pollfd_t pollfd;
|
|
Packit |
90a5c9 |
int state;
|
|
Packit |
90a5c9 |
apr_size_t read; /* amount of bytes read */
|
|
Packit |
90a5c9 |
apr_size_t bread; /* amount of body read */
|
|
Packit |
90a5c9 |
apr_size_t rwrite, rwrote; /* keep pointers in what we write - across
|
|
Packit |
90a5c9 |
* EAGAINs */
|
|
Packit |
90a5c9 |
apr_size_t length; /* Content-Length value used for keep-alive */
|
|
Packit |
90a5c9 |
char cbuff[CBUFFSIZE]; /* a buffer to store server response header */
|
|
Packit |
90a5c9 |
int cbx; /* offset in cbuffer */
|
|
Packit |
90a5c9 |
int keepalive; /* non-zero if a keep-alive request */
|
|
Packit |
90a5c9 |
int gotheader; /* non-zero if we have the entire header in
|
|
Packit |
90a5c9 |
* cbuff */
|
|
Packit |
90a5c9 |
apr_time_t start, /* Start of connection */
|
|
Packit |
90a5c9 |
connect, /* Connected, start writing */
|
|
Packit |
90a5c9 |
endwrite, /* Request written */
|
|
Packit |
90a5c9 |
beginread, /* First byte of input */
|
|
Packit |
90a5c9 |
done; /* Connection closed */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
int socknum;
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
SSL *ssl;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct data {
|
|
Packit |
90a5c9 |
apr_time_t starttime; /* start time of connection */
|
|
Packit |
90a5c9 |
apr_interval_time_t waittime; /* between request and reading response */
|
|
Packit |
90a5c9 |
apr_interval_time_t ctime; /* time to connect */
|
|
Packit |
90a5c9 |
apr_interval_time_t time; /* time for connection */
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define ap_min(a,b) (((a)<(b))?(a):(b))
|
|
Packit |
90a5c9 |
#define ap_max(a,b) (((a)>(b))?(a):(b))
|
|
Packit |
90a5c9 |
#define ap_round_ms(a) ((apr_time_t)((a) + 500)/1000)
|
|
Packit |
90a5c9 |
#define ap_double_ms(a) ((double)(a)/1000.0)
|
|
Packit |
90a5c9 |
#define MAX_CONCURRENCY 20000
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* --------------------- GLOBALS ---------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
int verbosity = 0; /* no verbosity by default */
|
|
Packit |
90a5c9 |
int recverrok = 0; /* ok to proceed after socket receive errors */
|
|
Packit |
90a5c9 |
enum {NO_METH = 0, GET, HEAD, PUT, POST, CUSTOM_METHOD} method = NO_METH;
|
|
Packit |
90a5c9 |
const char *method_str[] = {"bug", "GET", "HEAD", "PUT", "POST", ""};
|
|
Packit |
90a5c9 |
int send_body = 0; /* non-zero if sending body with request */
|
|
Packit |
90a5c9 |
int requests = 1; /* Number of requests to make */
|
|
Packit |
90a5c9 |
int heartbeatres = 100; /* How often do we say we're alive */
|
|
Packit |
90a5c9 |
int concurrency = 1; /* Number of multiple requests to make */
|
|
Packit |
90a5c9 |
int percentile = 1; /* Show percentile served */
|
|
Packit |
90a5c9 |
int nolength = 0; /* Accept variable document length */
|
|
Packit |
90a5c9 |
int confidence = 1; /* Show confidence estimator and warnings */
|
|
Packit |
90a5c9 |
int tlimit = 0; /* time limit in secs */
|
|
Packit |
90a5c9 |
int keepalive = 0; /* try and do keepalive connections */
|
|
Packit |
90a5c9 |
int windowsize = 0; /* we use the OS default window size */
|
|
Packit |
90a5c9 |
char servername[1024]; /* name that server reports */
|
|
Packit |
90a5c9 |
char *hostname; /* host name from URL */
|
|
Packit |
90a5c9 |
const char *host_field; /* value of "Host:" header field */
|
|
Packit |
90a5c9 |
const char *path; /* path name */
|
|
Packit |
90a5c9 |
char *postdata; /* *buffer containing data from postfile */
|
|
Packit |
90a5c9 |
apr_size_t postlen = 0; /* length of data to be POSTed */
|
|
Packit |
90a5c9 |
char *content_type = NULL; /* content type to put in POST header */
|
|
Packit |
90a5c9 |
const char *cookie, /* optional cookie line */
|
|
Packit |
90a5c9 |
*auth, /* optional (basic/uuencoded) auhentication */
|
|
Packit |
90a5c9 |
*hdrs; /* optional arbitrary headers */
|
|
Packit |
90a5c9 |
apr_port_t port; /* port number */
|
|
Packit |
90a5c9 |
char *proxyhost = NULL; /* proxy host name */
|
|
Packit |
90a5c9 |
int proxyport = 0; /* proxy port */
|
|
Packit |
90a5c9 |
const char *connecthost;
|
|
Packit |
90a5c9 |
const char *myhost;
|
|
Packit |
90a5c9 |
apr_port_t connectport;
|
|
Packit |
90a5c9 |
const char *gnuplot; /* GNUplot file */
|
|
Packit |
90a5c9 |
const char *csvperc; /* CSV Percentile file */
|
|
Packit |
90a5c9 |
const char *fullurl;
|
|
Packit |
90a5c9 |
const char *colonhost;
|
|
Packit |
90a5c9 |
int isproxy = 0;
|
|
Packit |
90a5c9 |
apr_interval_time_t aprtimeout = apr_time_from_sec(30); /* timeout value */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* overrides for ab-generated common headers */
|
|
Packit |
90a5c9 |
const char *opt_host; /* which optional "Host:" header specified, if any */
|
|
Packit |
90a5c9 |
int opt_useragent = 0; /* was an optional "User-Agent:" header specified? */
|
|
Packit |
90a5c9 |
int opt_accept = 0; /* was an optional "Accept:" header specified? */
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* XXX - this is now a per read/write transact type of value
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
int use_html = 0; /* use html in the report */
|
|
Packit |
90a5c9 |
const char *tablestring;
|
|
Packit |
90a5c9 |
const char *trstring;
|
|
Packit |
90a5c9 |
const char *tdstring;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_size_t doclen = 0; /* the length the document should be */
|
|
Packit |
90a5c9 |
apr_int64_t totalread = 0; /* total number of bytes read */
|
|
Packit |
90a5c9 |
apr_int64_t totalbread = 0; /* totoal amount of entity body read */
|
|
Packit |
90a5c9 |
apr_int64_t totalposted = 0; /* total number of bytes posted, inc. headers */
|
|
Packit |
90a5c9 |
int started = 0; /* number of requests started, so no excess */
|
|
Packit |
90a5c9 |
int done = 0; /* number of requests we have done */
|
|
Packit |
90a5c9 |
int doneka = 0; /* number of keep alive connections done */
|
|
Packit |
90a5c9 |
int good = 0, bad = 0; /* number of good and bad requests */
|
|
Packit |
90a5c9 |
int epipe = 0; /* number of broken pipe writes */
|
|
Packit |
90a5c9 |
int err_length = 0; /* requests failed due to response length */
|
|
Packit |
90a5c9 |
int err_conn = 0; /* requests failed due to connection drop */
|
|
Packit |
90a5c9 |
int err_recv = 0; /* requests failed due to broken read */
|
|
Packit |
90a5c9 |
int err_except = 0; /* requests failed due to exception */
|
|
Packit |
90a5c9 |
int err_response = 0; /* requests with invalid or non-200 response */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
int is_ssl;
|
|
Packit |
90a5c9 |
SSL_CTX *ssl_ctx;
|
|
Packit |
90a5c9 |
char *ssl_cipher = NULL;
|
|
Packit |
90a5c9 |
char *ssl_info = NULL;
|
|
Packit |
90a5c9 |
char *ssl_cert = NULL;
|
|
Packit |
90a5c9 |
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
|
|
Packit |
90a5c9 |
char *ssl_tmp_key = NULL;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
BIO *bio_out,*bio_err;
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSEXT
|
|
Packit |
90a5c9 |
int tls_use_sni = 1; /* used by default, -I disables it */
|
|
Packit |
90a5c9 |
const char *tls_sni = NULL; /* 'opt_host' if any, 'hostname' otherwise */
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_time_t start, lasttime, stoptime;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* global request (and its length) */
|
|
Packit |
90a5c9 |
char _request[8192];
|
|
Packit |
90a5c9 |
char *request = _request;
|
|
Packit |
90a5c9 |
apr_size_t reqlen;
|
|
Packit |
90a5c9 |
int requests_initialized = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* one global throw-away buffer to read stuff into */
|
|
Packit |
90a5c9 |
char buffer[8192];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* interesting percentiles */
|
|
Packit |
90a5c9 |
int percs[] = {50, 66, 75, 80, 90, 95, 98, 99, 100};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct connection *con; /* connection array */
|
|
Packit |
90a5c9 |
struct data *stats; /* data for each request */
|
|
Packit |
90a5c9 |
apr_pool_t *cntxt;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_pollset_t *readbits;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_sockaddr_t *mysa;
|
|
Packit |
90a5c9 |
apr_sockaddr_t *destsa;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef NOT_ASCII
|
|
Packit |
90a5c9 |
apr_xlate_t *from_ascii, *to_ascii;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void write_request(struct connection * c);
|
|
Packit |
90a5c9 |
static void close_connection(struct connection * c);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* --------------------------------------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* simple little function to write an error string and exit */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void err(const char *s)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
fprintf(stderr, "%s\n", s);
|
|
Packit |
90a5c9 |
if (done)
|
|
Packit |
90a5c9 |
printf("Total of %d requests completed\n" , done);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* simple little function to write an APR error string and exit */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void apr_err(const char *s, apr_status_t rv)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char buf[120];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
fprintf(stderr,
|
|
Packit |
90a5c9 |
"%s: %s (%d)\n",
|
|
Packit |
90a5c9 |
s, apr_strerror(rv, buf, sizeof buf), rv);
|
|
Packit |
90a5c9 |
if (done)
|
|
Packit |
90a5c9 |
printf("Total of %d requests completed\n" , done);
|
|
Packit |
90a5c9 |
exit(rv);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void *xmalloc(size_t size)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
void *ret = malloc(size);
|
|
Packit |
90a5c9 |
if (ret == NULL) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "Could not allocate memory (%"
|
|
Packit |
90a5c9 |
APR_SIZE_T_FMT" bytes)\n", size);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return ret;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void *xcalloc(size_t num, size_t size)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
void *ret = calloc(num, size);
|
|
Packit |
90a5c9 |
if (ret == NULL) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "Could not allocate memory (%"
|
|
Packit |
90a5c9 |
APR_SIZE_T_FMT" bytes)\n", size*num);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return ret;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static char *xstrdup(const char *s)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *ret = strdup(s);
|
|
Packit |
90a5c9 |
if (ret == NULL) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "Could not allocate memory (%"
|
|
Packit |
90a5c9 |
APR_SIZE_T_FMT " bytes)\n", strlen(s));
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return ret;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Similar to standard strstr() but we ignore case in this version.
|
|
Packit |
90a5c9 |
* Copied from ap_strcasestr().
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static char *xstrcasestr(const char *s1, const char *s2)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *p1, *p2;
|
|
Packit |
90a5c9 |
if (*s2 == '\0') {
|
|
Packit |
90a5c9 |
/* an empty s2 */
|
|
Packit |
90a5c9 |
return((char *)s1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
while(1) {
|
|
Packit |
90a5c9 |
for ( ; (*s1 != '\0') && (apr_tolower(*s1) != apr_tolower(*s2)); s1++);
|
|
Packit |
90a5c9 |
if (*s1 == '\0') {
|
|
Packit |
90a5c9 |
return(NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* found first character of s2, see if the rest matches */
|
|
Packit |
90a5c9 |
p1 = (char *)s1;
|
|
Packit |
90a5c9 |
p2 = (char *)s2;
|
|
Packit |
90a5c9 |
for (++p1, ++p2; apr_tolower(*p1) == apr_tolower(*p2); ++p1, ++p2) {
|
|
Packit |
90a5c9 |
if (*p1 == '\0') {
|
|
Packit |
90a5c9 |
/* both strings ended together */
|
|
Packit |
90a5c9 |
return((char *)s1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (*p2 == '\0') {
|
|
Packit |
90a5c9 |
/* second string ended, a match */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* didn't find a match here, try starting at next character in s1 */
|
|
Packit |
90a5c9 |
s1++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return((char *)s1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* pool abort function */
|
|
Packit |
90a5c9 |
static int abort_on_oom(int retcode)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
fprintf(stderr, "Could not allocate memory\n");
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
/* not reached */
|
|
Packit |
90a5c9 |
return retcode;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void set_polled_events(struct connection *c, apr_int16_t new_reqevents)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (c->pollfd.reqevents != new_reqevents) {
|
|
Packit |
90a5c9 |
if (c->pollfd.reqevents != 0) {
|
|
Packit |
90a5c9 |
rv = apr_pollset_remove(readbits, &c->pollfd);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
apr_err("apr_pollset_remove()", rv);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (new_reqevents != 0) {
|
|
Packit |
90a5c9 |
c->pollfd.reqevents = new_reqevents;
|
|
Packit |
90a5c9 |
rv = apr_pollset_add(readbits, &c->pollfd);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
apr_err("apr_pollset_add()", rv);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void set_conn_state(struct connection *c, connect_state_e new_state)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_int16_t events_by_state[] = {
|
|
Packit |
90a5c9 |
0, /* for STATE_UNCONNECTED */
|
|
Packit |
90a5c9 |
APR_POLLOUT, /* for STATE_CONNECTING */
|
|
Packit |
90a5c9 |
APR_POLLIN, /* for STATE_CONNECTED; we don't poll in this state,
|
|
Packit |
90a5c9 |
* so prepare for polling in the following state --
|
|
Packit |
90a5c9 |
* STATE_READ
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
APR_POLLIN /* for STATE_READ */
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
c->state = new_state;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
set_polled_events(c, events_by_state[new_state]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* --------------------------------------------------------- */
|
|
Packit |
90a5c9 |
/* write out request to a connection - assumes we can write
|
|
Packit |
90a5c9 |
* (small) request out in one go into our new socket buffer
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
static long ssl_print_cb(BIO *bio,int cmd,const char *argp,int argi,long argl,long ret)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
BIO *out;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
out=(BIO *)BIO_get_callback_arg(bio);
|
|
Packit |
90a5c9 |
if (out == NULL) return(ret);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (cmd == (BIO_CB_READ|BIO_CB_RETURN)) {
|
|
Packit |
90a5c9 |
BIO_printf(out,"read from %p [%p] (%d bytes => %ld (0x%lX))\n",
|
|
Packit |
90a5c9 |
bio, argp, argi, ret, ret);
|
|
Packit |
90a5c9 |
BIO_dump(out,(char *)argp,(int)ret);
|
|
Packit |
90a5c9 |
return(ret);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (cmd == (BIO_CB_WRITE|BIO_CB_RETURN)) {
|
|
Packit |
90a5c9 |
BIO_printf(out,"write to %p [%p] (%d bytes => %ld (0x%lX))\n",
|
|
Packit |
90a5c9 |
bio, argp, argi, ret, ret);
|
|
Packit |
90a5c9 |
BIO_dump(out,(char *)argp,(int)ret);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return ret;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ssl_state_cb(const SSL *s, int w, int r)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (w & SSL_CB_ALERT) {
|
|
Packit |
90a5c9 |
BIO_printf(bio_err, "SSL/TLS Alert [%s] %s:%s\n",
|
|
Packit |
90a5c9 |
(w & SSL_CB_READ ? "read" : "write"),
|
|
Packit |
90a5c9 |
SSL_alert_type_string_long(r),
|
|
Packit |
90a5c9 |
SSL_alert_desc_string_long(r));
|
|
Packit |
90a5c9 |
} else if (w & SSL_CB_LOOP) {
|
|
Packit |
90a5c9 |
BIO_printf(bio_err, "SSL/TLS State [%s] %s\n",
|
|
Packit |
90a5c9 |
(SSL_in_connect_init((SSL*)s) ? "connect" : "-"),
|
|
Packit |
90a5c9 |
SSL_state_string_long(s));
|
|
Packit |
90a5c9 |
} else if (w & (SSL_CB_HANDSHAKE_START|SSL_CB_HANDSHAKE_DONE)) {
|
|
Packit |
90a5c9 |
BIO_printf(bio_err, "SSL/TLS Handshake [%s] %s\n",
|
|
Packit |
90a5c9 |
(w & SSL_CB_HANDSHAKE_START ? "Start" : "Done"),
|
|
Packit |
90a5c9 |
SSL_state_string_long(s));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef RAND_MAX
|
|
Packit |
90a5c9 |
#define RAND_MAX INT_MAX
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int ssl_rand_choosenum(int l, int h)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
char buf[50];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
srand((unsigned int)time(NULL));
|
|
Packit |
90a5c9 |
apr_snprintf(buf, sizeof(buf), "%.0f",
|
|
Packit |
90a5c9 |
(((double)(rand()%RAND_MAX)/RAND_MAX)*(h-l)));
|
|
Packit |
90a5c9 |
i = atoi(buf)+1;
|
|
Packit |
90a5c9 |
if (i < l) i = l;
|
|
Packit |
90a5c9 |
if (i > h) i = h;
|
|
Packit |
90a5c9 |
return i;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ssl_rand_seed(void)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int n, l;
|
|
Packit |
90a5c9 |
time_t t;
|
|
Packit |
90a5c9 |
pid_t pid;
|
|
Packit |
90a5c9 |
unsigned char stackdata[256];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* seed in the current time (usually just 4 bytes)
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
t = time(NULL);
|
|
Packit |
90a5c9 |
l = sizeof(time_t);
|
|
Packit |
90a5c9 |
RAND_seed((unsigned char *)&t, l);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* seed in the current process id (usually just 4 bytes)
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
pid = getpid();
|
|
Packit |
90a5c9 |
l = sizeof(pid_t);
|
|
Packit |
90a5c9 |
RAND_seed((unsigned char *)&pid, l);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* seed in some current state of the run-time stack (128 bytes)
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
n = ssl_rand_choosenum(0, sizeof(stackdata)-128-1);
|
|
Packit |
90a5c9 |
RAND_seed(stackdata+n, 128);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int ssl_print_connection_info(BIO *bio, SSL *ssl)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
AB_SSL_CIPHER_CONST SSL_CIPHER *c;
|
|
Packit |
90a5c9 |
int alg_bits,bits;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
BIO_printf(bio,"Transport Protocol :%s\n", SSL_get_version(ssl));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
c = SSL_get_current_cipher(ssl);
|
|
Packit |
90a5c9 |
BIO_printf(bio,"Cipher Suite Protocol :%s\n", SSL_CIPHER_get_version(c));
|
|
Packit |
90a5c9 |
BIO_printf(bio,"Cipher Suite Name :%s\n",SSL_CIPHER_get_name(c));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
bits = SSL_CIPHER_get_bits(c,&alg_bits);
|
|
Packit |
90a5c9 |
BIO_printf(bio,"Cipher Suite Cipher Bits:%d (%d)\n",bits,alg_bits);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ssl_print_cert_info(BIO *bio, X509 *cert)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
X509_NAME *dn;
|
|
Packit |
90a5c9 |
EVP_PKEY *pk;
|
|
Packit |
90a5c9 |
char buf[1024];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
BIO_printf(bio, "Certificate version: %ld\n", X509_get_version(cert)+1);
|
|
Packit |
90a5c9 |
BIO_printf(bio,"Valid from: ");
|
|
Packit |
90a5c9 |
ASN1_UTCTIME_print(bio, X509_get_notBefore(cert));
|
|
Packit |
90a5c9 |
BIO_printf(bio,"\n");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
BIO_printf(bio,"Valid to : ");
|
|
Packit |
90a5c9 |
ASN1_UTCTIME_print(bio, X509_get_notAfter(cert));
|
|
Packit |
90a5c9 |
BIO_printf(bio,"\n");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
pk = X509_get_pubkey(cert);
|
|
Packit |
90a5c9 |
BIO_printf(bio,"Public key is %d bits\n",
|
|
Packit |
90a5c9 |
EVP_PKEY_bits(pk));
|
|
Packit |
90a5c9 |
EVP_PKEY_free(pk);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
dn = X509_get_issuer_name(cert);
|
|
Packit |
90a5c9 |
X509_NAME_oneline(dn, buf, sizeof(buf));
|
|
Packit |
90a5c9 |
BIO_printf(bio,"The issuer name is %s\n", buf);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
dn=X509_get_subject_name(cert);
|
|
Packit |
90a5c9 |
X509_NAME_oneline(dn, buf, sizeof(buf));
|
|
Packit |
90a5c9 |
BIO_printf(bio,"The subject name is %s\n", buf);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* dump the extension list too */
|
|
Packit |
90a5c9 |
BIO_printf(bio, "Extension Count: %d\n", X509_get_ext_count(cert));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ssl_print_info(struct connection *c)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
X509_STACK_TYPE *sk;
|
|
Packit |
90a5c9 |
X509 *cert;
|
|
Packit |
90a5c9 |
int count;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
BIO_printf(bio_err, "\n");
|
|
Packit |
90a5c9 |
sk = SSL_get_peer_cert_chain(c->ssl);
|
|
Packit |
90a5c9 |
if ((count = SK_NUM(sk)) > 0) {
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
for (i=1; i
|
|
Packit |
90a5c9 |
cert = (X509 *)SK_VALUE(sk, i);
|
|
Packit |
90a5c9 |
ssl_print_cert_info(bio_out, cert);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
cert = SSL_get_peer_certificate(c->ssl);
|
|
Packit |
90a5c9 |
if (cert == NULL) {
|
|
Packit |
90a5c9 |
BIO_printf(bio_out, "Anon DH\n");
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
BIO_printf(bio_out, "Peer certificate\n");
|
|
Packit |
90a5c9 |
ssl_print_cert_info(bio_out, cert);
|
|
Packit |
90a5c9 |
X509_free(cert);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ssl_print_connection_info(bio_err,c->ssl);
|
|
Packit |
90a5c9 |
SSL_SESSION_print(bio_err, SSL_get_session(c->ssl));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ssl_proceed_handshake(struct connection *c)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int do_next = 1;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (do_next) {
|
|
Packit |
90a5c9 |
int ret, ecode;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ret = SSL_do_handshake(c->ssl);
|
|
Packit |
90a5c9 |
ecode = SSL_get_error(c->ssl, ret);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
switch (ecode) {
|
|
Packit |
90a5c9 |
case SSL_ERROR_NONE:
|
|
Packit |
90a5c9 |
if (verbosity >= 2)
|
|
Packit |
90a5c9 |
ssl_print_info(c);
|
|
Packit |
90a5c9 |
if (ssl_info == NULL) {
|
|
Packit |
90a5c9 |
AB_SSL_CIPHER_CONST SSL_CIPHER *ci;
|
|
Packit |
90a5c9 |
X509 *cert;
|
|
Packit |
90a5c9 |
int sk_bits, pk_bits, swork;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ci = SSL_get_current_cipher(c->ssl);
|
|
Packit |
90a5c9 |
sk_bits = SSL_CIPHER_get_bits(ci, &swork);
|
|
Packit |
90a5c9 |
cert = SSL_get_peer_certificate(c->ssl);
|
|
Packit |
90a5c9 |
if (cert)
|
|
Packit |
90a5c9 |
pk_bits = EVP_PKEY_bits(X509_get_pubkey(cert));
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
pk_bits = 0; /* Anon DH */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ssl_info = xmalloc(128);
|
|
Packit |
90a5c9 |
apr_snprintf(ssl_info, 128, "%s,%s,%d,%d",
|
|
Packit |
90a5c9 |
SSL_get_version(c->ssl),
|
|
Packit |
90a5c9 |
SSL_CIPHER_get_name(ci),
|
|
Packit |
90a5c9 |
pk_bits, sk_bits);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
|
|
Packit |
90a5c9 |
if (ssl_tmp_key == NULL) {
|
|
Packit |
90a5c9 |
EVP_PKEY *key;
|
|
Packit |
90a5c9 |
if (SSL_get_server_tmp_key(c->ssl, &key)) {
|
|
Packit |
90a5c9 |
ssl_tmp_key = xmalloc(128);
|
|
Packit |
90a5c9 |
switch (EVP_PKEY_id(key)) {
|
|
Packit |
90a5c9 |
case EVP_PKEY_RSA:
|
|
Packit |
90a5c9 |
apr_snprintf(ssl_tmp_key, 128, "RSA %d bits",
|
|
Packit |
90a5c9 |
EVP_PKEY_bits(key));
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case EVP_PKEY_DH:
|
|
Packit |
90a5c9 |
apr_snprintf(ssl_tmp_key, 128, "DH %d bits",
|
|
Packit |
90a5c9 |
EVP_PKEY_bits(key));
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_EC
|
|
Packit |
90a5c9 |
case EVP_PKEY_EC: {
|
|
Packit |
90a5c9 |
const char *cname = NULL;
|
|
Packit |
90a5c9 |
EC_KEY *ec = EVP_PKEY_get1_EC_KEY(key);
|
|
Packit |
90a5c9 |
int nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
|
|
Packit |
90a5c9 |
EC_KEY_free(ec);
|
|
Packit |
90a5c9 |
cname = EC_curve_nid2nist(nid);
|
|
Packit |
90a5c9 |
if (!cname)
|
|
Packit |
90a5c9 |
cname = OBJ_nid2sn(nid);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_snprintf(ssl_tmp_key, 128, "ECDH %s %d bits",
|
|
Packit |
90a5c9 |
cname,
|
|
Packit |
90a5c9 |
EVP_PKEY_bits(key));
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
apr_snprintf(ssl_tmp_key, 128, "%s %d bits",
|
|
Packit |
90a5c9 |
OBJ_nid2sn(EVP_PKEY_id(key)),
|
|
Packit |
90a5c9 |
EVP_PKEY_bits(key));
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
EVP_PKEY_free(key);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
write_request(c);
|
|
Packit |
90a5c9 |
do_next = 0;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case SSL_ERROR_WANT_READ:
|
|
Packit |
90a5c9 |
set_polled_events(c, APR_POLLIN);
|
|
Packit |
90a5c9 |
do_next = 0;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case SSL_ERROR_WANT_WRITE:
|
|
Packit |
90a5c9 |
set_polled_events(c, APR_POLLOUT);
|
|
Packit |
90a5c9 |
do_next = 0;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case SSL_ERROR_WANT_CONNECT:
|
|
Packit |
90a5c9 |
case SSL_ERROR_SSL:
|
|
Packit |
90a5c9 |
case SSL_ERROR_SYSCALL:
|
|
Packit |
90a5c9 |
/* Unexpected result */
|
|
Packit |
90a5c9 |
BIO_printf(bio_err, "SSL handshake failed (%d).\n", ecode);
|
|
Packit |
90a5c9 |
ERR_print_errors(bio_err);
|
|
Packit |
90a5c9 |
close_connection(c);
|
|
Packit |
90a5c9 |
do_next = 0;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#endif /* USE_SSL */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void write_request(struct connection * c)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (started >= requests) {
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
do {
|
|
Packit |
90a5c9 |
apr_time_t tnow;
|
|
Packit |
90a5c9 |
apr_size_t l = c->rwrite;
|
|
Packit |
90a5c9 |
apr_status_t e = APR_SUCCESS; /* prevent gcc warning */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
tnow = lasttime = apr_time_now();
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* First time round ?
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (c->rwrite == 0) {
|
|
Packit |
90a5c9 |
apr_socket_timeout_set(c->aprsock, 0);
|
|
Packit |
90a5c9 |
c->connect = tnow;
|
|
Packit |
90a5c9 |
c->rwrote = 0;
|
|
Packit |
90a5c9 |
c->rwrite = reqlen;
|
|
Packit |
90a5c9 |
if (send_body)
|
|
Packit |
90a5c9 |
c->rwrite += postlen;
|
|
Packit |
90a5c9 |
l = c->rwrite;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (tnow > c->connect + aprtimeout) {
|
|
Packit |
90a5c9 |
printf("Send request timed out!\n");
|
|
Packit |
90a5c9 |
close_connection(c);
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
if (c->ssl) {
|
|
Packit |
90a5c9 |
e = SSL_write(c->ssl, request + c->rwrote, l);
|
|
Packit |
90a5c9 |
if (e <= 0) {
|
|
Packit |
90a5c9 |
switch (SSL_get_error(c->ssl, e)) {
|
|
Packit |
90a5c9 |
case SSL_ERROR_WANT_READ:
|
|
Packit |
90a5c9 |
set_polled_events(c, APR_POLLIN);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case SSL_ERROR_WANT_WRITE:
|
|
Packit |
90a5c9 |
set_polled_events(c, APR_POLLOUT);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
BIO_printf(bio_err, "SSL write failed - closing connection\n");
|
|
Packit |
90a5c9 |
ERR_print_errors(bio_err);
|
|
Packit |
90a5c9 |
close_connection (c);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
l = e;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
e = apr_socket_send(c->aprsock, request + c->rwrote, &l);
|
|
Packit |
90a5c9 |
if (e != APR_SUCCESS && !l) {
|
|
Packit |
90a5c9 |
if (!APR_STATUS_IS_EAGAIN(e)) {
|
|
Packit |
90a5c9 |
epipe++;
|
|
Packit |
90a5c9 |
printf("Send request failed!\n");
|
|
Packit |
90a5c9 |
close_connection(c);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
set_polled_events(c, APR_POLLOUT);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
totalposted += l;
|
|
Packit |
90a5c9 |
c->rwrote += l;
|
|
Packit |
90a5c9 |
c->rwrite -= l;
|
|
Packit |
90a5c9 |
} while (c->rwrite);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
c->endwrite = lasttime = apr_time_now();
|
|
Packit |
90a5c9 |
started++;
|
|
Packit |
90a5c9 |
set_conn_state(c, STATE_READ);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* --------------------------------------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* calculate and output results */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int compradre(struct data * a, struct data * b)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if ((a->ctime) < (b->ctime))
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
if ((a->ctime) > (b->ctime))
|
|
Packit |
90a5c9 |
return +1;
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int comprando(struct data * a, struct data * b)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if ((a->time) < (b->time))
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
if ((a->time) > (b->time))
|
|
Packit |
90a5c9 |
return +1;
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int compri(struct data * a, struct data * b)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_interval_time_t p = a->time - a->ctime;
|
|
Packit |
90a5c9 |
apr_interval_time_t q = b->time - b->ctime;
|
|
Packit |
90a5c9 |
if (p < q)
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
if (p > q)
|
|
Packit |
90a5c9 |
return +1;
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int compwait(struct data * a, struct data * b)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if ((a->waittime) < (b->waittime))
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
if ((a->waittime) > (b->waittime))
|
|
Packit |
90a5c9 |
return 1;
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void output_results(int sig)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
double timetaken;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (sig) {
|
|
Packit |
90a5c9 |
lasttime = apr_time_now(); /* record final time if interrupted */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
timetaken = (double) (lasttime - start) / APR_USEC_PER_SEC;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("\n\n");
|
|
Packit |
90a5c9 |
printf("Server Software: %s\n", servername);
|
|
Packit |
90a5c9 |
printf("Server Hostname: %s\n", hostname);
|
|
Packit |
90a5c9 |
printf("Server Port: %hu\n", port);
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
if (is_ssl && ssl_info) {
|
|
Packit |
90a5c9 |
printf("SSL/TLS Protocol: %s\n", ssl_info);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
|
|
Packit |
90a5c9 |
if (is_ssl && ssl_tmp_key) {
|
|
Packit |
90a5c9 |
printf("Server Temp Key: %s\n", ssl_tmp_key);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSEXT
|
|
Packit |
90a5c9 |
if (is_ssl && tls_sni) {
|
|
Packit |
90a5c9 |
printf("TLS Server Name: %s\n", tls_sni);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
printf("\n");
|
|
Packit |
90a5c9 |
printf("Document Path: %s\n", path);
|
|
Packit |
90a5c9 |
if (nolength)
|
|
Packit |
90a5c9 |
printf("Document Length: Variable\n");
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
printf("Document Length: %" APR_SIZE_T_FMT " bytes\n", doclen);
|
|
Packit |
90a5c9 |
printf("\n");
|
|
Packit |
90a5c9 |
printf("Concurrency Level: %d\n", concurrency);
|
|
Packit |
90a5c9 |
printf("Time taken for tests: %.3f seconds\n", timetaken);
|
|
Packit |
90a5c9 |
printf("Complete requests: %d\n", done);
|
|
Packit |
90a5c9 |
printf("Failed requests: %d\n", bad);
|
|
Packit |
90a5c9 |
if (bad)
|
|
Packit |
90a5c9 |
printf(" (Connect: %d, Receive: %d, Length: %d, Exceptions: %d)\n",
|
|
Packit |
90a5c9 |
err_conn, err_recv, err_length, err_except);
|
|
Packit |
90a5c9 |
if (epipe)
|
|
Packit |
90a5c9 |
printf("Write errors: %d\n", epipe);
|
|
Packit |
90a5c9 |
if (err_response)
|
|
Packit |
90a5c9 |
printf("Non-2xx responses: %d\n", err_response);
|
|
Packit |
90a5c9 |
if (keepalive)
|
|
Packit |
90a5c9 |
printf("Keep-Alive requests: %d\n", doneka);
|
|
Packit |
90a5c9 |
printf("Total transferred: %" APR_INT64_T_FMT " bytes\n", totalread);
|
|
Packit |
90a5c9 |
if (send_body)
|
|
Packit |
90a5c9 |
printf("Total body sent: %" APR_INT64_T_FMT "\n",
|
|
Packit |
90a5c9 |
totalposted);
|
|
Packit |
90a5c9 |
printf("HTML transferred: %" APR_INT64_T_FMT " bytes\n", totalbread);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* avoid divide by zero */
|
|
Packit |
90a5c9 |
if (timetaken && done) {
|
|
Packit |
90a5c9 |
printf("Requests per second: %.2f [#/sec] (mean)\n",
|
|
Packit |
90a5c9 |
(double) done / timetaken);
|
|
Packit |
90a5c9 |
printf("Time per request: %.3f [ms] (mean)\n",
|
|
Packit |
90a5c9 |
(double) concurrency * timetaken * 1000 / done);
|
|
Packit |
90a5c9 |
printf("Time per request: %.3f [ms] (mean, across all concurrent requests)\n",
|
|
Packit |
90a5c9 |
(double) timetaken * 1000 / done);
|
|
Packit |
90a5c9 |
printf("Transfer rate: %.2f [Kbytes/sec] received\n",
|
|
Packit |
90a5c9 |
(double) totalread / 1024 / timetaken);
|
|
Packit |
90a5c9 |
if (send_body) {
|
|
Packit |
90a5c9 |
printf(" %.2f kb/s sent\n",
|
|
Packit |
90a5c9 |
(double) totalposted / 1024 / timetaken);
|
|
Packit |
90a5c9 |
printf(" %.2f kb/s total\n",
|
|
Packit |
90a5c9 |
(double) (totalread + totalposted) / 1024 / timetaken);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (done > 0) {
|
|
Packit |
90a5c9 |
/* work out connection times */
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
apr_time_t totalcon = 0, total = 0, totald = 0, totalwait = 0;
|
|
Packit |
90a5c9 |
apr_time_t meancon, meantot, meand, meanwait;
|
|
Packit |
90a5c9 |
apr_interval_time_t mincon = AB_MAX, mintot = AB_MAX, mind = AB_MAX,
|
|
Packit |
90a5c9 |
minwait = AB_MAX;
|
|
Packit |
90a5c9 |
apr_interval_time_t maxcon = 0, maxtot = 0, maxd = 0, maxwait = 0;
|
|
Packit |
90a5c9 |
apr_interval_time_t mediancon = 0, mediantot = 0, mediand = 0, medianwait = 0;
|
|
Packit |
90a5c9 |
double sdtot = 0, sdcon = 0, sdd = 0, sdwait = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (i = 0; i < done; i++) {
|
|
Packit |
90a5c9 |
struct data *s = &stats[i];
|
|
Packit |
90a5c9 |
mincon = ap_min(mincon, s->ctime);
|
|
Packit |
90a5c9 |
mintot = ap_min(mintot, s->time);
|
|
Packit |
90a5c9 |
mind = ap_min(mind, s->time - s->ctime);
|
|
Packit |
90a5c9 |
minwait = ap_min(minwait, s->waittime);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
maxcon = ap_max(maxcon, s->ctime);
|
|
Packit |
90a5c9 |
maxtot = ap_max(maxtot, s->time);
|
|
Packit |
90a5c9 |
maxd = ap_max(maxd, s->time - s->ctime);
|
|
Packit |
90a5c9 |
maxwait = ap_max(maxwait, s->waittime);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
totalcon += s->ctime;
|
|
Packit |
90a5c9 |
total += s->time;
|
|
Packit |
90a5c9 |
totald += s->time - s->ctime;
|
|
Packit |
90a5c9 |
totalwait += s->waittime;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
meancon = totalcon / done;
|
|
Packit |
90a5c9 |
meantot = total / done;
|
|
Packit |
90a5c9 |
meand = totald / done;
|
|
Packit |
90a5c9 |
meanwait = totalwait / done;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* calculating the sample variance: the sum of the squared deviations, divided by n-1 */
|
|
Packit |
90a5c9 |
for (i = 0; i < done; i++) {
|
|
Packit |
90a5c9 |
struct data *s = &stats[i];
|
|
Packit |
90a5c9 |
double a;
|
|
Packit |
90a5c9 |
a = ((double)s->time - meantot);
|
|
Packit |
90a5c9 |
sdtot += a * a;
|
|
Packit |
90a5c9 |
a = ((double)s->ctime - meancon);
|
|
Packit |
90a5c9 |
sdcon += a * a;
|
|
Packit |
90a5c9 |
a = ((double)s->time - (double)s->ctime - meand);
|
|
Packit |
90a5c9 |
sdd += a * a;
|
|
Packit |
90a5c9 |
a = ((double)s->waittime - meanwait);
|
|
Packit |
90a5c9 |
sdwait += a * a;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
sdtot = (done > 1) ? sqrt(sdtot / (done - 1)) : 0;
|
|
Packit |
90a5c9 |
sdcon = (done > 1) ? sqrt(sdcon / (done - 1)) : 0;
|
|
Packit |
90a5c9 |
sdd = (done > 1) ? sqrt(sdd / (done - 1)) : 0;
|
|
Packit |
90a5c9 |
sdwait = (done > 1) ? sqrt(sdwait / (done - 1)) : 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* XXX: what is better; this hideous cast of the compradre function; or
|
|
Packit |
90a5c9 |
* the four warnings during compile ? dirkx just does not know and
|
|
Packit |
90a5c9 |
* hates both/
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
qsort(stats, done, sizeof(struct data),
|
|
Packit |
90a5c9 |
(int (*) (const void *, const void *)) compradre);
|
|
Packit |
90a5c9 |
if ((done > 1) && (done % 2))
|
|
Packit |
90a5c9 |
mediancon = (stats[done / 2].ctime + stats[done / 2 + 1].ctime) / 2;
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
mediancon = stats[done / 2].ctime;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
qsort(stats, done, sizeof(struct data),
|
|
Packit |
90a5c9 |
(int (*) (const void *, const void *)) compri);
|
|
Packit |
90a5c9 |
if ((done > 1) && (done % 2))
|
|
Packit |
90a5c9 |
mediand = (stats[done / 2].time + stats[done / 2 + 1].time \
|
|
Packit |
90a5c9 |
-stats[done / 2].ctime - stats[done / 2 + 1].ctime) / 2;
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
mediand = stats[done / 2].time - stats[done / 2].ctime;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
qsort(stats, done, sizeof(struct data),
|
|
Packit |
90a5c9 |
(int (*) (const void *, const void *)) compwait);
|
|
Packit |
90a5c9 |
if ((done > 1) && (done % 2))
|
|
Packit |
90a5c9 |
medianwait = (stats[done / 2].waittime + stats[done / 2 + 1].waittime) / 2;
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
medianwait = stats[done / 2].waittime;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
qsort(stats, done, sizeof(struct data),
|
|
Packit |
90a5c9 |
(int (*) (const void *, const void *)) comprando);
|
|
Packit |
90a5c9 |
if ((done > 1) && (done % 2))
|
|
Packit |
90a5c9 |
mediantot = (stats[done / 2].time + stats[done / 2 + 1].time) / 2;
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
mediantot = stats[done / 2].time;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("\nConnection Times (ms)\n");
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Reduce stats from apr time to milliseconds
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
mincon = ap_round_ms(mincon);
|
|
Packit |
90a5c9 |
mind = ap_round_ms(mind);
|
|
Packit |
90a5c9 |
minwait = ap_round_ms(minwait);
|
|
Packit |
90a5c9 |
mintot = ap_round_ms(mintot);
|
|
Packit |
90a5c9 |
meancon = ap_round_ms(meancon);
|
|
Packit |
90a5c9 |
meand = ap_round_ms(meand);
|
|
Packit |
90a5c9 |
meanwait = ap_round_ms(meanwait);
|
|
Packit |
90a5c9 |
meantot = ap_round_ms(meantot);
|
|
Packit |
90a5c9 |
mediancon = ap_round_ms(mediancon);
|
|
Packit |
90a5c9 |
mediand = ap_round_ms(mediand);
|
|
Packit |
90a5c9 |
medianwait = ap_round_ms(medianwait);
|
|
Packit |
90a5c9 |
mediantot = ap_round_ms(mediantot);
|
|
Packit |
90a5c9 |
maxcon = ap_round_ms(maxcon);
|
|
Packit |
90a5c9 |
maxd = ap_round_ms(maxd);
|
|
Packit |
90a5c9 |
maxwait = ap_round_ms(maxwait);
|
|
Packit |
90a5c9 |
maxtot = ap_round_ms(maxtot);
|
|
Packit |
90a5c9 |
sdcon = ap_double_ms(sdcon);
|
|
Packit |
90a5c9 |
sdd = ap_double_ms(sdd);
|
|
Packit |
90a5c9 |
sdwait = ap_double_ms(sdwait);
|
|
Packit |
90a5c9 |
sdtot = ap_double_ms(sdtot);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (confidence) {
|
|
Packit |
90a5c9 |
#define CONF_FMT_STRING "%5" APR_TIME_T_FMT " %4" APR_TIME_T_FMT " %5.1f %6" APR_TIME_T_FMT " %7" APR_TIME_T_FMT "\n"
|
|
Packit |
90a5c9 |
printf(" min mean[+/-sd] median max\n");
|
|
Packit |
90a5c9 |
printf("Connect: " CONF_FMT_STRING,
|
|
Packit |
90a5c9 |
mincon, meancon, sdcon, mediancon, maxcon);
|
|
Packit |
90a5c9 |
printf("Processing: " CONF_FMT_STRING,
|
|
Packit |
90a5c9 |
mind, meand, sdd, mediand, maxd);
|
|
Packit |
90a5c9 |
printf("Waiting: " CONF_FMT_STRING,
|
|
Packit |
90a5c9 |
minwait, meanwait, sdwait, medianwait, maxwait);
|
|
Packit |
90a5c9 |
printf("Total: " CONF_FMT_STRING,
|
|
Packit |
90a5c9 |
mintot, meantot, sdtot, mediantot, maxtot);
|
|
Packit |
90a5c9 |
#undef CONF_FMT_STRING
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define SANE(what,mean,median,sd) \
|
|
Packit |
90a5c9 |
{ \
|
|
Packit |
90a5c9 |
double d = (double)mean - median; \
|
|
Packit |
90a5c9 |
if (d < 0) d = -d; \
|
|
Packit |
90a5c9 |
if (d > 2 * sd ) \
|
|
Packit |
90a5c9 |
printf("ERROR: The median and mean for " what " are more than twice the standard\n" \
|
|
Packit |
90a5c9 |
" deviation apart. These results are NOT reliable.\n"); \
|
|
Packit |
90a5c9 |
else if (d > sd ) \
|
|
Packit |
90a5c9 |
printf("WARNING: The median and mean for " what " are not within a normal deviation\n" \
|
|
Packit |
90a5c9 |
" These results are probably not that reliable.\n"); \
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
SANE("the initial connection time", meancon, mediancon, sdcon);
|
|
Packit |
90a5c9 |
SANE("the processing time", meand, mediand, sdd);
|
|
Packit |
90a5c9 |
SANE("the waiting time", meanwait, medianwait, sdwait);
|
|
Packit |
90a5c9 |
SANE("the total time", meantot, mediantot, sdtot);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
printf(" min avg max\n");
|
|
Packit |
90a5c9 |
#define CONF_FMT_STRING "%5" APR_TIME_T_FMT " %5" APR_TIME_T_FMT "%5" APR_TIME_T_FMT "\n"
|
|
Packit |
90a5c9 |
printf("Connect: " CONF_FMT_STRING, mincon, meancon, maxcon);
|
|
Packit |
90a5c9 |
printf("Processing: " CONF_FMT_STRING, mind, meand, maxd);
|
|
Packit |
90a5c9 |
printf("Waiting: " CONF_FMT_STRING, minwait, meanwait, maxwait);
|
|
Packit |
90a5c9 |
printf("Total: " CONF_FMT_STRING, mintot, meantot, maxtot);
|
|
Packit |
90a5c9 |
#undef CONF_FMT_STRING
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Sorted on total connect times */
|
|
Packit |
90a5c9 |
if (percentile && (done > 1)) {
|
|
Packit |
90a5c9 |
printf("\nPercentage of the requests served within a certain time (ms)\n");
|
|
Packit |
90a5c9 |
for (i = 0; i < sizeof(percs) / sizeof(int); i++) {
|
|
Packit |
90a5c9 |
if (percs[i] <= 0)
|
|
Packit |
90a5c9 |
printf(" 0%% <0> (never)\n");
|
|
Packit |
90a5c9 |
else if (percs[i] >= 100)
|
|
Packit |
90a5c9 |
printf(" 100%% %5" APR_TIME_T_FMT " (longest request)\n",
|
|
Packit |
90a5c9 |
ap_round_ms(stats[done - 1].time));
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
printf(" %d%% %5" APR_TIME_T_FMT "\n", percs[i],
|
|
Packit |
90a5c9 |
ap_round_ms(stats[(unsigned long)done * percs[i] / 100].time));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (csvperc) {
|
|
Packit |
90a5c9 |
FILE *out = fopen(csvperc, "w");
|
|
Packit |
90a5c9 |
if (!out) {
|
|
Packit |
90a5c9 |
perror("Cannot open CSV output file");
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
fprintf(out, "" "Percentage served" "," "Time in ms" "\n");
|
|
Packit |
90a5c9 |
for (i = 0; i <= 100; i++) {
|
|
Packit |
90a5c9 |
double t;
|
|
Packit |
90a5c9 |
if (i == 0)
|
|
Packit |
90a5c9 |
t = ap_double_ms(stats[0].time);
|
|
Packit |
90a5c9 |
else if (i == 100)
|
|
Packit |
90a5c9 |
t = ap_double_ms(stats[done - 1].time);
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
t = ap_double_ms(stats[(unsigned long) (0.5 + (double)done * i / 100.0)].time);
|
|
Packit |
90a5c9 |
fprintf(out, "%d,%.3f\n", i, t);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
fclose(out);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (gnuplot) {
|
|
Packit |
90a5c9 |
FILE *out = fopen(gnuplot, "w");
|
|
Packit |
90a5c9 |
char tmstring[APR_CTIME_LEN];
|
|
Packit |
90a5c9 |
if (!out) {
|
|
Packit |
90a5c9 |
perror("Cannot open gnuplot output file");
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
fprintf(out, "starttime\tseconds\tctime\tdtime\tttime\twait\n");
|
|
Packit |
90a5c9 |
for (i = 0; i < done; i++) {
|
|
Packit |
90a5c9 |
(void) apr_ctime(tmstring, stats[i].starttime);
|
|
Packit |
90a5c9 |
fprintf(out, "%s\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT
|
|
Packit |
90a5c9 |
"\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT
|
|
Packit |
90a5c9 |
"\t%" APR_TIME_T_FMT "\n", tmstring,
|
|
Packit |
90a5c9 |
apr_time_sec(stats[i].starttime),
|
|
Packit |
90a5c9 |
ap_round_ms(stats[i].ctime),
|
|
Packit |
90a5c9 |
ap_round_ms(stats[i].time - stats[i].ctime),
|
|
Packit |
90a5c9 |
ap_round_ms(stats[i].time),
|
|
Packit |
90a5c9 |
ap_round_ms(stats[i].waittime));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
fclose(out);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (sig) {
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* --------------------------------------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* calculate and output results in HTML */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void output_html_results(void)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
double timetaken = (double) (lasttime - start) / APR_USEC_PER_SEC;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("\n\n\n", tablestring);
|
|
Packit |
90a5c9 |
printf("Server Software:"
|
|
Packit |
90a5c9 |
"%s\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, servername);
|
|
Packit |
90a5c9 |
printf("Server Hostname:"
|
|
Packit |
90a5c9 |
"%s\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, hostname);
|
|
Packit |
90a5c9 |
printf("Server Port:"
|
|
Packit |
90a5c9 |
"%hu\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, port);
|
|
Packit |
90a5c9 |
printf("Document Path:"
|
|
Packit |
90a5c9 |
"%s\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, path);
|
|
Packit |
90a5c9 |
if (nolength)
|
|
Packit |
90a5c9 |
printf("Document Length:"
|
|
Packit |
90a5c9 |
"Variable\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring);
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
printf("Document Length:"
|
|
Packit |
90a5c9 |
"%" APR_SIZE_T_FMT " bytes\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, doclen);
|
|
Packit |
90a5c9 |
printf("Concurrency Level:"
|
|
Packit |
90a5c9 |
"%d\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, concurrency);
|
|
Packit |
90a5c9 |
printf("Time taken for tests:"
|
|
Packit |
90a5c9 |
"%.3f seconds\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, timetaken);
|
|
Packit |
90a5c9 |
printf("Complete requests:"
|
|
Packit |
90a5c9 |
"%d\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, done);
|
|
Packit |
90a5c9 |
printf("Failed requests:"
|
|
Packit |
90a5c9 |
"%d\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, bad);
|
|
Packit |
90a5c9 |
if (bad)
|
|
Packit |
90a5c9 |
printf(" (Connect: %d, Length: %d, Exceptions: %d)\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, err_conn, err_length, err_except);
|
|
Packit |
90a5c9 |
if (err_response)
|
|
Packit |
90a5c9 |
printf("Non-2xx responses:"
|
|
Packit |
90a5c9 |
"%d\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, err_response);
|
|
Packit |
90a5c9 |
if (keepalive)
|
|
Packit |
90a5c9 |
printf("Keep-Alive requests:"
|
|
Packit |
90a5c9 |
"%d\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, doneka);
|
|
Packit |
90a5c9 |
printf("Total transferred:"
|
|
Packit |
90a5c9 |
"%" APR_INT64_T_FMT " bytes\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, totalread);
|
|
Packit |
90a5c9 |
if (send_body)
|
|
Packit |
90a5c9 |
printf("Total body sent:"
|
|
Packit |
90a5c9 |
"%" APR_INT64_T_FMT "\n",
|
|
Packit |
90a5c9 |
trstring, tdstring,
|
|
Packit |
90a5c9 |
tdstring, totalposted);
|
|
Packit |
90a5c9 |
printf("HTML transferred:"
|
|
Packit |
90a5c9 |
"%" APR_INT64_T_FMT " bytes\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, totalbread);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* avoid divide by zero */
|
|
Packit |
90a5c9 |
if (timetaken) {
|
|
Packit |
90a5c9 |
printf("Requests per second:"
|
|
Packit |
90a5c9 |
"%.2f\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, (double) done / timetaken);
|
|
Packit |
90a5c9 |
printf("Transfer rate:"
|
|
Packit |
90a5c9 |
"%.2f kb/s received\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, (double) totalread / 1024 / timetaken);
|
|
Packit |
90a5c9 |
if (send_body) {
|
|
Packit |
90a5c9 |
printf(" "
|
|
Packit |
90a5c9 |
"%.2f kb/s sent\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring,
|
|
Packit |
90a5c9 |
(double) totalposted / 1024 / timetaken);
|
|
Packit |
90a5c9 |
printf(" "
|
|
Packit |
90a5c9 |
"%.2f kb/s total\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring,
|
|
Packit |
90a5c9 |
(double) (totalread + totalposted) / 1024 / timetaken);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/* work out connection times */
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
apr_interval_time_t totalcon = 0, total = 0;
|
|
Packit |
90a5c9 |
apr_interval_time_t mincon = AB_MAX, mintot = AB_MAX;
|
|
Packit |
90a5c9 |
apr_interval_time_t maxcon = 0, maxtot = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (i = 0; i < done; i++) {
|
|
Packit |
90a5c9 |
struct data *s = &stats[i];
|
|
Packit |
90a5c9 |
mincon = ap_min(mincon, s->ctime);
|
|
Packit |
90a5c9 |
mintot = ap_min(mintot, s->time);
|
|
Packit |
90a5c9 |
maxcon = ap_max(maxcon, s->ctime);
|
|
Packit |
90a5c9 |
maxtot = ap_max(maxtot, s->time);
|
|
Packit |
90a5c9 |
totalcon += s->ctime;
|
|
Packit |
90a5c9 |
total += s->time;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Reduce stats from apr time to milliseconds
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
mincon = ap_round_ms(mincon);
|
|
Packit |
90a5c9 |
mintot = ap_round_ms(mintot);
|
|
Packit |
90a5c9 |
maxcon = ap_round_ms(maxcon);
|
|
Packit |
90a5c9 |
maxtot = ap_round_ms(maxtot);
|
|
Packit |
90a5c9 |
totalcon = ap_round_ms(totalcon);
|
|
Packit |
90a5c9 |
total = ap_round_ms(total);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (done > 0) { /* avoid division by zero (if 0 done) */
|
|
Packit |
90a5c9 |
printf("Connnection Times (ms)\n",
|
|
Packit |
90a5c9 |
trstring, tdstring);
|
|
Packit |
90a5c9 |
printf(" min avg max\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, tdstring, tdstring);
|
|
Packit |
90a5c9 |
printf("Connect:"
|
|
Packit |
90a5c9 |
"%5" APR_TIME_T_FMT ""
|
|
Packit |
90a5c9 |
"%5" APR_TIME_T_FMT ""
|
|
Packit |
90a5c9 |
"%5" APR_TIME_T_FMT "\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, mincon, tdstring, totalcon / done, tdstring, maxcon);
|
|
Packit |
90a5c9 |
printf("Processing:"
|
|
Packit |
90a5c9 |
"%5" APR_TIME_T_FMT ""
|
|
Packit |
90a5c9 |
"%5" APR_TIME_T_FMT ""
|
|
Packit |
90a5c9 |
"%5" APR_TIME_T_FMT "\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, mintot - mincon, tdstring,
|
|
Packit |
90a5c9 |
(total / done) - (totalcon / done), tdstring, maxtot - maxcon);
|
|
Packit |
90a5c9 |
printf("Total:"
|
|
Packit |
90a5c9 |
"%5" APR_TIME_T_FMT ""
|
|
Packit |
90a5c9 |
"%5" APR_TIME_T_FMT ""
|
|
Packit |
90a5c9 |
"%5" APR_TIME_T_FMT "\n",
|
|
Packit |
90a5c9 |
trstring, tdstring, tdstring, mintot, tdstring, total / done, tdstring, maxtot);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
printf("\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* --------------------------------------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* start asnchronous non-blocking connection */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void start_connect(struct connection * c)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(started < requests))
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
c->read = 0;
|
|
Packit |
90a5c9 |
c->bread = 0;
|
|
Packit |
90a5c9 |
c->keepalive = 0;
|
|
Packit |
90a5c9 |
c->cbx = 0;
|
|
Packit |
90a5c9 |
c->gotheader = 0;
|
|
Packit |
90a5c9 |
c->rwrite = 0;
|
|
Packit |
90a5c9 |
if (c->ctx)
|
|
Packit |
90a5c9 |
apr_pool_clear(c->ctx);
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
apr_pool_create(&c->ctx, cntxt);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = apr_socket_create(&c->aprsock, destsa->family,
|
|
Packit |
90a5c9 |
SOCK_STREAM, 0, c->ctx)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
apr_err("socket", rv);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (myhost) {
|
|
Packit |
90a5c9 |
if ((rv = apr_socket_bind(c->aprsock, mysa)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
apr_err("bind", rv);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
c->pollfd.desc_type = APR_POLL_SOCKET;
|
|
Packit |
90a5c9 |
c->pollfd.desc.s = c->aprsock;
|
|
Packit |
90a5c9 |
c->pollfd.reqevents = 0;
|
|
Packit |
90a5c9 |
c->pollfd.client_data = c;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rv = apr_socket_opt_set(c->aprsock, APR_SO_NONBLOCK, 1))
|
|
Packit |
90a5c9 |
!= APR_SUCCESS) {
|
|
Packit |
90a5c9 |
apr_err("socket nonblock", rv);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (windowsize != 0) {
|
|
Packit |
90a5c9 |
rv = apr_socket_opt_set(c->aprsock, APR_SO_SNDBUF,
|
|
Packit |
90a5c9 |
windowsize);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS && rv != APR_ENOTIMPL) {
|
|
Packit |
90a5c9 |
apr_err("socket send buffer", rv);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
rv = apr_socket_opt_set(c->aprsock, APR_SO_RCVBUF,
|
|
Packit |
90a5c9 |
windowsize);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS && rv != APR_ENOTIMPL) {
|
|
Packit |
90a5c9 |
apr_err("socket receive buffer", rv);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
c->start = lasttime = apr_time_now();
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
if (is_ssl) {
|
|
Packit |
90a5c9 |
BIO *bio;
|
|
Packit |
90a5c9 |
apr_os_sock_t fd;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((c->ssl = SSL_new(ssl_ctx)) == NULL) {
|
|
Packit |
90a5c9 |
BIO_printf(bio_err, "SSL_new failed.\n");
|
|
Packit |
90a5c9 |
ERR_print_errors(bio_err);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ssl_rand_seed();
|
|
Packit |
90a5c9 |
apr_os_sock_get(&fd, c->aprsock);
|
|
Packit |
90a5c9 |
bio = BIO_new_socket(fd, BIO_NOCLOSE);
|
|
Packit |
90a5c9 |
BIO_set_nbio(bio, 1);
|
|
Packit |
90a5c9 |
SSL_set_bio(c->ssl, bio, bio);
|
|
Packit |
90a5c9 |
SSL_set_connect_state(c->ssl);
|
|
Packit |
90a5c9 |
if (verbosity >= 4) {
|
|
Packit |
90a5c9 |
BIO_set_callback(bio, ssl_print_cb);
|
|
Packit |
90a5c9 |
BIO_set_callback_arg(bio, (void *)bio_err);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSEXT
|
|
Packit |
90a5c9 |
if (tls_sni) {
|
|
Packit |
90a5c9 |
SSL_set_tlsext_host_name(c->ssl, tls_sni);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
c->ssl = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
if ((rv = apr_socket_connect(c->aprsock, destsa)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
if (APR_STATUS_IS_EINPROGRESS(rv)) {
|
|
Packit |
90a5c9 |
set_conn_state(c, STATE_CONNECTING);
|
|
Packit |
90a5c9 |
c->rwrite = 0;
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
set_conn_state(c, STATE_UNCONNECTED);
|
|
Packit |
90a5c9 |
apr_socket_close(c->aprsock);
|
|
Packit |
90a5c9 |
if (good == 0 && destsa->next) {
|
|
Packit |
90a5c9 |
destsa = destsa->next;
|
|
Packit |
90a5c9 |
err_conn = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (bad++ > 10) {
|
|
Packit |
90a5c9 |
fprintf(stderr,
|
|
Packit |
90a5c9 |
"\nTest aborted after 10 failures\n\n");
|
|
Packit |
90a5c9 |
apr_err("apr_socket_connect()", rv);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
err_conn++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
start_connect(c);
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* connected first time */
|
|
Packit |
90a5c9 |
set_conn_state(c, STATE_CONNECTED);
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
if (c->ssl) {
|
|
Packit |
90a5c9 |
ssl_proceed_handshake(c);
|
|
Packit |
90a5c9 |
} else
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
write_request(c);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* --------------------------------------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* close down connection and save stats */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void close_connection(struct connection * c)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (c->read == 0 && c->keepalive) {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* server has legitimately shut down an idle keep alive request
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (good)
|
|
Packit |
90a5c9 |
good--; /* connection never happened */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
if (good == 1) {
|
|
Packit |
90a5c9 |
/* first time here */
|
|
Packit |
90a5c9 |
doclen = c->bread;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if ((c->bread != doclen) && !nolength) {
|
|
Packit |
90a5c9 |
bad++;
|
|
Packit |
90a5c9 |
err_length++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* save out time */
|
|
Packit |
90a5c9 |
if (done < requests) {
|
|
Packit |
90a5c9 |
struct data *s = &stats[done++];
|
|
Packit |
90a5c9 |
c->done = lasttime = apr_time_now();
|
|
Packit |
90a5c9 |
s->starttime = c->start;
|
|
Packit |
90a5c9 |
s->ctime = ap_max(0, c->connect - c->start);
|
|
Packit |
90a5c9 |
s->time = ap_max(0, c->done - c->start);
|
|
Packit |
90a5c9 |
s->waittime = ap_max(0, c->beginread - c->endwrite);
|
|
Packit |
90a5c9 |
if (heartbeatres && !(done % heartbeatres)) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "Completed %d requests\n", done);
|
|
Packit |
90a5c9 |
fflush(stderr);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
set_conn_state(c, STATE_UNCONNECTED);
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
if (c->ssl) {
|
|
Packit |
90a5c9 |
SSL_shutdown(c->ssl);
|
|
Packit |
90a5c9 |
SSL_free(c->ssl);
|
|
Packit |
90a5c9 |
c->ssl = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
apr_socket_close(c->aprsock);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* connect again */
|
|
Packit |
90a5c9 |
start_connect(c);
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* --------------------------------------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* read data from connection */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void read_connection(struct connection * c)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_size_t r;
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
char *part;
|
|
Packit |
90a5c9 |
char respcode[4]; /* 3 digits and null */
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
r = sizeof(buffer);
|
|
Packit |
90a5c9 |
read_more:
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
if (c->ssl) {
|
|
Packit |
90a5c9 |
status = SSL_read(c->ssl, buffer, r);
|
|
Packit |
90a5c9 |
if (status <= 0) {
|
|
Packit |
90a5c9 |
int scode = SSL_get_error(c->ssl, status);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (scode == SSL_ERROR_ZERO_RETURN) {
|
|
Packit |
90a5c9 |
/* connection closed cleanly: */
|
|
Packit |
90a5c9 |
good++;
|
|
Packit |
90a5c9 |
close_connection(c);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (scode == SSL_ERROR_SYSCALL
|
|
Packit |
90a5c9 |
&& status == 0
|
|
Packit |
90a5c9 |
&& c->read != 0) {
|
|
Packit |
90a5c9 |
/* connection closed, but in violation of the protocol, after
|
|
Packit |
90a5c9 |
* some data has already been read; this commonly happens, so
|
|
Packit |
90a5c9 |
* let the length check catch any response errors
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
good++;
|
|
Packit |
90a5c9 |
close_connection(c);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (scode == SSL_ERROR_SYSCALL
|
|
Packit |
90a5c9 |
&& c->read == 0
|
|
Packit |
90a5c9 |
&& destsa->next
|
|
Packit |
90a5c9 |
&& c->state == STATE_CONNECTING
|
|
Packit |
90a5c9 |
&& good == 0) {
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (scode == SSL_ERROR_WANT_READ) {
|
|
Packit |
90a5c9 |
set_polled_events(c, APR_POLLIN);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (scode == SSL_ERROR_WANT_WRITE) {
|
|
Packit |
90a5c9 |
set_polled_events(c, APR_POLLOUT);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* some fatal error: */
|
|
Packit |
90a5c9 |
c->read = 0;
|
|
Packit |
90a5c9 |
BIO_printf(bio_err, "SSL read failed (%d) - closing connection\n", scode);
|
|
Packit |
90a5c9 |
ERR_print_errors(bio_err);
|
|
Packit |
90a5c9 |
close_connection(c);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
r = status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
status = apr_socket_recv(c->aprsock, buffer, &r);
|
|
Packit |
90a5c9 |
if (APR_STATUS_IS_EAGAIN(status))
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
else if (r == 0 && APR_STATUS_IS_EOF(status)) {
|
|
Packit |
90a5c9 |
good++;
|
|
Packit |
90a5c9 |
close_connection(c);
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* catch legitimate fatal apr_socket_recv errors */
|
|
Packit |
90a5c9 |
else if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
if (recverrok) {
|
|
Packit |
90a5c9 |
err_recv++;
|
|
Packit |
90a5c9 |
bad++;
|
|
Packit |
90a5c9 |
close_connection(c);
|
|
Packit |
90a5c9 |
if (verbosity >= 1) {
|
|
Packit |
90a5c9 |
char buf[120];
|
|
Packit |
90a5c9 |
fprintf(stderr,"%s: %s (%d)\n", "apr_socket_recv", apr_strerror(status, buf, sizeof buf), status);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
} else if (destsa->next && c->state == STATE_CONNECTING
|
|
Packit |
90a5c9 |
&& c->read == 0 && good == 0) {
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
err_recv++;
|
|
Packit |
90a5c9 |
apr_err("apr_socket_recv", status);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
totalread += r;
|
|
Packit |
90a5c9 |
if (c->read == 0) {
|
|
Packit |
90a5c9 |
c->beginread = apr_time_now();
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
c->read += r;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!c->gotheader) {
|
|
Packit |
90a5c9 |
char *s;
|
|
Packit |
90a5c9 |
int l = 4;
|
|
Packit |
90a5c9 |
apr_size_t space = CBUFFSIZE - c->cbx - 1; /* -1 allows for \0 term */
|
|
Packit |
90a5c9 |
int tocopy = (space < r) ? space : r;
|
|
Packit |
90a5c9 |
#ifdef NOT_ASCII
|
|
Packit |
90a5c9 |
apr_size_t inbytes_left = space, outbytes_left = space;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = apr_xlate_conv_buffer(from_ascii, buffer, &inbytes_left,
|
|
Packit |
90a5c9 |
c->cbuff + c->cbx, &outbytes_left);
|
|
Packit |
90a5c9 |
if (status || inbytes_left || outbytes_left) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "only simple translation is supported (%d/%" APR_SIZE_T_FMT
|
|
Packit |
90a5c9 |
"/%" APR_SIZE_T_FMT ")\n", status, inbytes_left, outbytes_left);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
memcpy(c->cbuff + c->cbx, buffer, space);
|
|
Packit |
90a5c9 |
#endif /* NOT_ASCII */
|
|
Packit |
90a5c9 |
c->cbx += tocopy;
|
|
Packit |
90a5c9 |
space -= tocopy;
|
|
Packit |
90a5c9 |
c->cbuff[c->cbx] = 0; /* terminate for benefit of strstr */
|
|
Packit |
90a5c9 |
if (verbosity >= 2) {
|
|
Packit |
90a5c9 |
printf("LOG: header received:\n%s\n", c->cbuff);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
s = strstr(c->cbuff, "\r\n\r\n");
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* this next line is so that we talk to NCSA 1.5 which blatantly
|
|
Packit |
90a5c9 |
* breaks the http specifaction
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!s) {
|
|
Packit |
90a5c9 |
s = strstr(c->cbuff, "\n\n");
|
|
Packit |
90a5c9 |
l = 2;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!s) {
|
|
Packit |
90a5c9 |
/* read rest next time */
|
|
Packit |
90a5c9 |
if (space) {
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* header is in invalid or too big - close connection */
|
|
Packit |
90a5c9 |
set_conn_state(c, STATE_UNCONNECTED);
|
|
Packit |
90a5c9 |
apr_socket_close(c->aprsock);
|
|
Packit |
90a5c9 |
err_response++;
|
|
Packit |
90a5c9 |
if (bad++ > 10) {
|
|
Packit |
90a5c9 |
err("\nTest aborted after 10 failures\n\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
start_connect(c);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* have full header */
|
|
Packit |
90a5c9 |
if (!good) {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* this is first time, extract some interesting info
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
char *p, *q;
|
|
Packit |
90a5c9 |
size_t len = 0;
|
|
Packit |
90a5c9 |
p = xstrcasestr(c->cbuff, "Server:");
|
|
Packit |
90a5c9 |
q = servername;
|
|
Packit |
90a5c9 |
if (p) {
|
|
Packit |
90a5c9 |
p += 8;
|
|
Packit |
90a5c9 |
/* -1 to not overwrite last '\0' byte */
|
|
Packit |
90a5c9 |
while (*p > 32 && len++ < sizeof(servername) - 1)
|
|
Packit |
90a5c9 |
*q++ = *p++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
*q = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* XXX: this parsing isn't even remotely HTTP compliant... but in
|
|
Packit |
90a5c9 |
* the interest of speed it doesn't totally have to be, it just
|
|
Packit |
90a5c9 |
* needs to be extended to handle whatever servers folks want to
|
|
Packit |
90a5c9 |
* test against. -djg
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* check response code */
|
|
Packit |
90a5c9 |
part = strstr(c->cbuff, "HTTP"); /* really HTTP/1.x_ */
|
|
Packit |
90a5c9 |
if (part && strlen(part) > strlen("HTTP/1.x_")) {
|
|
Packit |
90a5c9 |
strncpy(respcode, (part + strlen("HTTP/1.x_")), 3);
|
|
Packit |
90a5c9 |
respcode[3] = '\0';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
strcpy(respcode, "500");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (respcode[0] != '2') {
|
|
Packit |
90a5c9 |
err_response++;
|
|
Packit |
90a5c9 |
if (verbosity >= 2)
|
|
Packit |
90a5c9 |
printf("WARNING: Response code not 2xx (%s)\n", respcode);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (verbosity >= 3) {
|
|
Packit |
90a5c9 |
printf("LOG: Response code = %s\n", respcode);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
c->gotheader = 1;
|
|
Packit |
90a5c9 |
*s = 0; /* terminate at end of header */
|
|
Packit |
90a5c9 |
if (keepalive && xstrcasestr(c->cbuff, "Keep-Alive")) {
|
|
Packit |
90a5c9 |
char *cl;
|
|
Packit |
90a5c9 |
c->keepalive = 1;
|
|
Packit |
90a5c9 |
cl = xstrcasestr(c->cbuff, "Content-Length:");
|
|
Packit |
90a5c9 |
if (cl && method != HEAD) {
|
|
Packit |
90a5c9 |
/* response to HEAD doesn't have entity body */
|
|
Packit |
90a5c9 |
c->length = atoi(cl + 16);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
c->length = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
c->bread += c->cbx - (s + l - c->cbuff) + r - tocopy;
|
|
Packit |
90a5c9 |
totalbread += c->bread;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* We have received the header, so we know this destination socket
|
|
Packit |
90a5c9 |
* address is working, so initialize all remaining requests. */
|
|
Packit |
90a5c9 |
if (!requests_initialized) {
|
|
Packit |
90a5c9 |
for (i = 1; i < concurrency; i++) {
|
|
Packit |
90a5c9 |
con[i].socknum = i;
|
|
Packit |
90a5c9 |
start_connect(&con[i]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
requests_initialized = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* outside header, everything we have read is entity body */
|
|
Packit |
90a5c9 |
c->bread += r;
|
|
Packit |
90a5c9 |
totalbread += r;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (r == sizeof(buffer) && c->bread < c->length) {
|
|
Packit |
90a5c9 |
/* read was full, try more immediately (nonblocking already) */
|
|
Packit |
90a5c9 |
goto read_more;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (c->keepalive && (c->bread >= c->length)) {
|
|
Packit |
90a5c9 |
/* finished a keep-alive connection */
|
|
Packit |
90a5c9 |
good++;
|
|
Packit |
90a5c9 |
/* save out time */
|
|
Packit |
90a5c9 |
if (good == 1) {
|
|
Packit |
90a5c9 |
/* first time here */
|
|
Packit |
90a5c9 |
doclen = c->bread;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if ((c->bread != doclen) && !nolength) {
|
|
Packit |
90a5c9 |
bad++;
|
|
Packit |
90a5c9 |
err_length++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (done < requests) {
|
|
Packit |
90a5c9 |
struct data *s = &stats[done++];
|
|
Packit |
90a5c9 |
doneka++;
|
|
Packit |
90a5c9 |
c->done = apr_time_now();
|
|
Packit |
90a5c9 |
s->starttime = c->start;
|
|
Packit |
90a5c9 |
s->ctime = ap_max(0, c->connect - c->start);
|
|
Packit |
90a5c9 |
s->time = ap_max(0, c->done - c->start);
|
|
Packit |
90a5c9 |
s->waittime = ap_max(0, c->beginread - c->endwrite);
|
|
Packit |
90a5c9 |
if (heartbeatres && !(done % heartbeatres)) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "Completed %d requests\n", done);
|
|
Packit |
90a5c9 |
fflush(stderr);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
c->keepalive = 0;
|
|
Packit |
90a5c9 |
c->length = 0;
|
|
Packit |
90a5c9 |
c->gotheader = 0;
|
|
Packit |
90a5c9 |
c->cbx = 0;
|
|
Packit |
90a5c9 |
c->read = c->bread = 0;
|
|
Packit |
90a5c9 |
/* zero connect time with keep-alive */
|
|
Packit |
90a5c9 |
c->start = c->connect = lasttime = apr_time_now();
|
|
Packit |
90a5c9 |
set_conn_state(c, STATE_CONNECTED);
|
|
Packit |
90a5c9 |
write_request(c);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* --------------------------------------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* run the tests */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void test(void)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_time_t stoptime;
|
|
Packit |
90a5c9 |
apr_int16_t rtnev;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
int snprintf_res = 0;
|
|
Packit |
90a5c9 |
#ifdef NOT_ASCII
|
|
Packit |
90a5c9 |
apr_size_t inbytes_left, outbytes_left;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (isproxy) {
|
|
Packit |
90a5c9 |
connecthost = apr_pstrdup(cntxt, proxyhost);
|
|
Packit |
90a5c9 |
connectport = proxyport;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
connecthost = apr_pstrdup(cntxt, hostname);
|
|
Packit |
90a5c9 |
connectport = port;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!use_html) {
|
|
Packit |
90a5c9 |
printf("Benchmarking %s ", hostname);
|
|
Packit |
90a5c9 |
if (isproxy)
|
|
Packit |
90a5c9 |
printf("[through %s:%d] ", proxyhost, proxyport);
|
|
Packit |
90a5c9 |
printf("(be patient)%s",
|
|
Packit |
90a5c9 |
(heartbeatres ? "\n" : "..."));
|
|
Packit |
90a5c9 |
fflush(stdout);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
con = xcalloc(concurrency, sizeof(struct connection));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* XXX: a way to calculate the stats without requiring O(requests) memory
|
|
Packit |
90a5c9 |
* XXX: would be nice.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
stats = xcalloc(requests, sizeof(struct data));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((status = apr_pollset_create(&readbits, concurrency, cntxt,
|
|
Packit |
90a5c9 |
APR_POLLSET_NOCOPY)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
apr_err("apr_pollset_create failed", status);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* add default headers if necessary */
|
|
Packit |
90a5c9 |
if (!opt_host) {
|
|
Packit |
90a5c9 |
/* Host: header not overridden, add default value to hdrs */
|
|
Packit |
90a5c9 |
hdrs = apr_pstrcat(cntxt, hdrs, "Host: ", host_field, colonhost, "\r\n", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* Header overridden, no need to add, as it is already in hdrs */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSEXT
|
|
Packit |
90a5c9 |
if (is_ssl && tls_use_sni) {
|
|
Packit |
90a5c9 |
apr_ipsubnet_t *ip;
|
|
Packit |
90a5c9 |
if (((tls_sni = opt_host) || (tls_sni = hostname)) &&
|
|
Packit |
90a5c9 |
(!*tls_sni || apr_ipsubnet_create(&ip, tls_sni, NULL,
|
|
Packit |
90a5c9 |
cntxt) == APR_SUCCESS)) {
|
|
Packit |
90a5c9 |
/* IP not allowed in TLS SNI extension */
|
|
Packit |
90a5c9 |
tls_sni = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!opt_useragent) {
|
|
Packit |
90a5c9 |
/* User-Agent: header not overridden, add default value to hdrs */
|
|
Packit |
90a5c9 |
hdrs = apr_pstrcat(cntxt, hdrs, "User-Agent: ApacheBench/", AP_AB_BASEREVISION, "\r\n", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* Header overridden, no need to add, as it is already in hdrs */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!opt_accept) {
|
|
Packit |
90a5c9 |
/* Accept: header not overridden, add default value to hdrs */
|
|
Packit |
90a5c9 |
hdrs = apr_pstrcat(cntxt, hdrs, "Accept: */*\r\n", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* Header overridden, no need to add, as it is already in hdrs */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* setup request */
|
|
Packit |
90a5c9 |
if (!send_body) {
|
|
Packit |
90a5c9 |
snprintf_res = apr_snprintf(request, sizeof(_request),
|
|
Packit |
90a5c9 |
"%s %s HTTP/1.0\r\n"
|
|
Packit |
90a5c9 |
"%s" "%s" "%s"
|
|
Packit |
90a5c9 |
"%s" "\r\n",
|
|
Packit |
90a5c9 |
method_str[method],
|
|
Packit |
90a5c9 |
(isproxy) ? fullurl : path,
|
|
Packit |
90a5c9 |
keepalive ? "Connection: Keep-Alive\r\n" : "",
|
|
Packit |
90a5c9 |
cookie, auth, hdrs);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
snprintf_res = apr_snprintf(request, sizeof(_request),
|
|
Packit |
90a5c9 |
"%s %s HTTP/1.0\r\n"
|
|
Packit |
90a5c9 |
"%s" "%s" "%s"
|
|
Packit |
90a5c9 |
"Content-length: %" APR_SIZE_T_FMT "\r\n"
|
|
Packit |
90a5c9 |
"Content-type: %s\r\n"
|
|
Packit |
90a5c9 |
"%s"
|
|
Packit |
90a5c9 |
"\r\n",
|
|
Packit |
90a5c9 |
method_str[method],
|
|
Packit |
90a5c9 |
(isproxy) ? fullurl : path,
|
|
Packit |
90a5c9 |
keepalive ? "Connection: Keep-Alive\r\n" : "",
|
|
Packit |
90a5c9 |
cookie, auth,
|
|
Packit |
90a5c9 |
postlen,
|
|
Packit |
90a5c9 |
(content_type != NULL) ? content_type : "text/plain", hdrs);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (snprintf_res >= sizeof(_request)) {
|
|
Packit |
90a5c9 |
err("Request too long\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (verbosity >= 2)
|
|
Packit |
90a5c9 |
printf("INFO: %s header == \n---\n%s\n---\n",
|
|
Packit |
90a5c9 |
method_str[method], request);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
reqlen = strlen(request);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Combine headers and (optional) post file into one continuous buffer
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (send_body) {
|
|
Packit |
90a5c9 |
char *buff = xmalloc(postlen + reqlen + 1);
|
|
Packit |
90a5c9 |
strcpy(buff, request);
|
|
Packit |
90a5c9 |
memcpy(buff + reqlen, postdata, postlen);
|
|
Packit |
90a5c9 |
request = buff;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef NOT_ASCII
|
|
Packit |
90a5c9 |
inbytes_left = outbytes_left = reqlen;
|
|
Packit |
90a5c9 |
status = apr_xlate_conv_buffer(to_ascii, request, &inbytes_left,
|
|
Packit |
90a5c9 |
request, &outbytes_left);
|
|
Packit |
90a5c9 |
if (status || inbytes_left || outbytes_left) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "only simple translation is supported (%d/%"
|
|
Packit |
90a5c9 |
APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT ")\n",
|
|
Packit |
90a5c9 |
status, inbytes_left, outbytes_left);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif /* NOT_ASCII */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (myhost) {
|
|
Packit |
90a5c9 |
/* This only needs to be done once */
|
|
Packit |
90a5c9 |
if ((rv = apr_sockaddr_info_get(&mysa, myhost, APR_UNSPEC, 0, 0, cntxt)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
char buf[120];
|
|
Packit |
90a5c9 |
apr_snprintf(buf, sizeof(buf),
|
|
Packit |
90a5c9 |
"apr_sockaddr_info_get() for %s", myhost);
|
|
Packit |
90a5c9 |
apr_err(buf, rv);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* This too */
|
|
Packit |
90a5c9 |
if ((rv = apr_sockaddr_info_get(&destsa, connecthost,
|
|
Packit |
90a5c9 |
myhost ? mysa->family : APR_UNSPEC,
|
|
Packit |
90a5c9 |
connectport, 0, cntxt))
|
|
Packit |
90a5c9 |
!= APR_SUCCESS) {
|
|
Packit |
90a5c9 |
char buf[120];
|
|
Packit |
90a5c9 |
apr_snprintf(buf, sizeof(buf),
|
|
Packit |
90a5c9 |
"apr_sockaddr_info_get() for %s", connecthost);
|
|
Packit |
90a5c9 |
apr_err(buf, rv);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* ok - lets start */
|
|
Packit |
90a5c9 |
start = lasttime = apr_time_now();
|
|
Packit |
90a5c9 |
stoptime = tlimit ? (start + apr_time_from_sec(tlimit)) : AB_MAX;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef SIGINT
|
|
Packit |
90a5c9 |
/* Output the results if the user terminates the run early. */
|
|
Packit |
90a5c9 |
apr_signal(SIGINT, output_results);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* initialise first connection to determine destination socket address
|
|
Packit |
90a5c9 |
* which should be used for next connections. */
|
|
Packit |
90a5c9 |
con[0].socknum = 0;
|
|
Packit |
90a5c9 |
start_connect(&con[0]);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
do {
|
|
Packit |
90a5c9 |
apr_int32_t n;
|
|
Packit |
90a5c9 |
const apr_pollfd_t *pollresults, *pollfd;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
n = concurrency;
|
|
Packit |
90a5c9 |
do {
|
|
Packit |
90a5c9 |
status = apr_pollset_poll(readbits, aprtimeout, &n, &pollresults);
|
|
Packit |
90a5c9 |
} while (APR_STATUS_IS_EINTR(status));
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS)
|
|
Packit |
90a5c9 |
apr_err("apr_pollset_poll", status);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (i = 0, pollfd = pollresults; i < n; i++, pollfd++) {
|
|
Packit |
90a5c9 |
struct connection *c;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
c = pollfd->client_data;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If the connection isn't connected how can we check it?
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (c->state == STATE_UNCONNECTED)
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rtnev = pollfd->rtnevents;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
if (c->state == STATE_CONNECTED && c->ssl && SSL_in_init(c->ssl)) {
|
|
Packit |
90a5c9 |
ssl_proceed_handshake(c);
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Notes: APR_POLLHUP is set after FIN is received on some
|
|
Packit |
90a5c9 |
* systems, so treat that like APR_POLLIN so that we try to read
|
|
Packit |
90a5c9 |
* again.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Some systems return APR_POLLERR with APR_POLLHUP. We need to
|
|
Packit |
90a5c9 |
* call read_connection() for APR_POLLHUP, so check for
|
|
Packit |
90a5c9 |
* APR_POLLHUP first so that a closed connection isn't treated
|
|
Packit |
90a5c9 |
* like an I/O error. If it is, we never figure out that the
|
|
Packit |
90a5c9 |
* connection is done and we loop here endlessly calling
|
|
Packit |
90a5c9 |
* apr_poll().
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((rtnev & APR_POLLIN) || (rtnev & APR_POLLPRI) || (rtnev & APR_POLLHUP))
|
|
Packit |
90a5c9 |
read_connection(c);
|
|
Packit |
90a5c9 |
if ((rtnev & APR_POLLERR) || (rtnev & APR_POLLNVAL)) {
|
|
Packit |
90a5c9 |
if (destsa->next && c->state == STATE_CONNECTING && good == 0) {
|
|
Packit |
90a5c9 |
destsa = destsa->next;
|
|
Packit |
90a5c9 |
start_connect(c);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
bad++;
|
|
Packit |
90a5c9 |
err_except++;
|
|
Packit |
90a5c9 |
/* avoid apr_poll/EINPROGRESS loop on HP-UX, let recv discover ECONNREFUSED */
|
|
Packit |
90a5c9 |
if (c->state == STATE_CONNECTING) {
|
|
Packit |
90a5c9 |
read_connection(c);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
start_connect(c);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (rtnev & APR_POLLOUT) {
|
|
Packit |
90a5c9 |
if (c->state == STATE_CONNECTING) {
|
|
Packit |
90a5c9 |
/* call connect() again to detect errors */
|
|
Packit |
90a5c9 |
rv = apr_socket_connect(c->aprsock, destsa);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
set_conn_state(c, STATE_UNCONNECTED);
|
|
Packit |
90a5c9 |
apr_socket_close(c->aprsock);
|
|
Packit |
90a5c9 |
err_conn++;
|
|
Packit |
90a5c9 |
if (bad++ > 10) {
|
|
Packit |
90a5c9 |
fprintf(stderr,
|
|
Packit |
90a5c9 |
"\nTest aborted after 10 failures\n\n");
|
|
Packit |
90a5c9 |
apr_err("apr_socket_connect()", rv);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
start_connect(c);
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
set_conn_state(c, STATE_CONNECTED);
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
if (c->ssl)
|
|
Packit |
90a5c9 |
ssl_proceed_handshake(c);
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
write_request(c);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* POLLOUT is one shot */
|
|
Packit |
90a5c9 |
set_polled_events(c, APR_POLLIN);
|
|
Packit |
90a5c9 |
if (c->state == STATE_READ) {
|
|
Packit |
90a5c9 |
read_connection(c);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
write_request(c);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
} while (lasttime < stoptime && done < requests);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (heartbeatres)
|
|
Packit |
90a5c9 |
fprintf(stderr, "Finished %d requests\n", done);
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
printf("..done\n");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (use_html)
|
|
Packit |
90a5c9 |
output_html_results();
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
output_results(0);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* ------------------------------------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* display copyright information */
|
|
Packit |
90a5c9 |
static void copyright(void)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (!use_html) {
|
|
Packit |
90a5c9 |
printf("This is ApacheBench, Version %s\n", AP_AB_BASEREVISION " <$Revision: 1843412 $>");
|
|
Packit |
90a5c9 |
printf("Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\n");
|
|
Packit |
90a5c9 |
printf("Licensed to The Apache Software Foundation, http://www.apache.org/\n");
|
|
Packit |
90a5c9 |
printf("\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
printf("\n");
|
|
Packit |
90a5c9 |
printf(" This is ApacheBench, Version %s <%s> \n", AP_AB_BASEREVISION, "$Revision: 1843412 $");
|
|
Packit |
90a5c9 |
printf(" Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ \n");
|
|
Packit |
90a5c9 |
printf(" Licensed to The Apache Software Foundation, http://www.apache.org/ \n");
|
|
Packit |
90a5c9 |
printf("\n\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* display usage information */
|
|
Packit |
90a5c9 |
static void usage(const char *progname)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
fprintf(stderr, "Usage: %s [options] [http"
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
"[s]"
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
"://]hostname[:port]/path\n", progname);
|
|
Packit |
90a5c9 |
/* 80 column ruler: ********************************************************************************
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
fprintf(stderr, "Options are:\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -n requests Number of requests to perform\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -c concurrency Number of multiple requests to make at a time\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -t timelimit Seconds to max. to spend on benchmarking\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " This implies -n 50000\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -s timeout Seconds to max. wait for each response\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " Default is 30 seconds\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -b windowsize Size of TCP send/receive buffer, in bytes\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -B address Address to bind to when making outgoing connections\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -p postfile File containing data to POST. Remember also to set -T\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -u putfile File containing data to PUT. Remember also to set -T\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -T content-type Content-type header to use for POST/PUT data, eg.\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " 'application/x-www-form-urlencoded'\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " Default is 'text/plain'\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -v verbosity How much troubleshooting info to print\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -w Print out results in HTML tables\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -i Use HEAD instead of GET\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -x attributes String to insert as table attributes\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -y attributes String to insert as tr attributes\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -z attributes String to insert as td or th attributes\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -C attribute Add cookie, eg. 'Apache=1234'. (repeatable)\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " Inserted after all normal header lines. (repeatable)\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -A attribute Add Basic WWW Authentication, the attributes\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " are a colon separated username and password.\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -P attribute Add Basic Proxy Authentication, the attributes\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " are a colon separated username and password.\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -X proxy:port Proxyserver and port number to use\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -V Print version number and exit\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -k Use HTTP KeepAlive feature\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -d Do not show percentiles served table.\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -S Do not show confidence estimators and warnings.\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -q Do not show progress when doing more than 150 requests\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -l Accept variable document length (use this for dynamic pages)\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -g filename Output collected data to gnuplot format file.\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -e filename Output CSV file with percentages served\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -r Don't exit on socket receive errors.\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -m method Method name\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -h Display usage information (this message)\n");
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_SSL2
|
|
Packit |
90a5c9 |
#define SSL2_HELP_MSG "SSL2, "
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
#define SSL2_HELP_MSG ""
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_SSL3
|
|
Packit |
90a5c9 |
#define SSL3_HELP_MSG "SSL3, "
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
#define SSL3_HELP_MSG ""
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSV1_X
|
|
Packit |
90a5c9 |
#define TLS1_X_HELP_MSG ", TLS1.1, TLS1.2"
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
#define TLS1_X_HELP_MSG ""
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSEXT
|
|
Packit |
90a5c9 |
fprintf(stderr, " -I Disable TLS Server Name Indication (SNI) extension\n");
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
fprintf(stderr, " -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -f protocol Specify SSL/TLS protocol\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " (" SSL2_HELP_MSG SSL3_HELP_MSG "TLS1" TLS1_X_HELP_MSG " or ALL)\n");
|
|
Packit |
90a5c9 |
fprintf(stderr, " -E certfile Specify optional client certificate chain and private key\n");
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
exit(EINVAL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* ------------------------------------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* split URL into parts */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int parse_url(const char *url)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *cp;
|
|
Packit |
90a5c9 |
char *h;
|
|
Packit |
90a5c9 |
char *scope_id;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Save a copy for the proxy */
|
|
Packit |
90a5c9 |
fullurl = apr_pstrdup(cntxt, url);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (strlen(url) > 7 && strncmp(url, "http://", 7) == 0) {
|
|
Packit |
90a5c9 |
url += 7;
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
is_ssl = 0;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
if (strlen(url) > 8 && strncmp(url, "https://", 8) == 0) {
|
|
Packit |
90a5c9 |
url += 8;
|
|
Packit |
90a5c9 |
is_ssl = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
if (strlen(url) > 8 && strncmp(url, "https://", 8) == 0) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "SSL not compiled in; no https support\n");
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((cp = strchr(url, '/')) == NULL)
|
|
Packit |
90a5c9 |
return 1;
|
|
Packit |
90a5c9 |
h = apr_pstrmemdup(cntxt, url, cp - url);
|
|
Packit |
90a5c9 |
rv = apr_parse_addr_port(&hostname, &scope_id, &port, h, cntxt);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS || !hostname || scope_id) {
|
|
Packit |
90a5c9 |
return 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
path = apr_pstrdup(cntxt, cp);
|
|
Packit |
90a5c9 |
*cp = '\0';
|
|
Packit |
90a5c9 |
if (*url == '[') { /* IPv6 numeric address string */
|
|
Packit |
90a5c9 |
host_field = apr_psprintf(cntxt, "[%s]", hostname);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
host_field = hostname;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (port == 0) { /* no port specified */
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
if (is_ssl)
|
|
Packit |
90a5c9 |
port = 443;
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
port = 80;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
is_ssl && (port != 443)) || (!is_ssl &&
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
(port != 80)))
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
colonhost = apr_psprintf(cntxt,":%d",port);
|
|
Packit |
90a5c9 |
} else
|
|
Packit |
90a5c9 |
colonhost = "";
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* ------------------------------------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* read data to POST/PUT from file, save contents and length */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t open_postfile(const char *pfile)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_file_t *postfd;
|
|
Packit |
90a5c9 |
apr_finfo_t finfo;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
char errmsg[120];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = apr_file_open(&postfd, pfile, APR_READ, APR_OS_DEFAULT, cntxt);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "ab: Could not open POST data file (%s): %s\n", pfile,
|
|
Packit |
90a5c9 |
apr_strerror(rv, errmsg, sizeof errmsg));
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = apr_file_info_get(&finfo, APR_FINFO_NORM, postfd);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "ab: Could not stat POST data file (%s): %s\n", pfile,
|
|
Packit |
90a5c9 |
apr_strerror(rv, errmsg, sizeof errmsg));
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
postlen = (apr_size_t)finfo.size;
|
|
Packit |
90a5c9 |
postdata = xmalloc(postlen);
|
|
Packit |
90a5c9 |
rv = apr_file_read_full(postfd, postdata, postlen, NULL);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "ab: Could not read POST data file: %s\n",
|
|
Packit |
90a5c9 |
apr_strerror(rv, errmsg, sizeof errmsg));
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
apr_file_close(postfd);
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* ------------------------------------------------------- */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* sort out command-line args and call test */
|
|
Packit |
90a5c9 |
int main(int argc, const char * const argv[])
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int l;
|
|
Packit |
90a5c9 |
char tmp[1024];
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
apr_getopt_t *opt;
|
|
Packit |
90a5c9 |
const char *opt_arg;
|
|
Packit |
90a5c9 |
char c;
|
|
Packit |
90a5c9 |
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
Packit |
90a5c9 |
int max_prot = TLS1_2_VERSION;
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_SSL3
|
|
Packit |
90a5c9 |
int min_prot = SSL3_VERSION;
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
int min_prot = TLS1_VERSION;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#endif /* #if OPENSSL_VERSION_NUMBER >= 0x10100000L */
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
AB_SSL_METHOD_CONST SSL_METHOD *meth = SSLv23_client_method();
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* table defaults */
|
|
Packit |
90a5c9 |
tablestring = "";
|
|
Packit |
90a5c9 |
trstring = "";
|
|
Packit |
90a5c9 |
tdstring = "bgcolor=white";
|
|
Packit |
90a5c9 |
cookie = "";
|
|
Packit |
90a5c9 |
auth = "";
|
|
Packit |
90a5c9 |
proxyhost = "";
|
|
Packit |
90a5c9 |
hdrs = "";
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_app_initialize(&argc, &argv, NULL);
|
|
Packit |
90a5c9 |
atexit(apr_terminate);
|
|
Packit |
90a5c9 |
apr_pool_create(&cntxt, NULL);
|
|
Packit |
90a5c9 |
apr_pool_abort_set(abort_on_oom, cntxt);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef NOT_ASCII
|
|
Packit |
90a5c9 |
status = apr_xlate_open(&to_ascii, "ISO-8859-1", APR_DEFAULT_CHARSET, cntxt);
|
|
Packit |
90a5c9 |
if (status) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "apr_xlate_open(to ASCII)->%d\n", status);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
status = apr_xlate_open(&from_ascii, APR_DEFAULT_CHARSET, "ISO-8859-1", cntxt);
|
|
Packit |
90a5c9 |
if (status) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "apr_xlate_open(from ASCII)->%d\n", status);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
status = apr_base64init_ebcdic(to_ascii, from_ascii);
|
|
Packit |
90a5c9 |
if (status) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "apr_base64init_ebcdic()->%d\n", status);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
myhost = NULL; /* 0.0.0.0 or :: */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_getopt_init(&opt, cntxt, argc, argv);
|
|
Packit |
90a5c9 |
while ((status = apr_getopt(opt, "n:c:t:s:b:T:p:u:v:lrkVhwiIx:y:z:C:H:P:A:g:X:de:SqB:m:"
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
"Z:f:E:"
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
,&c, &opt_arg)) == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
switch (c) {
|
|
Packit |
90a5c9 |
case 'n':
|
|
Packit |
90a5c9 |
requests = atoi(opt_arg);
|
|
Packit |
90a5c9 |
if (requests <= 0) {
|
|
Packit |
90a5c9 |
err("Invalid number of requests\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'k':
|
|
Packit |
90a5c9 |
keepalive = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'q':
|
|
Packit |
90a5c9 |
heartbeatres = 0;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'c':
|
|
Packit |
90a5c9 |
concurrency = atoi(opt_arg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'b':
|
|
Packit |
90a5c9 |
windowsize = atoi(opt_arg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'i':
|
|
Packit |
90a5c9 |
if (method != NO_METH)
|
|
Packit |
90a5c9 |
err("Cannot mix HEAD with other methods\n");
|
|
Packit |
90a5c9 |
method = HEAD;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'g':
|
|
Packit |
90a5c9 |
gnuplot = xstrdup(opt_arg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'd':
|
|
Packit |
90a5c9 |
percentile = 0;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'e':
|
|
Packit |
90a5c9 |
csvperc = xstrdup(opt_arg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'S':
|
|
Packit |
90a5c9 |
confidence = 0;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 's':
|
|
Packit |
90a5c9 |
aprtimeout = apr_time_from_sec(atoi(opt_arg)); /* timeout value */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'p':
|
|
Packit |
90a5c9 |
if (method != NO_METH)
|
|
Packit |
90a5c9 |
err("Cannot mix POST with other methods\n");
|
|
Packit |
90a5c9 |
if (open_postfile(opt_arg) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
method = POST;
|
|
Packit |
90a5c9 |
send_body = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'u':
|
|
Packit |
90a5c9 |
if (method != NO_METH)
|
|
Packit |
90a5c9 |
err("Cannot mix PUT with other methods\n");
|
|
Packit |
90a5c9 |
if (open_postfile(opt_arg) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
method = PUT;
|
|
Packit |
90a5c9 |
send_body = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'l':
|
|
Packit |
90a5c9 |
nolength = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'r':
|
|
Packit |
90a5c9 |
recverrok = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'v':
|
|
Packit |
90a5c9 |
verbosity = atoi(opt_arg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 't':
|
|
Packit |
90a5c9 |
tlimit = atoi(opt_arg);
|
|
Packit |
90a5c9 |
requests = MAX_REQUESTS; /* need to size data array on
|
|
Packit |
90a5c9 |
* something */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'T':
|
|
Packit |
90a5c9 |
content_type = apr_pstrdup(cntxt, opt_arg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'C':
|
|
Packit |
90a5c9 |
cookie = apr_pstrcat(cntxt, "Cookie: ", opt_arg, "\r\n", NULL);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'A':
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* assume username passwd already to be in colon separated form.
|
|
Packit |
90a5c9 |
* Ready to be uu-encoded.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
while (apr_isspace(*opt_arg))
|
|
Packit |
90a5c9 |
opt_arg++;
|
|
Packit |
90a5c9 |
if (apr_base64_encode_len(strlen(opt_arg)) > sizeof(tmp)) {
|
|
Packit |
90a5c9 |
err("Authentication credentials too long\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
l = apr_base64_encode(tmp, opt_arg, strlen(opt_arg));
|
|
Packit |
90a5c9 |
tmp[l] = '\0';
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
auth = apr_pstrcat(cntxt, auth, "Authorization: Basic ", tmp,
|
|
Packit |
90a5c9 |
"\r\n", NULL);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'P':
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* assume username passwd already to be in colon separated form.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
while (apr_isspace(*opt_arg))
|
|
Packit |
90a5c9 |
opt_arg++;
|
|
Packit |
90a5c9 |
if (apr_base64_encode_len(strlen(opt_arg)) > sizeof(tmp)) {
|
|
Packit |
90a5c9 |
err("Proxy credentials too long\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
l = apr_base64_encode(tmp, opt_arg, strlen(opt_arg));
|
|
Packit |
90a5c9 |
tmp[l] = '\0';
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
auth = apr_pstrcat(cntxt, auth, "Proxy-Authorization: Basic ",
|
|
Packit |
90a5c9 |
tmp, "\r\n", NULL);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'H':
|
|
Packit |
90a5c9 |
hdrs = apr_pstrcat(cntxt, hdrs, opt_arg, "\r\n", NULL);
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* allow override of some of the common headers that ab adds
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (strncasecmp(opt_arg, "Host:", 5) == 0) {
|
|
Packit |
90a5c9 |
char *host;
|
|
Packit |
90a5c9 |
apr_size_t len;
|
|
Packit |
90a5c9 |
opt_arg += 5;
|
|
Packit |
90a5c9 |
while (apr_isspace(*opt_arg))
|
|
Packit |
90a5c9 |
opt_arg++;
|
|
Packit |
90a5c9 |
len = strlen(opt_arg);
|
|
Packit |
90a5c9 |
host = strdup(opt_arg);
|
|
Packit |
90a5c9 |
while (len && apr_isspace(host[len-1]))
|
|
Packit |
90a5c9 |
host[--len] = '\0';
|
|
Packit |
90a5c9 |
opt_host = host;
|
|
Packit |
90a5c9 |
} else if (strncasecmp(opt_arg, "Accept:", 7) == 0) {
|
|
Packit |
90a5c9 |
opt_accept = 1;
|
|
Packit |
90a5c9 |
} else if (strncasecmp(opt_arg, "User-Agent:", 11) == 0) {
|
|
Packit |
90a5c9 |
opt_useragent = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'w':
|
|
Packit |
90a5c9 |
use_html = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* if any of the following three are used, turn on html output
|
|
Packit |
90a5c9 |
* automatically
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
case 'x':
|
|
Packit |
90a5c9 |
use_html = 1;
|
|
Packit |
90a5c9 |
tablestring = opt_arg;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'X':
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *p;
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* assume proxy-name[:port]
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((p = strchr(opt_arg, ':'))) {
|
|
Packit |
90a5c9 |
*p = '\0';
|
|
Packit |
90a5c9 |
p++;
|
|
Packit |
90a5c9 |
proxyport = atoi(p);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
proxyhost = apr_pstrdup(cntxt, opt_arg);
|
|
Packit |
90a5c9 |
isproxy = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'y':
|
|
Packit |
90a5c9 |
use_html = 1;
|
|
Packit |
90a5c9 |
trstring = opt_arg;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'z':
|
|
Packit |
90a5c9 |
use_html = 1;
|
|
Packit |
90a5c9 |
tdstring = opt_arg;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'h':
|
|
Packit |
90a5c9 |
usage(argv[0]);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'V':
|
|
Packit |
90a5c9 |
copyright();
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
case 'B':
|
|
Packit |
90a5c9 |
myhost = apr_pstrdup(cntxt, opt_arg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'm':
|
|
Packit |
90a5c9 |
method = CUSTOM_METHOD;
|
|
Packit |
90a5c9 |
method_str[CUSTOM_METHOD] = strdup(opt_arg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
case 'Z':
|
|
Packit |
90a5c9 |
ssl_cipher = strdup(opt_arg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'E':
|
|
Packit |
90a5c9 |
ssl_cert = strdup(opt_arg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'f':
|
|
Packit |
90a5c9 |
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
|
Packit |
90a5c9 |
if (strncasecmp(opt_arg, "ALL", 3) == 0) {
|
|
Packit |
90a5c9 |
meth = SSLv23_client_method();
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_SSL2
|
|
Packit |
90a5c9 |
} else if (strncasecmp(opt_arg, "SSL2", 4) == 0) {
|
|
Packit |
90a5c9 |
meth = SSLv2_client_method();
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSEXT
|
|
Packit |
90a5c9 |
tls_use_sni = 0;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_SSL3
|
|
Packit |
90a5c9 |
} else if (strncasecmp(opt_arg, "SSL3", 4) == 0) {
|
|
Packit |
90a5c9 |
meth = SSLv3_client_method();
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSEXT
|
|
Packit |
90a5c9 |
tls_use_sni = 0;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSV1_X
|
|
Packit |
90a5c9 |
} else if (strncasecmp(opt_arg, "TLS1.1", 6) == 0) {
|
|
Packit |
90a5c9 |
meth = TLSv1_1_client_method();
|
|
Packit |
90a5c9 |
} else if (strncasecmp(opt_arg, "TLS1.2", 6) == 0) {
|
|
Packit |
90a5c9 |
meth = TLSv1_2_client_method();
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
} else if (strncasecmp(opt_arg, "TLS1", 4) == 0) {
|
|
Packit |
90a5c9 |
meth = TLSv1_client_method();
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#else /* #if OPENSSL_VERSION_NUMBER < 0x10100000L */
|
|
Packit |
90a5c9 |
meth = TLS_client_method();
|
|
Packit |
90a5c9 |
if (strncasecmp(opt_arg, "ALL", 3) == 0) {
|
|
Packit |
90a5c9 |
max_prot = TLS1_2_VERSION;
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_SSL3
|
|
Packit |
90a5c9 |
min_prot = SSL3_VERSION;
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
min_prot = TLS1_VERSION;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#ifndef OPENSSL_NO_SSL3
|
|
Packit |
90a5c9 |
} else if (strncasecmp(opt_arg, "SSL3", 4) == 0) {
|
|
Packit |
90a5c9 |
max_prot = SSL3_VERSION;
|
|
Packit |
90a5c9 |
min_prot = SSL3_VERSION;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
} else if (strncasecmp(opt_arg, "TLS1.1", 6) == 0) {
|
|
Packit |
90a5c9 |
max_prot = TLS1_1_VERSION;
|
|
Packit |
90a5c9 |
min_prot = TLS1_1_VERSION;
|
|
Packit |
90a5c9 |
} else if (strncasecmp(opt_arg, "TLS1.2", 6) == 0) {
|
|
Packit |
90a5c9 |
max_prot = TLS1_2_VERSION;
|
|
Packit |
90a5c9 |
min_prot = TLS1_2_VERSION;
|
|
Packit |
90a5c9 |
} else if (strncasecmp(opt_arg, "TLS1", 4) == 0) {
|
|
Packit |
90a5c9 |
max_prot = TLS1_VERSION;
|
|
Packit |
90a5c9 |
min_prot = TLS1_VERSION;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif /* #if OPENSSL_VERSION_NUMBER < 0x10100000L */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
#ifdef HAVE_TLSEXT
|
|
Packit |
90a5c9 |
case 'I':
|
|
Packit |
90a5c9 |
tls_use_sni = 0;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (opt->ind != argc - 1) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "%s: wrong number of arguments\n", argv[0]);
|
|
Packit |
90a5c9 |
usage(argv[0]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (method == NO_METH) {
|
|
Packit |
90a5c9 |
method = GET;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (parse_url(apr_pstrdup(cntxt, opt->argv[opt->ind++]))) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "%s: invalid URL\n", argv[0]);
|
|
Packit |
90a5c9 |
usage(argv[0]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((concurrency < 0) || (concurrency > MAX_CONCURRENCY)) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "%s: Invalid Concurrency [Range 0..%d]\n",
|
|
Packit |
90a5c9 |
argv[0], MAX_CONCURRENCY);
|
|
Packit |
90a5c9 |
usage(argv[0]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (concurrency > requests) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "%s: Cannot use concurrency level greater than "
|
|
Packit |
90a5c9 |
"total number of requests\n", argv[0]);
|
|
Packit |
90a5c9 |
usage(argv[0]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((heartbeatres) && (requests > 150)) {
|
|
Packit |
90a5c9 |
heartbeatres = requests / 10; /* Print line every 10% of requests */
|
|
Packit |
90a5c9 |
if (heartbeatres < 100)
|
|
Packit |
90a5c9 |
heartbeatres = 100; /* but never more often than once every 100
|
|
Packit |
90a5c9 |
* connections. */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
heartbeatres = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef USE_SSL
|
|
Packit |
90a5c9 |
#ifdef RSAREF
|
|
Packit |
90a5c9 |
R_malloc_init();
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
|
Packit |
90a5c9 |
CRYPTO_malloc_init();
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
SSL_load_error_strings();
|
|
Packit |
90a5c9 |
SSL_library_init();
|
|
Packit |
90a5c9 |
bio_out=BIO_new_fp(stdout,BIO_NOCLOSE);
|
|
Packit |
90a5c9 |
bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(ssl_ctx = SSL_CTX_new(meth))) {
|
|
Packit |
90a5c9 |
BIO_printf(bio_err, "Could not initialize SSL Context.\n");
|
|
Packit |
90a5c9 |
ERR_print_errors(bio_err);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL);
|
|
Packit |
90a5c9 |
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
Packit |
90a5c9 |
SSL_CTX_set_max_proto_version(ssl_ctx, max_prot);
|
|
Packit |
90a5c9 |
SSL_CTX_set_min_proto_version(ssl_ctx, min_prot);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#ifdef SSL_MODE_RELEASE_BUFFERS
|
|
Packit |
90a5c9 |
/* Keep memory usage as low as possible */
|
|
Packit |
90a5c9 |
SSL_CTX_set_mode (ssl_ctx, SSL_MODE_RELEASE_BUFFERS);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
if (ssl_cipher != NULL) {
|
|
Packit |
90a5c9 |
if (!SSL_CTX_set_cipher_list(ssl_ctx, ssl_cipher)) {
|
|
Packit |
90a5c9 |
fprintf(stderr, "error setting cipher list [%s]\n", ssl_cipher);
|
|
Packit |
90a5c9 |
ERR_print_errors_fp(stderr);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (verbosity >= 3) {
|
|
Packit |
90a5c9 |
SSL_CTX_set_info_callback(ssl_ctx, ssl_state_cb);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (ssl_cert != NULL) {
|
|
Packit |
90a5c9 |
if (SSL_CTX_use_certificate_chain_file(ssl_ctx, ssl_cert) <= 0) {
|
|
Packit |
90a5c9 |
BIO_printf(bio_err, "unable to get certificate from '%s'\n",
|
|
Packit |
90a5c9 |
ssl_cert);
|
|
Packit |
90a5c9 |
ERR_print_errors(bio_err);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (SSL_CTX_use_PrivateKey_file(ssl_ctx, ssl_cert, SSL_FILETYPE_PEM) <= 0) {
|
|
Packit |
90a5c9 |
BIO_printf(bio_err, "unable to get private key from '%s'\n",
|
|
Packit |
90a5c9 |
ssl_cert);
|
|
Packit |
90a5c9 |
ERR_print_errors(bio_err);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!SSL_CTX_check_private_key(ssl_ctx)) {
|
|
Packit |
90a5c9 |
BIO_printf(bio_err,
|
|
Packit |
90a5c9 |
"private key does not match the certificate public key in %s\n", ssl_cert);
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#ifdef SIGPIPE
|
|
Packit |
90a5c9 |
apr_signal(SIGPIPE, SIG_IGN); /* Ignore writes to connections that
|
|
Packit |
90a5c9 |
* have been closed at the other end. */
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
copyright();
|
|
Packit |
90a5c9 |
test();
|
|
Packit |
90a5c9 |
apr_pool_destroy(cntxt);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|