implemented code review changes - r100/101, added a check on failure to receive STREAM_END message
This commit is contained in:
parent
6044ffd6f5
commit
8b44cd5a88
@ -256,6 +256,11 @@ int iperf_tcp_recv(struct iperf_stream *sp)
|
||||
message = (int) ch;
|
||||
}
|
||||
|
||||
if(message == 3 || message == 9 || message == 8)
|
||||
{
|
||||
printf(" Recieved %d from client\n", message);
|
||||
}
|
||||
|
||||
if(message!= STREAM_END)
|
||||
sp->result->bytes_received+= result;
|
||||
|
||||
@ -310,6 +315,7 @@ int iperf_tcp_send(struct iperf_stream *sp)
|
||||
buf[0]= STREAM_BEGIN;
|
||||
break;
|
||||
case STREAM_END:
|
||||
printf("STREAM END STARTING\n");
|
||||
buf[0]= STREAM_END;
|
||||
break;
|
||||
case RESULT_REQUEST:
|
||||
@ -329,10 +335,17 @@ int iperf_tcp_send(struct iperf_stream *sp)
|
||||
//applicable for 1st packet sent
|
||||
if(sp->settings->state == STREAM_BEGIN)
|
||||
{
|
||||
sp->settings->state = TEST_RUNNING;
|
||||
sp->settings->state = STREAM_RUNNING;
|
||||
}
|
||||
|
||||
result = send(sp->socket, buf, size , 0);
|
||||
|
||||
if(result <=0)
|
||||
{
|
||||
perror("send:");
|
||||
return -1;
|
||||
}
|
||||
|
||||
sp->result->bytes_sent+= size;
|
||||
|
||||
free(buf);
|
||||
@ -347,7 +360,7 @@ int iperf_udp_send(struct iperf_stream *sp)
|
||||
|
||||
|
||||
// the || part ensures that last packet is sent to server - the STREAM_END MESSAGE
|
||||
if(((struct timer *) sp->data)->expired((struct timer *) sp->data) || sp->settings->state == STREAM_END)
|
||||
if(sp->send_timer->expired(sp->send_timer) || sp->settings->state == STREAM_END)
|
||||
{
|
||||
int size = sp->settings->blksize;
|
||||
char *buf = (char *) malloc(size);
|
||||
@ -385,7 +398,7 @@ int iperf_udp_send(struct iperf_stream *sp)
|
||||
// applicable for 1st packet sent
|
||||
if(sp->settings->state == STREAM_BEGIN)
|
||||
{
|
||||
sp->settings->state = TEST_RUNNING;
|
||||
sp->settings->state = STREAM_RUNNING;
|
||||
}
|
||||
|
||||
|
||||
@ -393,6 +406,13 @@ int iperf_udp_send(struct iperf_stream *sp)
|
||||
perror("gettimeofday");
|
||||
|
||||
result = send(sp->socket, buf, size, 0);
|
||||
if(result <=0)
|
||||
{
|
||||
perror("send:");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
sp->result->bytes_sent+= result;
|
||||
|
||||
if(gettimeofday(&after, 0) < 0)
|
||||
@ -409,7 +429,7 @@ int iperf_udp_send(struct iperf_stream *sp)
|
||||
memcpy(&before, &after, sizeof before);
|
||||
|
||||
// RESET THE TIMER
|
||||
sp->data = new_timer(0, dtargus);
|
||||
sp->send_timer = new_timer(0, dtargus);
|
||||
//printf(" new timer is %lld usec\n", dtargus);
|
||||
|
||||
} // timer_expired_micro
|
||||
@ -658,7 +678,9 @@ char *iperf_reporter_callback(struct iperf_test *test)
|
||||
if(test->role == 'c')
|
||||
bytes+= sp->result->bytes_sent;
|
||||
else
|
||||
{
|
||||
bytes+= sp->result->bytes_received;
|
||||
}
|
||||
|
||||
sprintf(message,report_bw_header);
|
||||
strcat(message_final, message);
|
||||
@ -1031,6 +1053,7 @@ void iperf_run_server(struct iperf_test *test)
|
||||
if(message == STREAM_END)
|
||||
{
|
||||
n->settings->state = STREAM_END;
|
||||
printf("stream ended \n");
|
||||
gettimeofday(&n->result->end_time, NULL);
|
||||
FD_CLR(j, &test->read_set);
|
||||
}
|
||||
@ -1040,7 +1063,6 @@ void iperf_run_server(struct iperf_test *test)
|
||||
n->settings->state = RESULT_RESPOND;
|
||||
n->data = read;
|
||||
send_result_to_client(n);
|
||||
|
||||
// FREE ALL STREAMS
|
||||
n = test->streams;
|
||||
while(n)
|
||||
@ -1058,6 +1080,19 @@ void iperf_run_server(struct iperf_test *test)
|
||||
|
||||
if(message == ALL_STREAMS_END)
|
||||
{
|
||||
//sometimes the server is not getting the STREAM_END message
|
||||
// hence changing the state of all but last stream forcefully
|
||||
n = test->streams;
|
||||
while(n->next)
|
||||
{
|
||||
if(n->settings->state == STREAM_BEGIN)
|
||||
{
|
||||
n->settings->state = STREAM_END;
|
||||
gettimeofday(&n->result->end_time, NULL);
|
||||
}
|
||||
n= n->next;
|
||||
}
|
||||
|
||||
test->default_settings->state = RESULT_REQUEST;
|
||||
read = test->reporter_callback(test);
|
||||
puts(read);
|
||||
@ -1076,7 +1111,6 @@ void iperf_run_server(struct iperf_test *test)
|
||||
test->max_fd = test->listener_sock;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}// end if (FD_ISSET(j, &temp_set))
|
||||
@ -1117,7 +1151,7 @@ void iperf_run_client(struct iperf_test *test)
|
||||
sp = test->streams;
|
||||
for(i=0; i< test->num_streams; i++)
|
||||
{
|
||||
sp->data = new_timer(0, dtargus);
|
||||
sp->send_timer = new_timer(0, dtargus);
|
||||
sp= sp->next;
|
||||
}
|
||||
}
|
||||
@ -1180,6 +1214,8 @@ void iperf_run_client(struct iperf_test *test)
|
||||
sp = np;
|
||||
sp->settings->state = STREAM_END;
|
||||
sp->snd(sp);
|
||||
printf("sent the STREAM_END message \n");
|
||||
|
||||
np = sp->next;
|
||||
} while (np);
|
||||
|
||||
|
@ -47,6 +47,8 @@ struct iperf_stream
|
||||
|
||||
int socket; // socket
|
||||
|
||||
struct timer *send_timer;
|
||||
|
||||
struct sockaddr_storage local_addr;
|
||||
struct sockaddr_storage remote_addr;
|
||||
|
||||
@ -132,8 +134,9 @@ enum {
|
||||
RESULT_RESPOND = 4,
|
||||
TEST_END = 5,
|
||||
STREAM_BEGIN = 6,
|
||||
STREAM_END = 7,
|
||||
ALL_STREAMS_END = 8,
|
||||
STREAM_RUNNING = 7,
|
||||
STREAM_END = 8,
|
||||
ALL_STREAMS_END = 9,
|
||||
SEC_TO_US = 1000000
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user