Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions support/ab.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ struct connection {
done; /* Connection closed */

int socknum;
char c_response_code[4]; /* for response code saving */
#ifdef USE_SSL
SSL *ssl;
#endif
Expand All @@ -254,6 +255,7 @@ struct data {
apr_interval_time_t waittime; /* between request and reading response */
apr_interval_time_t ctime; /* time to connect */
apr_interval_time_t time; /* time for connection */
char response_code[4]; /* Response code */
};

#define ap_min(a,b) (((a)<(b))?(a):(b))
Expand Down Expand Up @@ -1040,7 +1042,7 @@ static void output_results(int sig)
exit(1);
}
fprintf(out, "" "Percentage served" "," "Time in ms" "\n");
for (i = 0; i < 100; i++) {
for (i = 0; i <= 100; i++) {
double t;
if (i == 0)
t = ap_double_ms(stats[0].time);
Expand All @@ -1059,17 +1061,18 @@ static void output_results(int sig)
perror("Cannot open gnuplot output file");
exit(1);
}
fprintf(out, "starttime\tseconds\tctime\tdtime\tttime\twait\n");
fprintf(out, "starttime\tseconds\tctime\tdtime\tttime\twait\tresponse_code\n");
for (i = 0; i < done; i++) {
(void) apr_ctime(tmstring, stats[i].starttime);
fprintf(out, "%s\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT
"\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT
"\t%" APR_TIME_T_FMT "\n", tmstring,
"\t%" APR_TIME_T_FMT "\t%s\n", tmstring,
apr_time_sec(stats[i].starttime),
ap_round_ms(stats[i].ctime),
ap_round_ms(stats[i].time - stats[i].ctime),
ap_round_ms(stats[i].time),
ap_round_ms(stats[i].waittime));
ap_round_ms(stats[i].waittime),
stats[i].response_code);
}
fclose(out);
}
Expand Down Expand Up @@ -1364,6 +1367,8 @@ static void close_connection(struct connection * c)
s->ctime = ap_max(0, c->connect - c->start);
s->time = ap_max(0, c->done - c->start);
s->waittime = ap_max(0, c->beginread - c->endwrite);
// Now save the connection response code over to the stats[i] response code.
memcpy(s->response_code, c->c_response_code, 4);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a null-terminated string, you should use strncpy rather than memcpy (weird to use memcpy on null-terminated strings). Also, what is the true size of c->c_response_code? Is it 4 bytes or 4 characters? How big is a character?

if (heartbeatres && !(done % heartbeatres)) {
fprintf(stderr, "Completed %d requests\n", done);
fflush(stderr);
Expand Down Expand Up @@ -1563,6 +1568,8 @@ static void read_connection(struct connection * c)
else {
strcpy(respcode, "500");
}
// save the header.
memcpy(c->c_response_code, respcode, 4);

if (respcode[0] != '2') {
err_response++;
Expand Down