in flood_profile.c [582:735]
apr_status_t run_profile(apr_pool_t *pool, config_t *config, const char * profile_name)
{
profile_events_t *events;
profile_t *profile;
report_t *report;
request_t *req;
response_t *resp;
socket_t *socket;
flood_timer_t *timer;
apr_status_t stat;
int verified;
/* init to NULL for the sake of our error checking */
events = NULL;
profile = NULL;
req = NULL;
resp = NULL;
socket = NULL;
verified = FLOOD_INVALID;
/* assign the implementations (function pointers) */
if ((stat = initialize_events(&events, profile_name, config, pool)) != APR_SUCCESS) {
return stat;
}
if (events == NULL) {
apr_file_printf(local_stderr, "Error initializing test profile.\n");
return APR_EGENERAL; /* FIXME: What error code to return? */
}
/* initialize this profile */
if ((stat = events->profile_init(&profile, config, profile_name, pool)) != APR_SUCCESS)
return stat;
/* initialize this report */
if ((stat = events->report_init(&report, config, profile_name, pool)) != APR_SUCCESS)
return stat;
/* initialize the socket */
if ((stat = events->socket_init(&socket, pool)) != APR_SUCCESS)
return stat;
timer = apr_palloc(pool, sizeof(flood_timer_t));
do {
if ((stat = events->get_next_url(&req, profile)) != APR_SUCCESS)
return stat;
/* sample timer "begin" */
timer->begin = apr_time_now();
if ((stat = events->begin_conn(socket, req, pool)) != APR_SUCCESS) {
apr_file_printf(local_stderr, "open request failed (%s).\n",
req->uri);
return stat;
}
/* connect()ion was just made, sample it */
timer->connect = apr_time_now();
/* FIXME: I don't like doing this after we've opened the socket.
* But, I'm not sure how to do it otherwise.
*/
if ((stat = events->create_req(profile, req)) != APR_SUCCESS) {
apr_file_printf(local_stderr, "create request failed (%s).\n",
req->uri);
return stat;
}
/* If we wanted to keep track of our request generation overhead,
* we could take a timer sample here */
if ((stat = events->send_req(socket, req, pool)) != APR_SUCCESS) {
apr_file_printf(local_stderr, "send request failed (%s).\n",
req->uri);
return stat;
}
/* record the time at which we finished sending the entire request */
timer->write = apr_time_now();
if ((stat = events->recv_resp(&resp, socket, pool)) != APR_SUCCESS) {
apr_file_printf(local_stderr, "receive request failed (%s).\n",
req->uri);
return stat;
}
/* record the time at which we received the first chunk of response data */
timer->read = apr_time_now();
if ((stat = events->postprocess(profile, req, resp)) != APR_SUCCESS) {
apr_file_printf(local_stderr, "postprocessing failed (%s).\n",
req->uri);
return stat;
}
if ((stat = events->verify_resp(&verified, profile, req, resp)) != APR_SUCCESS) {
apr_file_printf(local_stderr,
"Error while verifying query (%s).\n", req->uri);
return stat;
}
if ((stat = events->end_conn(socket, req, resp)) != APR_SUCCESS) {
apr_file_printf(local_stderr,
"Unable to end the connection (%s).\n", req->uri);
return stat;
}
/* record the time at which we had finished reading the entire response.
* Note: this sample includes overhead from postprocessing and verification
* and is not a good representation of raw server response speed. */
timer->close = apr_time_now();
if ((stat = events->process_stats(report, verified, req, resp, timer)) != APR_SUCCESS) {
apr_file_printf(local_stderr,
"Unable to process statistics (%s).\n", req->uri);
return stat;
}
if ((stat = events->request_destroy(req)) != APR_SUCCESS) {
apr_file_printf(local_stderr, "Error cleaning up request.\n");
return stat;
}
if ((stat = events->response_destroy(resp)) != APR_SUCCESS) {
apr_file_printf(local_stderr, "Error cleaning up Response.\n");
return stat;
}
if ((stat = events->socket_destroy(socket)) != APR_SUCCESS) {
apr_file_printf(local_stderr, "Error cleaning up Socket.\n");
return stat;
}
} while (events->loop_condition(profile));
if ((stat = events->report_stats(report)) != APR_SUCCESS) {
apr_file_printf(local_stderr, "Unable to report statistics.\n");
return stat;
}
if (events->destroy_report(report) != APR_SUCCESS) {
apr_file_printf(local_stderr, "Error cleaning up report '%s'.\n", profile_name);
return APR_EGENERAL; /* FIXME: What error code to return? */
}
if (events->profile_destroy(profile) != APR_SUCCESS) {
apr_file_printf(local_stderr, "Error cleaning up profile '%s'.\n", profile_name);
return APR_EGENERAL; /* FIXME: What error code to return? */
}
return APR_SUCCESS;
}