2009-11-02 22:43:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2009, The Regents of the University of California, through
|
|
|
|
* Lawrence Berkeley National Laboratory (subject to receipt of any required
|
|
|
|
* approvals from the U.S. Dept. of Energy). All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* iperf_server_api.c: Functions to be used by an iperf server
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
|
|
|
#include "iperf.h"
|
|
|
|
#include "iperf_server_api.h"
|
|
|
|
#include "iperf_api.h"
|
|
|
|
#include "iperf_udp.h"
|
|
|
|
#include "iperf_tcp.h"
|
2010-07-20 22:27:50 +00:00
|
|
|
#include "iperf_error.h"
|
2010-07-22 18:57:08 +00:00
|
|
|
#include "iperf_util.h"
|
2009-11-02 22:43:19 +00:00
|
|
|
#include "timer.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "units.h"
|
|
|
|
#include "tcp_window_size.h"
|
2010-07-09 00:29:51 +00:00
|
|
|
#include "iperf_util.h"
|
2009-11-02 22:43:19 +00:00
|
|
|
#include "locale.h"
|
|
|
|
|
|
|
|
|
2010-06-18 21:08:50 +00:00
|
|
|
int
|
|
|
|
iperf_server_listen(struct iperf_test *test)
|
2009-11-02 22:43:19 +00:00
|
|
|
{
|
2010-06-18 21:08:50 +00:00
|
|
|
char ubuf[UNIT_LEN];
|
|
|
|
int x;
|
|
|
|
|
2010-07-27 20:27:34 +00:00
|
|
|
if((test->listener = netannounce(test->settings->domain, Ptcp, test->bind_address, test->server_port)) < 0) {
|
2010-07-20 22:27:50 +00:00
|
|
|
i_errno = IELISTEN;
|
|
|
|
return (-1);
|
2010-06-18 21:08:50 +00:00
|
|
|
}
|
2009-11-02 22:43:19 +00:00
|
|
|
|
2010-06-18 21:08:50 +00:00
|
|
|
printf("-----------------------------------------------------------\n");
|
|
|
|
printf("Server listening on %d\n", test->server_port);
|
|
|
|
|
|
|
|
// This needs to be changed to reflect if client has different window size
|
|
|
|
// make sure we got what we asked for
|
2010-06-21 15:08:47 +00:00
|
|
|
/* XXX: This needs to be moved to the stream listener
|
2010-07-22 23:26:38 +00:00
|
|
|
if ((x = get_tcp_windowsize(test->listener, SO_RCVBUF)) < 0) {
|
2010-06-18 21:08:50 +00:00
|
|
|
// Needs to set some sort of error number/message
|
|
|
|
perror("SO_RCVBUF");
|
|
|
|
return -1;
|
|
|
|
}
|
2010-06-21 15:08:47 +00:00
|
|
|
*/
|
2010-06-18 21:08:50 +00:00
|
|
|
|
2010-06-21 15:08:47 +00:00
|
|
|
// XXX: This code needs to be moved to after parameter exhange
|
2010-07-15 23:19:42 +00:00
|
|
|
/*
|
2010-07-22 23:26:38 +00:00
|
|
|
if (test->protocol->id == Ptcp) {
|
2010-07-23 18:39:14 +00:00
|
|
|
if (test->settings->socket_bufsize > 0) {
|
2010-06-18 21:08:50 +00:00
|
|
|
unit_snprintf(ubuf, UNIT_LEN, (double) x, 'A');
|
|
|
|
printf("TCP window size: %s\n", ubuf);
|
|
|
|
} else {
|
|
|
|
printf("Using TCP Autotuning\n");
|
|
|
|
}
|
|
|
|
}
|
2010-07-15 23:19:42 +00:00
|
|
|
*/
|
2010-06-18 21:08:50 +00:00
|
|
|
printf("-----------------------------------------------------------\n");
|
2009-11-06 02:19:20 +00:00
|
|
|
|
2009-11-02 22:43:19 +00:00
|
|
|
FD_ZERO(&test->read_set);
|
2010-06-30 15:58:16 +00:00
|
|
|
FD_ZERO(&test->write_set);
|
2010-07-22 23:26:38 +00:00
|
|
|
FD_SET(test->listener, &test->read_set);
|
|
|
|
test->max_fd = (test->listener > test->max_fd) ? test->listener : test->max_fd;
|
2010-06-18 21:08:50 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
iperf_accept(struct iperf_test *test)
|
|
|
|
{
|
|
|
|
int s;
|
2010-06-23 19:13:37 +00:00
|
|
|
int rbuf = ACCESS_DENIED;
|
2010-06-30 22:09:45 +00:00
|
|
|
char cookie[COOKIE_SIZE];
|
2010-06-18 21:08:50 +00:00
|
|
|
socklen_t len;
|
|
|
|
struct sockaddr_in addr;
|
2010-07-06 23:12:54 +00:00
|
|
|
|
|
|
|
len = sizeof(addr);
|
2010-07-22 23:26:38 +00:00
|
|
|
if ((s = accept(test->listener, (struct sockaddr *) &addr, &len)) < 0) {
|
2010-07-20 22:27:50 +00:00
|
|
|
i_errno = IEACCEPT;
|
|
|
|
return (-1);
|
2010-06-30 22:09:45 +00:00
|
|
|
}
|
2010-06-18 21:08:50 +00:00
|
|
|
|
2010-06-23 19:13:37 +00:00
|
|
|
if (test->ctrl_sck == -1) {
|
2010-06-30 22:09:45 +00:00
|
|
|
/* Server free, accept new client */
|
2010-07-23 18:39:14 +00:00
|
|
|
if (Nread(s, test->cookie, COOKIE_SIZE, Ptcp) < 0) {
|
2010-07-20 22:27:50 +00:00
|
|
|
i_errno = IERECVCOOKIE;
|
|
|
|
return (-1);
|
2010-06-18 21:08:50 +00:00
|
|
|
}
|
2010-06-30 22:09:45 +00:00
|
|
|
|
2010-06-23 19:13:37 +00:00
|
|
|
FD_SET(s, &test->read_set);
|
|
|
|
FD_SET(s, &test->write_set);
|
|
|
|
test->max_fd = (s > test->max_fd) ? s : test->max_fd;
|
|
|
|
test->ctrl_sck = s;
|
2010-06-18 21:08:50 +00:00
|
|
|
|
2010-06-30 22:09:45 +00:00
|
|
|
test->state = PARAM_EXCHANGE;
|
|
|
|
if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) {
|
2010-07-20 22:27:50 +00:00
|
|
|
i_errno = IESENDMESSAGE;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (iperf_exchange_parameters(test) < 0) {
|
|
|
|
return (-1);
|
2010-06-30 22:09:45 +00:00
|
|
|
}
|
2010-07-23 20:46:58 +00:00
|
|
|
if (test->on_connect) {
|
|
|
|
test->on_connect(test);
|
|
|
|
}
|
2010-06-18 21:08:50 +00:00
|
|
|
} else {
|
2010-07-20 22:27:50 +00:00
|
|
|
// XXX: Do we even need to receive cookie if we're just going to deny anyways?
|
2010-06-30 22:09:45 +00:00
|
|
|
if (Nread(s, cookie, COOKIE_SIZE, Ptcp) < 0) {
|
2010-07-20 22:27:50 +00:00
|
|
|
i_errno = IERECVCOOKIE;
|
|
|
|
return (-1);
|
2010-06-23 19:13:37 +00:00
|
|
|
}
|
2010-07-20 22:27:50 +00:00
|
|
|
if (Nwrite(s, &rbuf, sizeof(int), Ptcp) < 0) {
|
|
|
|
i_errno = IESENDMESSAGE;
|
|
|
|
return (-1);
|
2010-06-23 19:13:37 +00:00
|
|
|
}
|
2010-07-20 22:27:50 +00:00
|
|
|
close(s);
|
2009-11-10 04:41:42 +00:00
|
|
|
}
|
2010-06-30 22:09:45 +00:00
|
|
|
|
2010-07-20 22:27:50 +00:00
|
|
|
return (0);
|
2010-06-18 21:08:50 +00:00
|
|
|
}
|
|
|
|
|
2010-07-06 23:12:54 +00:00
|
|
|
|
2010-06-18 21:08:50 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
int
|
2010-06-23 19:13:37 +00:00
|
|
|
iperf_handle_message_server(struct iperf_test *test)
|
2010-06-18 21:08:50 +00:00
|
|
|
{
|
2010-07-06 23:12:54 +00:00
|
|
|
int rval;
|
2010-06-30 15:58:16 +00:00
|
|
|
struct iperf_stream *sp;
|
|
|
|
|
2010-07-20 22:27:50 +00:00
|
|
|
// XXX: Need to rethink how this behaves to fit API
|
|
|
|
if ((rval = Nread(test->ctrl_sck, &test->state, sizeof(char), Ptcp)) <= 0) {
|
2010-07-06 23:12:54 +00:00
|
|
|
if (rval == 0) {
|
|
|
|
fprintf(stderr, "The client has unexpectedly closed the connection.\n");
|
2010-07-20 22:27:50 +00:00
|
|
|
i_errno = IECTRLCLOSE;
|
2010-07-06 23:12:54 +00:00
|
|
|
test->state = IPERF_DONE;
|
2010-07-20 22:27:50 +00:00
|
|
|
return (0);
|
2010-07-06 23:12:54 +00:00
|
|
|
} else {
|
2010-07-20 22:27:50 +00:00
|
|
|
i_errno = IERECVMESSAGE;
|
|
|
|
return (-1);
|
2010-07-06 23:12:54 +00:00
|
|
|
}
|
2010-06-18 21:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(test->state) {
|
2010-06-21 15:08:47 +00:00
|
|
|
case TEST_START:
|
|
|
|
break;
|
2010-06-23 19:13:37 +00:00
|
|
|
case TEST_END:
|
2011-02-24 17:08:54 +00:00
|
|
|
cpu_util(&test->cpu_util);
|
2010-07-07 21:54:24 +00:00
|
|
|
test->stats_callback(test);
|
2010-07-28 20:29:25 +00:00
|
|
|
SLIST_FOREACH(sp, &test->streams, streams) {
|
2010-06-30 15:58:16 +00:00
|
|
|
FD_CLR(sp->socket, &test->read_set);
|
|
|
|
FD_CLR(sp->socket, &test->write_set);
|
|
|
|
close(sp->socket);
|
|
|
|
}
|
2010-06-29 22:02:30 +00:00
|
|
|
test->state = EXCHANGE_RESULTS;
|
2010-07-01 00:01:57 +00:00
|
|
|
if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) {
|
2010-07-20 22:27:50 +00:00
|
|
|
i_errno = IESENDMESSAGE;
|
|
|
|
return (-1);
|
2010-06-29 22:02:30 +00:00
|
|
|
}
|
2010-07-20 22:27:50 +00:00
|
|
|
if (iperf_exchange_results(test) < 0)
|
|
|
|
return (-1);
|
2010-06-23 20:28:32 +00:00
|
|
|
test->state = DISPLAY_RESULTS;
|
2010-07-01 00:01:57 +00:00
|
|
|
if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) {
|
2010-07-20 22:27:50 +00:00
|
|
|
i_errno = IESENDMESSAGE;
|
|
|
|
return (-1);
|
2010-06-23 19:13:37 +00:00
|
|
|
}
|
2010-07-23 20:46:58 +00:00
|
|
|
if (test->on_test_finish)
|
|
|
|
test->on_test_finish(test);
|
2010-06-29 22:02:30 +00:00
|
|
|
test->reporter_callback(test);
|
2010-06-23 19:13:37 +00:00
|
|
|
break;
|
2010-06-23 20:28:32 +00:00
|
|
|
case IPERF_DONE:
|
|
|
|
break;
|
2010-06-23 19:13:37 +00:00
|
|
|
case CLIENT_TERMINATE:
|
2010-07-27 22:11:09 +00:00
|
|
|
i_errno = IECLIENTTERM;
|
|
|
|
|
|
|
|
// XXX: Remove this line below!
|
2010-07-08 22:41:22 +00:00
|
|
|
fprintf(stderr, "The client has terminated.\n");
|
2010-07-28 20:29:25 +00:00
|
|
|
SLIST_FOREACH(sp, &test->streams, streams) {
|
2010-07-08 22:41:22 +00:00
|
|
|
FD_CLR(sp->socket, &test->read_set);
|
|
|
|
FD_CLR(sp->socket, &test->write_set);
|
|
|
|
close(sp->socket);
|
|
|
|
}
|
|
|
|
test->state = IPERF_DONE;
|
|
|
|
break;
|
2010-06-21 15:08:47 +00:00
|
|
|
default:
|
2010-07-20 22:27:50 +00:00
|
|
|
i_errno = IEMESSAGE;
|
|
|
|
return (-1);
|
2010-06-18 21:08:50 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 22:27:50 +00:00
|
|
|
return (0);
|
2010-06-18 21:08:50 +00:00
|
|
|
}
|
2009-11-02 22:43:19 +00:00
|
|
|
|
2010-08-02 22:45:53 +00:00
|
|
|
/* XXX: This function is not used anymore */
|
2010-06-30 15:58:16 +00:00
|
|
|
void
|
|
|
|
iperf_test_reset(struct iperf_test *test)
|
|
|
|
{
|
2010-08-02 22:45:53 +00:00
|
|
|
struct iperf_stream *sp;
|
2010-06-30 15:58:16 +00:00
|
|
|
|
|
|
|
close(test->ctrl_sck);
|
|
|
|
|
|
|
|
/* Free streams */
|
2010-07-28 20:29:25 +00:00
|
|
|
while (!SLIST_EMPTY(&test->streams)) {
|
|
|
|
sp = SLIST_FIRST(&test->streams);
|
|
|
|
SLIST_REMOVE_HEAD(&test->streams, streams);
|
|
|
|
iperf_free_stream(sp);
|
|
|
|
}
|
2010-07-07 21:54:24 +00:00
|
|
|
free_timer(test->timer);
|
|
|
|
free_timer(test->stats_timer);
|
|
|
|
free_timer(test->reporter_timer);
|
|
|
|
test->timer = NULL;
|
|
|
|
test->stats_timer = NULL;
|
|
|
|
test->reporter_timer = NULL;
|
2010-06-30 15:58:16 +00:00
|
|
|
|
2010-07-28 20:29:25 +00:00
|
|
|
SLIST_INIT(&test->streams);
|
2010-06-30 19:57:17 +00:00
|
|
|
|
2010-06-30 15:58:16 +00:00
|
|
|
test->role = 's';
|
2010-07-22 23:26:38 +00:00
|
|
|
set_protocol(test, Ptcp);
|
2010-06-30 19:57:17 +00:00
|
|
|
test->duration = DURATION;
|
|
|
|
test->state = 0;
|
|
|
|
test->server_hostname = NULL;
|
|
|
|
|
|
|
|
test->ctrl_sck = -1;
|
2010-07-22 23:26:38 +00:00
|
|
|
test->prot_listener = -1;
|
2010-06-30 19:57:17 +00:00
|
|
|
|
2010-07-07 21:54:24 +00:00
|
|
|
test->bytes_sent = 0;
|
|
|
|
|
2010-06-30 19:57:17 +00:00
|
|
|
test->reverse = 0;
|
2010-07-06 23:12:54 +00:00
|
|
|
test->no_delay = 0;
|
2010-06-30 19:57:17 +00:00
|
|
|
|
2010-06-30 15:58:16 +00:00
|
|
|
FD_ZERO(&test->read_set);
|
|
|
|
FD_ZERO(&test->write_set);
|
2010-07-22 23:26:38 +00:00
|
|
|
FD_SET(test->listener, &test->read_set);
|
|
|
|
test->max_fd = test->listener;
|
2010-06-30 19:57:17 +00:00
|
|
|
|
|
|
|
test->num_streams = 1;
|
2010-07-23 18:39:14 +00:00
|
|
|
test->settings->socket_bufsize = 0;
|
|
|
|
test->settings->blksize = DEFAULT_TCP_BLKSIZE;
|
|
|
|
test->settings->rate = RATE; /* UDP only */
|
|
|
|
test->settings->mss = 0;
|
|
|
|
memset(test->cookie, 0, COOKIE_SIZE);
|
2010-06-30 15:58:16 +00:00
|
|
|
}
|
|
|
|
|
2010-06-23 21:34:07 +00:00
|
|
|
int
|
2010-06-18 21:08:50 +00:00
|
|
|
iperf_run_server(struct iperf_test *test)
|
|
|
|
{
|
2010-07-23 18:39:14 +00:00
|
|
|
int result, s, streams_accepted;
|
2010-06-30 15:58:16 +00:00
|
|
|
fd_set temp_read_set, temp_write_set;
|
2010-07-22 18:57:08 +00:00
|
|
|
struct iperf_stream *sp;
|
2010-06-23 21:34:07 +00:00
|
|
|
struct timeval tv;
|
2010-08-02 22:45:53 +00:00
|
|
|
time_t sec, usec;
|
2010-06-18 21:08:50 +00:00
|
|
|
|
|
|
|
// Open socket and listen
|
|
|
|
if (iperf_server_listen(test) < 0) {
|
2010-07-20 22:27:50 +00:00
|
|
|
return (-1);
|
2010-06-18 21:08:50 +00:00
|
|
|
}
|
2009-11-02 22:43:19 +00:00
|
|
|
|
2011-02-24 17:08:54 +00:00
|
|
|
// Begin calculating CPU utilization
|
|
|
|
cpu_util(NULL);
|
|
|
|
|
2010-08-02 22:45:53 +00:00
|
|
|
test->state = IPERF_START;
|
|
|
|
streams_accepted = 0;
|
2010-06-18 21:08:50 +00:00
|
|
|
|
2010-08-02 22:45:53 +00:00
|
|
|
while (test->state != IPERF_DONE) {
|
2010-06-18 21:08:50 +00:00
|
|
|
|
2010-08-02 22:45:53 +00:00
|
|
|
memcpy(&temp_read_set, &test->read_set, sizeof(fd_set));
|
|
|
|
memcpy(&temp_write_set, &test->write_set, sizeof(fd_set));
|
|
|
|
tv.tv_sec = 15;
|
|
|
|
tv.tv_usec = 0;
|
2010-06-30 22:09:45 +00:00
|
|
|
|
2010-08-02 22:45:53 +00:00
|
|
|
result = select(test->max_fd + 1, &temp_read_set, &temp_write_set, NULL, &tv);
|
|
|
|
if (result < 0 && errno != EINTR) {
|
|
|
|
i_errno = IESELECT;
|
|
|
|
return (-1);
|
|
|
|
} else if (result > 0) {
|
|
|
|
if (FD_ISSET(test->listener, &temp_read_set)) {
|
|
|
|
if (test->state != CREATE_STREAMS) {
|
|
|
|
if (iperf_accept(test) < 0) {
|
|
|
|
return (-1);
|
2010-06-30 22:09:45 +00:00
|
|
|
}
|
2010-08-02 22:45:53 +00:00
|
|
|
FD_CLR(test->listener, &temp_read_set);
|
2010-06-18 21:08:50 +00:00
|
|
|
}
|
2010-08-02 22:45:53 +00:00
|
|
|
}
|
|
|
|
if (FD_ISSET(test->ctrl_sck, &temp_read_set)) {
|
|
|
|
if (iperf_handle_message_server(test) < 0)
|
|
|
|
return (-1);
|
|
|
|
FD_CLR(test->ctrl_sck, &temp_read_set);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test->state == CREATE_STREAMS) {
|
|
|
|
if (FD_ISSET(test->prot_listener, &temp_read_set)) {
|
|
|
|
|
|
|
|
if ((s = test->protocol->accept(test)) < 0)
|
2010-07-20 22:27:50 +00:00
|
|
|
return (-1);
|
2010-06-30 22:09:45 +00:00
|
|
|
|
2010-08-02 22:45:53 +00:00
|
|
|
if (!is_closed(s)) {
|
|
|
|
sp = iperf_new_stream(test, s);
|
|
|
|
if (!sp)
|
2010-07-22 18:57:08 +00:00
|
|
|
return (-1);
|
|
|
|
|
2010-08-02 22:45:53 +00:00
|
|
|
FD_SET(s, &test->read_set);
|
|
|
|
FD_SET(s, &test->write_set);
|
|
|
|
test->max_fd = (s > test->max_fd) ? s : test->max_fd;
|
2010-07-22 23:26:38 +00:00
|
|
|
|
2010-08-02 22:45:53 +00:00
|
|
|
streams_accepted++;
|
|
|
|
if (test->on_new_stream)
|
|
|
|
test->on_new_stream(sp);
|
2010-06-30 22:09:45 +00:00
|
|
|
}
|
2010-08-02 22:45:53 +00:00
|
|
|
FD_CLR(test->prot_listener, &temp_read_set);
|
|
|
|
}
|
2010-07-22 18:57:08 +00:00
|
|
|
|
2010-08-02 22:45:53 +00:00
|
|
|
if (streams_accepted == test->num_streams) {
|
|
|
|
if (test->protocol->id != Ptcp) {
|
|
|
|
FD_CLR(test->prot_listener, &test->read_set);
|
|
|
|
close(test->prot_listener);
|
|
|
|
} else {
|
|
|
|
if (test->no_delay || test->settings->mss || test->settings->socket_bufsize) {
|
|
|
|
FD_CLR(test->listener, &test->read_set);
|
|
|
|
close(test->listener);
|
|
|
|
if ((s = netannounce(test->settings->domain, Ptcp, test->bind_address, test->server_port)) < 0) {
|
|
|
|
i_errno = IELISTEN;
|
|
|
|
return (-1);
|
2010-07-15 23:19:42 +00:00
|
|
|
}
|
2010-08-02 22:45:53 +00:00
|
|
|
test->listener = s;
|
|
|
|
test->max_fd = (s > test->max_fd ? s : test->max_fd);
|
|
|
|
FD_SET(test->listener, &test->read_set);
|
2010-07-14 23:24:58 +00:00
|
|
|
}
|
2010-08-02 22:45:53 +00:00
|
|
|
}
|
|
|
|
test->prot_listener = -1;
|
|
|
|
test->state = TEST_START;
|
|
|
|
if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) {
|
|
|
|
i_errno = IESENDMESSAGE;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (iperf_init_test(test) < 0)
|
|
|
|
return (-1);
|
|
|
|
test->state = TEST_RUNNING;
|
|
|
|
if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) {
|
|
|
|
i_errno = IESENDMESSAGE;
|
|
|
|
return (-1);
|
2010-06-23 19:13:37 +00:00
|
|
|
}
|
2010-06-18 21:08:50 +00:00
|
|
|
}
|
2010-08-02 22:45:53 +00:00
|
|
|
}
|
2010-06-30 22:09:45 +00:00
|
|
|
|
2010-08-02 22:45:53 +00:00
|
|
|
if (test->state == TEST_RUNNING) {
|
|
|
|
if (test->reverse) {
|
|
|
|
// Reverse mode. Server sends.
|
|
|
|
if (iperf_send(test) < 0)
|
|
|
|
return (-1);
|
|
|
|
} else {
|
|
|
|
// Regular mode. Server receives.
|
|
|
|
if (iperf_recv(test) < 0)
|
|
|
|
return (-1);
|
|
|
|
}
|
2010-07-07 21:54:24 +00:00
|
|
|
|
2010-08-02 22:45:53 +00:00
|
|
|
/* Perform callbacks */
|
|
|
|
if (timer_expired(test->stats_timer)) {
|
|
|
|
test->stats_callback(test);
|
|
|
|
sec = (time_t) test->stats_interval;
|
|
|
|
usec = (test->stats_interval - sec) * SEC_TO_US;
|
|
|
|
if (update_timer(test->stats_timer, sec, usec) < 0)
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (timer_expired(test->reporter_timer)) {
|
|
|
|
test->reporter_callback(test);
|
|
|
|
sec = (time_t) test->reporter_interval;
|
|
|
|
usec = (test->reporter_interval - sec) * SEC_TO_US;
|
|
|
|
if (update_timer(test->reporter_timer, sec, usec) < 0)
|
|
|
|
return (-1);
|
2010-06-30 22:09:45 +00:00
|
|
|
}
|
2010-06-18 21:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-02 22:45:53 +00:00
|
|
|
}
|
2009-11-06 07:25:10 +00:00
|
|
|
|
2010-08-04 19:19:08 +00:00
|
|
|
/* Close open test sockets */
|
2010-08-02 22:45:53 +00:00
|
|
|
close(test->ctrl_sck);
|
|
|
|
close(test->listener);
|
2010-06-30 15:58:16 +00:00
|
|
|
|
2010-07-20 22:27:50 +00:00
|
|
|
return (0);
|
2009-11-06 07:25:10 +00:00
|
|
|
}
|
|
|
|
|