Stream list is now managed by queue.h SLIST macros
Этот коммит содержится в:
родитель
ffdcc7d457
Коммит
dd4bc0089b
12
src/iperf.h
12
src/iperf.h
@ -40,8 +40,8 @@ struct iperf_stream_result
|
|||||||
iperf_size_t bytes_sent_this_interval;
|
iperf_size_t bytes_sent_this_interval;
|
||||||
struct timeval start_time;
|
struct timeval start_time;
|
||||||
struct timeval end_time;
|
struct timeval end_time;
|
||||||
struct iperf_interval_results *interval_results; /* head of list */
|
struct iperf_interval_results *interval_results; // head of list
|
||||||
struct iperf_interval_results *last_interval_results; /* end of list */
|
struct iperf_interval_results *last_interval_results; // end of list
|
||||||
void *data;
|
void *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -92,7 +92,8 @@ struct iperf_stream
|
|||||||
int (*rcv) (struct iperf_stream * stream);
|
int (*rcv) (struct iperf_stream * stream);
|
||||||
int (*snd) (struct iperf_stream * stream);
|
int (*snd) (struct iperf_stream * stream);
|
||||||
|
|
||||||
struct iperf_stream *next;
|
// struct iperf_stream *next;
|
||||||
|
SLIST_ENTRY(iperf_stream) streams;
|
||||||
|
|
||||||
void *data;
|
void *data;
|
||||||
};
|
};
|
||||||
@ -155,10 +156,11 @@ struct iperf_test
|
|||||||
|
|
||||||
iperf_size_t bytes_sent;
|
iperf_size_t bytes_sent;
|
||||||
char cookie[COOKIE_SIZE];
|
char cookie[COOKIE_SIZE];
|
||||||
struct iperf_stream *streams; /* pointer to list of struct stream */
|
// struct iperf_stream *streams; /* pointer to list of struct stream */
|
||||||
|
SLIST_HEAD(slisthead, iperf_stream) streams;
|
||||||
struct iperf_settings *settings;
|
struct iperf_settings *settings;
|
||||||
|
|
||||||
SLIST_HEAD(slisthead, protocol) protocols;
|
SLIST_HEAD(plisthead, protocol) protocols;
|
||||||
|
|
||||||
/* callback functions */
|
/* callback functions */
|
||||||
void (*on_new_stream)(struct iperf_stream *);
|
void (*on_new_stream)(struct iperf_stream *);
|
||||||
|
@ -400,7 +400,8 @@ iperf_send(struct iperf_test *test)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (result > 0) {
|
if (result > 0) {
|
||||||
for (sp = test->streams; sp != NULL; sp = sp->next) {
|
// for (sp = test->streams; sp != NULL; sp = sp->next) {
|
||||||
|
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||||
if (FD_ISSET(sp->socket, &temp_write_set)) {
|
if (FD_ISSET(sp->socket, &temp_write_set)) {
|
||||||
if ((bytes_sent = sp->snd(sp)) < 0) {
|
if ((bytes_sent = sp->snd(sp)) < 0) {
|
||||||
i_errno = IESTREAMWRITE;
|
i_errno = IESTREAMWRITE;
|
||||||
@ -434,7 +435,8 @@ iperf_recv(struct iperf_test *test)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (result > 0) {
|
if (result > 0) {
|
||||||
for (sp = test->streams; sp != NULL; sp = sp->next) {
|
// for (sp = test->streams; sp != NULL; sp = sp->next) {
|
||||||
|
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||||
if (FD_ISSET(sp->socket, &temp_read_set)) {
|
if (FD_ISSET(sp->socket, &temp_read_set)) {
|
||||||
if ((bytes_sent = sp->rcv(sp)) < 0) {
|
if ((bytes_sent = sp->rcv(sp)) < 0) {
|
||||||
i_errno = IESTREAMREAD;
|
i_errno = IESTREAMREAD;
|
||||||
@ -478,7 +480,8 @@ iperf_init_test(struct iperf_test *test)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set start time */
|
/* Set start time */
|
||||||
for (sp = test->streams; sp; sp = sp->next) {
|
// for (sp = test->streams; sp; sp = sp->next) {
|
||||||
|
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||||
if (gettimeofday(&sp->result->start_time, NULL) < 0) {
|
if (gettimeofday(&sp->result->start_time, NULL) < 0) {
|
||||||
i_errno = IEINITTEST;
|
i_errno = IEINITTEST;
|
||||||
return (-1);
|
return (-1);
|
||||||
@ -691,7 +694,8 @@ iperf_exchange_results(struct iperf_test *test)
|
|||||||
/* Prepare results string and send to server */
|
/* Prepare results string and send to server */
|
||||||
results = NULL;
|
results = NULL;
|
||||||
size = 0;
|
size = 0;
|
||||||
for (sp = test->streams; sp; sp = sp->next) {
|
// for (sp = test->streams; sp; sp = sp->next) {
|
||||||
|
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||||
bytes_transferred = (test->reverse ? sp->result->bytes_received : sp->result->bytes_sent);
|
bytes_transferred = (test->reverse ? sp->result->bytes_received : sp->result->bytes_sent);
|
||||||
snprintf(buf, 128, "%d:%llu,%lf,%d,%d\n", sp->id, bytes_transferred,sp->jitter,
|
snprintf(buf, 128, "%d:%llu,%lf,%d,%d\n", sp->id, bytes_transferred,sp->jitter,
|
||||||
sp->cnt_error, sp->packet_count);
|
sp->cnt_error, sp->packet_count);
|
||||||
@ -700,7 +704,7 @@ iperf_exchange_results(struct iperf_test *test)
|
|||||||
i_errno = IEPACKAGERESULTS;
|
i_errno = IEPACKAGERESULTS;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (sp == test->streams)
|
if (sp == SLIST_FIRST(&test->streams))
|
||||||
*results = '\0';
|
*results = '\0';
|
||||||
strncat(results, buf, size+1);
|
strncat(results, buf, size+1);
|
||||||
}
|
}
|
||||||
@ -764,7 +768,8 @@ iperf_exchange_results(struct iperf_test *test)
|
|||||||
/* Prepare results string and send to client */
|
/* Prepare results string and send to client */
|
||||||
results = NULL;
|
results = NULL;
|
||||||
size = 0;
|
size = 0;
|
||||||
for (sp = test->streams; sp; sp = sp->next) {
|
// for (sp = test->streams; sp; sp = sp->next) {
|
||||||
|
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||||
bytes_transferred = (test->reverse ? sp->result->bytes_sent : sp->result->bytes_received);
|
bytes_transferred = (test->reverse ? sp->result->bytes_sent : sp->result->bytes_received);
|
||||||
snprintf(buf, 128, "%d:%llu,%lf,%d,%d\n", sp->id, bytes_transferred, sp->jitter,
|
snprintf(buf, 128, "%d:%llu,%lf,%d,%d\n", sp->id, bytes_transferred, sp->jitter,
|
||||||
sp->cnt_error, sp->packet_count);
|
sp->cnt_error, sp->packet_count);
|
||||||
@ -773,7 +778,7 @@ iperf_exchange_results(struct iperf_test *test)
|
|||||||
i_errno = IEPACKAGERESULTS;
|
i_errno = IEPACKAGERESULTS;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (sp == test->streams)
|
if (sp == SLIST_FIRST(&test->streams))
|
||||||
*results = '\0';
|
*results = '\0';
|
||||||
strncat(results, buf, size+1);
|
strncat(results, buf, size+1);
|
||||||
}
|
}
|
||||||
@ -808,7 +813,8 @@ parse_results(struct iperf_test *test, char *results)
|
|||||||
for (strp = results; *strp; strp = strchr(strp, '\n')+1) {
|
for (strp = results; *strp; strp = strchr(strp, '\n')+1) {
|
||||||
sscanf(strp, "%d:%llu,%lf,%d,%d\n", &sid, &bytes_transferred, &jitter,
|
sscanf(strp, "%d:%llu,%lf,%d,%d\n", &sid, &bytes_transferred, &jitter,
|
||||||
&cerror, &pcount);
|
&cerror, &pcount);
|
||||||
for (sp = test->streams; sp; sp = sp->next)
|
// for (sp = test->streams; sp; sp = sp->next)
|
||||||
|
SLIST_FOREACH(sp, &test->streams, streams)
|
||||||
if (sp->id == sid) break;
|
if (sp->id == sid) break;
|
||||||
if (sp == NULL) {
|
if (sp == NULL) {
|
||||||
i_errno = IESTREAMID;
|
i_errno = IESTREAMID;
|
||||||
@ -930,6 +936,7 @@ iperf_defaults(struct iperf_test * testp)
|
|||||||
memset(testp->cookie, 0, COOKIE_SIZE);
|
memset(testp->cookie, 0, COOKIE_SIZE);
|
||||||
|
|
||||||
/* Set up protocol list */
|
/* Set up protocol list */
|
||||||
|
SLIST_INIT(&testp->streams);
|
||||||
SLIST_INIT(&testp->protocols);
|
SLIST_INIT(&testp->protocols);
|
||||||
|
|
||||||
struct protocol *tcp, *udp;
|
struct protocol *tcp, *udp;
|
||||||
@ -992,7 +999,7 @@ iperf_free_test(struct iperf_test * test)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: Why are we setting these values to NULL? */
|
/* XXX: Why are we setting these values to NULL? */
|
||||||
test->streams = NULL;
|
// test->streams = NULL;
|
||||||
test->stats_callback = NULL;
|
test->stats_callback = NULL;
|
||||||
test->reporter_callback = NULL;
|
test->reporter_callback = NULL;
|
||||||
free(test);
|
free(test);
|
||||||
@ -1014,7 +1021,8 @@ iperf_stats_callback(struct iperf_test * test)
|
|||||||
struct iperf_stream_result *rp = NULL;
|
struct iperf_stream_result *rp = NULL;
|
||||||
struct iperf_interval_results *ip = NULL, temp;
|
struct iperf_interval_results *ip = NULL, temp;
|
||||||
|
|
||||||
for (sp = test->streams; sp != NULL; sp = sp->next) {
|
// for (sp = test->streams; sp != NULL; sp = sp->next) {
|
||||||
|
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||||
rp = sp->result;
|
rp = sp->result;
|
||||||
|
|
||||||
if (test->role == 'c')
|
if (test->role == 'c')
|
||||||
@ -1065,7 +1073,8 @@ iperf_reporter_callback(struct iperf_test * test)
|
|||||||
case TEST_RUNNING:
|
case TEST_RUNNING:
|
||||||
case STREAM_RUNNING:
|
case STREAM_RUNNING:
|
||||||
/* print interval results for each stream */
|
/* print interval results for each stream */
|
||||||
for (sp = test->streams; sp != NULL; sp = sp->next) {
|
// for (sp = test->streams; sp != NULL; sp = sp->next) {
|
||||||
|
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||||
print_interval_results(test, sp);
|
print_interval_results(test, sp);
|
||||||
bytes += sp->result->interval_results->bytes_transferred; /* sum up all streams */
|
bytes += sp->result->interval_results->bytes_transferred; /* sum up all streams */
|
||||||
}
|
}
|
||||||
@ -1075,8 +1084,8 @@ iperf_reporter_callback(struct iperf_test * test)
|
|||||||
}
|
}
|
||||||
/* next build string with sum of all streams */
|
/* next build string with sum of all streams */
|
||||||
if (test->num_streams > 1) {
|
if (test->num_streams > 1) {
|
||||||
sp = test->streams; /* reset back to 1st stream */
|
sp = SLIST_FIRST(&test->streams); /* reset back to 1st stream */
|
||||||
ip = test->streams->result->last_interval_results; /* use 1st stream for timing info */
|
ip = sp->result->last_interval_results; /* use 1st stream for timing info */
|
||||||
|
|
||||||
unit_snprintf(ubuf, UNIT_LEN, (double) (bytes), 'A');
|
unit_snprintf(ubuf, UNIT_LEN, (double) (bytes), 'A');
|
||||||
unit_snprintf(nbuf, UNIT_LEN, (double) (bytes / ip->interval_duration),
|
unit_snprintf(nbuf, UNIT_LEN, (double) (bytes / ip->interval_duration),
|
||||||
@ -1098,9 +1107,10 @@ iperf_reporter_callback(struct iperf_test * test)
|
|||||||
printf(report_bw_header);
|
printf(report_bw_header);
|
||||||
|
|
||||||
start_time = 0.;
|
start_time = 0.;
|
||||||
sp = test->streams;
|
sp = SLIST_FIRST(&test->streams);
|
||||||
end_time = timeval_diff(&sp->result->start_time, &sp->result->end_time);
|
end_time = timeval_diff(&sp->result->start_time, &sp->result->end_time);
|
||||||
for (sp = test->streams; sp != NULL; sp = sp->next) {
|
// for (sp = test->streams; sp != NULL; sp = sp->next) {
|
||||||
|
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||||
bytes_sent = sp->result->bytes_sent;
|
bytes_sent = sp->result->bytes_sent;
|
||||||
bytes_received = sp->result->bytes_received;
|
bytes_received = sp->result->bytes_received;
|
||||||
total_sent += bytes_sent;
|
total_sent += bytes_sent;
|
||||||
@ -1186,7 +1196,7 @@ print_interval_results(struct iperf_test * test, struct iperf_stream * sp)
|
|||||||
printf("print_interval_results Error: interval_results = NULL \n");
|
printf("print_interval_results Error: interval_results = NULL \n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (sp == test->streams) {
|
if (sp == SLIST_FIRST(&test->streams)) {
|
||||||
printf(report_bw_header);
|
printf(report_bw_header);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1304,14 +1314,19 @@ void
|
|||||||
iperf_add_stream(struct iperf_test * test, struct iperf_stream * sp)
|
iperf_add_stream(struct iperf_test * test, struct iperf_stream * sp)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct iperf_stream *n;
|
struct iperf_stream *n, *prev;
|
||||||
|
|
||||||
if (!test->streams) {
|
if (SLIST_EMPTY(&test->streams)) {
|
||||||
test->streams = sp;
|
SLIST_INSERT_HEAD(&test->streams, sp, streams);
|
||||||
sp->id = 1;
|
sp->id = 1;
|
||||||
} else {
|
} else {
|
||||||
for (n = test->streams, i = 2; n->next; n = n->next, ++i);
|
// for (n = test->streams, i = 2; n->next; n = n->next, ++i);
|
||||||
n->next = sp;
|
i = 2;
|
||||||
|
SLIST_FOREACH(n, &test->streams, streams) {
|
||||||
|
prev = n;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
SLIST_INSERT_AFTER(prev, sp, streams);
|
||||||
sp->id = i;
|
sp->id = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/queue.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
@ -140,11 +141,19 @@ iperf_client_end(struct iperf_test *test)
|
|||||||
test->reporter_callback(test);
|
test->reporter_callback(test);
|
||||||
|
|
||||||
/* Deleting all streams - CAN CHANGE FREE_STREAM FN */
|
/* Deleting all streams - CAN CHANGE FREE_STREAM FN */
|
||||||
|
/*
|
||||||
for (sp = test->streams; sp; sp = np) {
|
for (sp = test->streams; sp; sp = np) {
|
||||||
close(sp->socket);
|
close(sp->socket);
|
||||||
np = sp->next;
|
np = sp->next;
|
||||||
iperf_free_stream(sp);
|
iperf_free_stream(sp);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
while (!SLIST_EMPTY(&test->streams)) {
|
||||||
|
sp = SLIST_FIRST(&test->streams);
|
||||||
|
SLIST_REMOVE_HEAD(&test->streams, streams);
|
||||||
|
close(sp->socket);
|
||||||
|
iperf_free_stream(sp);
|
||||||
|
}
|
||||||
|
|
||||||
test->state = IPERF_DONE;
|
test->state = IPERF_DONE;
|
||||||
if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) {
|
if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) {
|
||||||
|
@ -170,7 +170,8 @@ iperf_handle_message_server(struct iperf_test *test)
|
|||||||
break;
|
break;
|
||||||
case TEST_END:
|
case TEST_END:
|
||||||
test->stats_callback(test);
|
test->stats_callback(test);
|
||||||
for (sp = test->streams; sp; sp = sp->next) {
|
// for (sp = test->streams; sp; sp = sp->next) {
|
||||||
|
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||||
FD_CLR(sp->socket, &test->read_set);
|
FD_CLR(sp->socket, &test->read_set);
|
||||||
FD_CLR(sp->socket, &test->write_set);
|
FD_CLR(sp->socket, &test->write_set);
|
||||||
close(sp->socket);
|
close(sp->socket);
|
||||||
@ -198,7 +199,8 @@ iperf_handle_message_server(struct iperf_test *test)
|
|||||||
|
|
||||||
// XXX: Remove this line below!
|
// XXX: Remove this line below!
|
||||||
fprintf(stderr, "The client has terminated.\n");
|
fprintf(stderr, "The client has terminated.\n");
|
||||||
for (sp = test->streams; sp; sp = sp->next) {
|
// for (sp = test->streams; sp; sp = sp->next) {
|
||||||
|
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||||
FD_CLR(sp->socket, &test->read_set);
|
FD_CLR(sp->socket, &test->read_set);
|
||||||
FD_CLR(sp->socket, &test->write_set);
|
FD_CLR(sp->socket, &test->write_set);
|
||||||
close(sp->socket);
|
close(sp->socket);
|
||||||
@ -221,10 +223,17 @@ iperf_test_reset(struct iperf_test *test)
|
|||||||
close(test->ctrl_sck);
|
close(test->ctrl_sck);
|
||||||
|
|
||||||
/* Free streams */
|
/* Free streams */
|
||||||
|
/*
|
||||||
for (sp = test->streams; sp; sp = np) {
|
for (sp = test->streams; sp; sp = np) {
|
||||||
np = sp->next;
|
np = sp->next;
|
||||||
iperf_free_stream(sp);
|
iperf_free_stream(sp);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
while (!SLIST_EMPTY(&test->streams)) {
|
||||||
|
sp = SLIST_FIRST(&test->streams);
|
||||||
|
SLIST_REMOVE_HEAD(&test->streams, streams);
|
||||||
|
iperf_free_stream(sp);
|
||||||
|
}
|
||||||
free_timer(test->timer);
|
free_timer(test->timer);
|
||||||
free_timer(test->stats_timer);
|
free_timer(test->stats_timer);
|
||||||
free_timer(test->reporter_timer);
|
free_timer(test->reporter_timer);
|
||||||
@ -232,7 +241,7 @@ iperf_test_reset(struct iperf_test *test)
|
|||||||
test->stats_timer = NULL;
|
test->stats_timer = NULL;
|
||||||
test->reporter_timer = NULL;
|
test->reporter_timer = NULL;
|
||||||
|
|
||||||
test->streams = NULL;
|
SLIST_INIT(&test->streams);
|
||||||
|
|
||||||
test->role = 's';
|
test->role = 's';
|
||||||
set_protocol(test, Ptcp);
|
set_protocol(test, Ptcp);
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <sys/queue.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@ -254,7 +255,8 @@ iperf_udp_init(struct iperf_test *test)
|
|||||||
|
|
||||||
assert(dtargus != 0);
|
assert(dtargus != 0);
|
||||||
|
|
||||||
for (sp = test->streams; sp; sp = sp->next) {
|
// for (sp = test->streams; sp; sp = sp->next) {
|
||||||
|
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||||
sp->send_timer = new_timer(dtargus / SEC_TO_US, dtargus % SEC_TO_US);
|
sp->send_timer = new_timer(dtargus / SEC_TO_US, dtargus % SEC_TO_US);
|
||||||
if (sp->send_timer == NULL)
|
if (sp->send_timer == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/queue.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
@ -34,7 +35,7 @@ get_tcpinfo(struct iperf_test *test, struct iperf_interval_results *rp)
|
|||||||
{
|
{
|
||||||
#if defined(linux) || defined(__FreeBSD__)
|
#if defined(linux) || defined(__FreeBSD__)
|
||||||
socklen_t tcp_info_length;
|
socklen_t tcp_info_length;
|
||||||
struct iperf_stream *sp = test->streams;
|
struct iperf_stream *sp = SLIST_FIRST(&test->streams);
|
||||||
|
|
||||||
tcp_info_length = sizeof(struct tcp_info);
|
tcp_info_length = sizeof(struct tcp_info);
|
||||||
//printf("getting TCP_INFO for socket %d \n", sp->socket);
|
//printf("getting TCP_INFO for socket %d \n", sp->socket);
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user