added new field listener_port in iperf_api.h, changed udp_Accept() port assignment in iperf_api.c
This commit is contained in:
parent
d1dc4db8c2
commit
ba492bef36
@ -192,7 +192,7 @@ void iperf_defaults(struct iperf_test *testp)
|
|||||||
{
|
{
|
||||||
testp->protocol = Ptcp;
|
testp->protocol = Ptcp;
|
||||||
testp->role = 's';
|
testp->role = 's';
|
||||||
|
testp->port = 5001;
|
||||||
testp->duration = 10;
|
testp->duration = 10;
|
||||||
|
|
||||||
testp->stats_interval = 0;
|
testp->stats_interval = 0;
|
||||||
@ -217,7 +217,7 @@ void iperf_init_test(struct iperf_test *test)
|
|||||||
|
|
||||||
if(test->role == 's')
|
if(test->role == 's')
|
||||||
{
|
{
|
||||||
test->listener_sock = netannounce(test->protocol, NULL, ntohs(((struct sockaddr_in *)(test->local_addr))->sin_port));
|
test->listener_sock = netannounce(test->protocol, NULL, test->listener_port);
|
||||||
if( test->listener_sock < 0)
|
if( test->listener_sock < 0)
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
@ -284,6 +284,8 @@ void iperf_free_test(struct iperf_test *test)
|
|||||||
free(test);
|
free(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* TODO */
|
||||||
void iperf_free_stream(struct iperf_test *test, struct iperf_stream *sp)
|
void iperf_free_stream(struct iperf_test *test, struct iperf_stream *sp)
|
||||||
{
|
{
|
||||||
free(sp->settings);
|
free(sp->settings);
|
||||||
@ -374,18 +376,18 @@ int iperf_udp_accept(struct iperf_test *test)
|
|||||||
struct sockaddr_in sa_peer;
|
struct sockaddr_in sa_peer;
|
||||||
char *buf;
|
char *buf;
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
int sz, s;
|
int sz;
|
||||||
|
|
||||||
buf = (char *) malloc(test->default_settings->bufsize);
|
|
||||||
|
|
||||||
|
|
||||||
|
buf = (char *) malloc(test->default_settings->bufsize);
|
||||||
sp = test->new_stream(test);
|
sp = test->new_stream(test);
|
||||||
|
|
||||||
len = sizeof sa_peer;
|
len = sizeof sa_peer;
|
||||||
|
|
||||||
sz = recvfrom(test->listener_sock, buf, test->default_settings->bufsize, 0, (struct sockaddr *) &sa_peer, &len);
|
sz = recvfrom(test->listener_sock, buf, test->default_settings->bufsize, 0, (struct sockaddr *) &sa_peer, &len);
|
||||||
|
|
||||||
|
|
||||||
if(!sz)
|
if(!sz)
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(connect(test->listener_sock, (struct sockaddr *) &sa_peer, len) < 0)
|
if(connect(test->listener_sock, (struct sockaddr *) &sa_peer, len) < 0)
|
||||||
@ -394,18 +396,21 @@ int iperf_udp_accept(struct iperf_test *test)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sp->socket = test->listener_sock;
|
sp->socket = test->listener_sock;
|
||||||
iperf_init_stream(sp, test);
|
iperf_init_stream(sp, test);
|
||||||
iperf_add_stream(test, sp);
|
iperf_add_stream(test, sp);
|
||||||
|
|
||||||
|
printf(" stream added , socket = %d\n", sp->socket);
|
||||||
|
|
||||||
test->listener_sock = netannounce(test->protocol, NULL, ntohs(((struct sockaddr_in *)(test->local_addr))->sin_port));
|
test->listener_sock = netannounce(test->protocol, NULL, test->listener_port);
|
||||||
if(test->listener_sock < 0)
|
if(test->listener_sock < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
FD_SET(test->listener_sock, &(test->read_set));
|
|
||||||
test->max_fd = (test->max_fd < s)?s:test->max_fd;
|
|
||||||
|
|
||||||
printf(" in udp accept \n");
|
|
||||||
|
FD_SET(test->listener_sock, &(test->read_set));
|
||||||
|
test->max_fd = (test->max_fd < test->listener_sock)?test->listener_sock:test->max_fd;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -605,38 +610,38 @@ void iperf_run_server(struct iperf_test *test)
|
|||||||
|
|
||||||
Display(test);
|
Display(test);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// test end message ?
|
// test end message ?
|
||||||
|
|
||||||
//result_request message ?
|
//result_request message ?
|
||||||
|
|
||||||
//Process the sockets for read operation
|
//Process the sockets for read operation
|
||||||
for (j=0; j< test->max_fd+1; j++)
|
for (j=0; j< test->max_fd+1; j++)
|
||||||
{
|
{
|
||||||
if (FD_ISSET(j, &(test->temp_set)))
|
if (FD_ISSET(j, &(test->temp_set)))
|
||||||
{
|
|
||||||
// find the correct stream
|
|
||||||
n = update_stream(test,j,0);
|
|
||||||
|
|
||||||
result = n->rcv(n);
|
|
||||||
|
|
||||||
if(result == 0)
|
|
||||||
{
|
|
||||||
// stream shutdown message
|
|
||||||
unit_snprintf(ubuf, UNIT_LEN, (double) (n->result->bytes_received / n->result->duration), 'a');
|
|
||||||
printf("%llu bytes received %s/sec for stream %d\n\n",n->result->bytes_received, ubuf,(int)n);
|
|
||||||
close(j);
|
|
||||||
free_stream(test, n);
|
|
||||||
FD_CLR(j, &(test->read_set));
|
|
||||||
}
|
|
||||||
else if(result < 0)
|
|
||||||
{
|
{
|
||||||
printf("Error in recv(): %s\n", strerror(errno));
|
// find the correct stream
|
||||||
}
|
n = update_stream(test,j,0);
|
||||||
} // end if (FD_ISSET(j, &temp_set))
|
|
||||||
|
result = n->rcv(n);
|
||||||
|
|
||||||
|
if(result == 0)
|
||||||
|
{
|
||||||
|
// stream shutdown message
|
||||||
|
unit_snprintf(ubuf, UNIT_LEN, (double) (n->result->bytes_received / n->result->duration), 'a');
|
||||||
|
printf("%llu bytes received %s/sec for stream %d\n\n",n->result->bytes_received, ubuf,(int)n);
|
||||||
|
close(j);
|
||||||
|
free_stream(test, n);
|
||||||
|
FD_CLR(j, &(test->read_set));
|
||||||
|
}
|
||||||
|
else if(result < 0)
|
||||||
|
{
|
||||||
|
printf("Error in recv(): %s\n", strerror(errno));
|
||||||
|
}
|
||||||
|
} // end if (FD_ISSET(j, &temp_set))
|
||||||
|
|
||||||
}// end for (j=0;...)
|
}// end for (j=0;...)
|
||||||
|
}// end else (result>0)
|
||||||
|
|
||||||
}// end while
|
}// end while
|
||||||
}
|
}
|
||||||
@ -779,6 +784,7 @@ main(int argc, char **argv)
|
|||||||
case 's':
|
case 's':
|
||||||
test->role = 's';
|
test->role = 's';
|
||||||
addr_local->sin_port = htons(5001);
|
addr_local->sin_port = htons(5001);
|
||||||
|
test->port = 5001;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
test->duration = atoi(optarg);
|
test->duration = atoi(optarg);
|
||||||
|
@ -57,12 +57,13 @@ struct iperf_test
|
|||||||
{
|
{
|
||||||
char role; // 'c'lient or 's'erver -s / -c
|
char role; // 'c'lient or 's'erver -s / -c
|
||||||
int protocol;
|
int protocol;
|
||||||
|
|
||||||
struct sockaddr_storage *remote_addr; // arg of -c
|
struct sockaddr_storage *remote_addr; // arg of -c
|
||||||
struct sockaddr_storage *local_addr;
|
struct sockaddr_storage *local_addr;
|
||||||
int duration; // total duration of test -t
|
int duration; // total duration of test -t
|
||||||
|
|
||||||
int listener_sock;
|
int listener_sock;
|
||||||
|
int listener_port;
|
||||||
|
|
||||||
/* Select related parameters */
|
/* Select related parameters */
|
||||||
int max_fd;
|
int max_fd;
|
||||||
|
Loading…
Reference in New Issue
Block a user