📄 ab.c
字号:
new_pollfd.client_data = c; apr_pollset_add(readbits, &new_pollfd); } } } if (heartbeatres) fprintf(stderr, "Finished %ld requests\n", done); else printf("..done\n"); if (use_html) output_html_results(); else output_results();}/* ------------------------------------------------------- *//* display copyright information */static void copyright(void){ if (!use_html) { printf("This is ApacheBench, Version %s\n", AP_AB_BASEREVISION " <$Revision: 1.121.2.12 $> apache-2.0"); printf("Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\n"); printf("Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/\n"); printf("\n"); } else { printf("<p>\n"); printf(" This is ApacheBench, Version %s <i><%s></i> apache-2.0<br>\n", AP_AB_BASEREVISION, "$Revision: 1.121.2.12 $"); printf(" Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/<br>\n"); printf(" Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/<br>\n"); printf("</p>\n<p>\n"); }}/* display usage information */static void usage(const char *progname){ fprintf(stderr, "Usage: %s [options] [http"#ifdef USE_SSL "[s]"#endif "://]hostname[:port]/path\n", progname); fprintf(stderr, "Options are:\n"); fprintf(stderr, " -n requests Number of requests to perform\n"); fprintf(stderr, " -c concurrency Number of multiple requests to make\n"); fprintf(stderr, " -t timelimit Seconds to max. wait for responses\n"); fprintf(stderr, " -p postfile File containing data to POST\n"); fprintf(stderr, " -T content-type Content-type header for POSTing\n"); fprintf(stderr, " -v verbosity How much troubleshooting info to print\n"); fprintf(stderr, " -w Print out results in HTML tables\n"); fprintf(stderr, " -i Use HEAD instead of GET\n"); fprintf(stderr, " -x attributes String to insert as table attributes\n"); fprintf(stderr, " -y attributes String to insert as tr attributes\n"); fprintf(stderr, " -z attributes String to insert as td or th attributes\n"); fprintf(stderr, " -C attribute Add cookie, eg. 'Apache=1234. (repeatable)\n"); fprintf(stderr, " -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'\n"); fprintf(stderr, " Inserted after all normal header lines. (repeatable)\n"); fprintf(stderr, " -A attribute Add Basic WWW Authentication, the attributes\n"); fprintf(stderr, " are a colon separated username and password.\n"); fprintf(stderr, " -P attribute Add Basic Proxy Authentication, the attributes\n"); fprintf(stderr, " are a colon separated username and password.\n"); fprintf(stderr, " -X proxy:port Proxyserver and port number to use\n"); fprintf(stderr, " -V Print version number and exit\n"); fprintf(stderr, " -k Use HTTP KeepAlive feature\n"); fprintf(stderr, " -d Do not show percentiles served table.\n"); fprintf(stderr, " -S Do not show confidence estimators and warnings.\n"); fprintf(stderr, " -g filename Output collected data to gnuplot format file.\n"); fprintf(stderr, " -e filename Output CSV file with percentages served\n");#ifdef USE_SSL fprintf(stderr, " -s Use httpS instead of HTTP (SSL)\n");#endif fprintf(stderr, " -h Display usage information (this message)\n"); exit(EINVAL);}/* ------------------------------------------------------- *//* split URL into parts */static int parse_url(char *url){ char *cp; char *h; char *scope_id; apr_status_t rv; /* Save a copy for the proxy */ fullurl = apr_pstrdup(cntxt, url); if (strlen(url) > 7 && strncmp(url, "http://", 7) == 0) { url += 7;#ifdef USE_SSL ssl = 0;#endif } else#ifdef USE_SSL if (strlen(url) > 8 && strncmp(url, "https://", 8) == 0) { url += 8; ssl = 1; }#else if (strlen(url) > 8 && strncmp(url, "https://", 8) == 0) { fprintf(stderr, "SSL not compiled in; no https support\n"); exit(1); }#endif if ((cp = strchr(url, '/')) == NULL) return 1; h = apr_palloc(cntxt, cp - url + 1); memcpy(h, url, cp - url); h[cp - url] = '\0'; rv = apr_parse_addr_port(&hostname, &scope_id, &port, h, cntxt); if (rv != APR_SUCCESS || !hostname || scope_id) { return 1; } path = apr_pstrdup(cntxt, cp); *cp = '\0'; if (*url == '[') { /* IPv6 numeric address string */ host_field = apr_psprintf(cntxt, "[%s]", hostname); } else { host_field = hostname; } if (port == 0) { /* no port specified */#ifdef USE_SSL if (ssl == 1) port = 443; else#endif port = 80; } if ((#ifdef USE_SSL (ssl == 1) && (port != 443)) || (( ssl == 0 ) && #endif (port != 80))) { colonhost = apr_psprintf(cntxt,":%d",port); } else colonhost = ""; return 0;}/* ------------------------------------------------------- *//* read data to POST from file, save contents and length */static int open_postfile(const char *pfile){ apr_file_t *postfd = NULL; apr_finfo_t finfo; apr_fileperms_t mode = APR_OS_DEFAULT; apr_size_t length; apr_status_t rv; char errmsg[120]; rv = apr_file_open(&postfd, pfile, APR_READ, mode, cntxt); if (rv != APR_SUCCESS) { printf("Invalid postfile name (%s): %s\n", pfile, apr_strerror(rv, errmsg, sizeof errmsg)); return rv; } apr_file_info_get(&finfo, APR_FINFO_NORM, postfd); postlen = (apr_size_t)finfo.size; postdata = (char *) malloc(postlen); if (!postdata) { printf("Can\'t alloc postfile buffer\n"); return APR_ENOMEM; } length = postlen; rv = apr_file_read(postfd, postdata, &length); if (rv != APR_SUCCESS) { printf("error reading postfile: %s\n", apr_strerror(rv, errmsg, sizeof errmsg)); return rv; } if (length != postlen) { printf("error reading postfile: read only %" APR_SIZE_T_FMT " bytes", length); return APR_EINVAL; } apr_file_close(postfd); return 0;}/* ------------------------------------------------------- *//* sort out command-line args and call test */int main(int argc, const char * const argv[]){ int r, l; char tmp[1024]; apr_status_t status; apr_getopt_t *opt; const char *optarg; char c; /* table defaults */ tablestring = ""; trstring = ""; tdstring = "bgcolor=white"; cookie = ""; auth = ""; proxyhost[0] = '\0'; hdrs = ""; apr_app_initialize(&argc, &argv, NULL); atexit(apr_terminate); apr_pool_create(&cntxt, NULL);#ifdef NOT_ASCII status = apr_xlate_open(&to_ascii, "ISO8859-1", APR_DEFAULT_CHARSET, cntxt); if (status) { fprintf(stderr, "apr_xlate_open(to ASCII)->%d\n", status); exit(1); } status = apr_xlate_open(&from_ascii, APR_DEFAULT_CHARSET, "ISO8859-1", cntxt); if (status) { fprintf(stderr, "apr_xlate_open(from ASCII)->%d\n", status); exit(1); } status = apr_base64init_ebcdic(to_ascii, from_ascii); if (status) { fprintf(stderr, "apr_base64init_ebcdic()->%d\n", status); exit(1); }#endif apr_getopt_init(&opt, cntxt, argc, argv); while ((status = apr_getopt(opt, "n:c:t:T:p:v:kVhwix:y:z:C:H:P:A:g:X:de:Sq"#ifdef USE_SSL "s"#endif ,&c, &optarg)) == APR_SUCCESS) { switch (c) { case 's':#ifdef USE_SSL ssl = 1; break;#else fprintf(stderr, "SSL not compiled in; no https support\n"); exit(1);#endif case 'n': requests = atoi(optarg); if (!requests) { err("Invalid number of requests\n"); } break; case 'k': keepalive = 1; break; case 'q': heartbeatres = 0; break; case 'c': concurrency = atoi(optarg); break; case 'i': if (posting == 1) err("Cannot mix POST and HEAD\n"); posting = -1; break; case 'g': gnuplot = strdup(optarg); break; case 'd': percentile = 0; break; case 'e': csvperc = strdup(optarg); break; case 'S': confidence = 0; break; case 'p': if (posting != 0) err("Cannot mix POST and HEAD\n"); if (0 == (r = open_postfile(optarg))) { posting = 1; } else if (postdata) { exit(r); } break; case 'v': verbosity = atoi(optarg); break; case 't': tlimit = atoi(optarg); requests = MAX_REQUESTS; /* need to size data array on * something */ break; case 'T': strcpy(content_type, optarg); break; case 'C': cookie = apr_pstrcat(cntxt, "Cookie: ", optarg, "\r\n", NULL); break; case 'A': /* * assume username passwd already to be in colon separated form. * Ready to be uu-encoded. */ while (apr_isspace(*optarg)) optarg++; if (apr_base64_encode_len(strlen(optarg)) > sizeof(tmp)) { err("Authentication credentials too long\n"); } l = apr_base64_encode(tmp, optarg, strlen(optarg)); tmp[l] = '\0'; auth = apr_pstrcat(cntxt, auth, "Authorization: Basic ", tmp, "\r\n", NULL); break; case 'P': /* * assume username passwd already to be in colon separated form. */ while (apr_isspace(*optarg)) optarg++; if (apr_base64_encode_len(strlen(optarg)) > sizeof(tmp)) { err("Proxy credentials too long\n"); } l = apr_base64_encode(tmp, optarg, strlen(optarg)); tmp[l] = '\0'; auth = apr_pstrcat(cntxt, auth, "Proxy-Authorization: Basic ", tmp, "\r\n", NULL); break; case 'H': hdrs = apr_pstrcat(cntxt, hdrs, optarg, "\r\n", NULL); break; case 'w': use_html = 1; break; /* * if any of the following three are used, turn on html output * automatically */ case 'x': use_html = 1; tablestring = optarg; break; case 'X': { char *p; /* * assume proxy-name[:port] */ if ((p = strchr(optarg, ':'))) { *p = '\0'; p++; proxyport = atoi(p); } strcpy(proxyhost, optarg); isproxy = 1; } break; case 'y': use_html = 1; trstring = optarg; break; case 'z': use_html = 1; tdstring = optarg; break; case 'h': usage(argv[0]); break; case 'V': copyright(); return 0; } } if (opt->ind != argc - 1) { fprintf(stderr, "%s: wrong number of arguments\n", argv[0]); usage(argv[0]); } if (parse_url(apr_pstrdup(cntxt, opt->argv[opt->ind++]))) { fprintf(stderr, "%s: invalid URL\n", argv[0]); usage(argv[0]); } if ((concurrency < 0) || (concurrency > MAX_CONCURRENCY)) { fprintf(stderr, "%s: Invalid Concurrency [Range 0..%d]\n", argv[0], MAX_CONCURRENCY); usage(argv[0]); } if ((heartbeatres) && (requests > 150)) { heartbeatres = requests / 10; /* Print line every 10% of requests */ if (heartbeatres < 100) heartbeatres = 100; /* but never more often than once every 100 * connections. */ } else heartbeatres = 0;#ifdef USE_SSL#ifdef RSAREF R_malloc_init();#else CRYPTO_malloc_init();#endif SSL_load_error_strings(); SSL_library_init(); bio_out=BIO_new_fp(stdout,BIO_NOCLOSE); bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); /* TODO: Allow force SSLv2_client_method() (TLSv1?) */ if (!(ctx = SSL_CTX_new(SSLv23_client_method()))) { fprintf(stderr, "Could not init SSL CTX"); ERR_print_errors_fp(stderr); exit(1); } SSL_CTX_set_options(ctx, SSL_OP_ALL);#ifdef USE_THREADS ssl_util_thread_setup(cntxt);#endif#endif#ifdef SIGPIPE apr_signal(SIGPIPE, SIG_IGN); /* Ignore writes to connections that * have been
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -