bug fix:name resolution issue, TCP reception corrected by adding MSG_WAITALL flag in recv function
This commit is contained in:
parent
254a65cf73
commit
cbd16a325f
110
src/iperf_api.c
110
src/iperf_api.c
@ -82,8 +82,9 @@ void add_interval_list(struct iperf_stream_result *rp, struct iperf_interval_res
|
|||||||
while(n->next)
|
while(n->next)
|
||||||
n = n->next;
|
n = n->next;
|
||||||
|
|
||||||
n->next = ip;
|
n->next = ip;
|
||||||
}
|
}
|
||||||
|
ip->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_interval_list(struct iperf_stream_result *rp)
|
void display_interval_list(struct iperf_stream_result *rp)
|
||||||
@ -140,8 +141,6 @@ void receive_result_from_server(struct iperf_test *test)
|
|||||||
sp->settings->state = ALL_STREAMS_END;
|
sp->settings->state = ALL_STREAMS_END;
|
||||||
sp->snd(sp);
|
sp->snd(sp);
|
||||||
|
|
||||||
sleep(1);
|
|
||||||
|
|
||||||
sp->settings->state = RESULT_REQUEST;
|
sp->settings->state = RESULT_REQUEST;
|
||||||
sp->snd(sp);
|
sp->snd(sp);
|
||||||
|
|
||||||
@ -268,7 +267,8 @@ void Display(struct iperf_test *test)
|
|||||||
|
|
||||||
int iperf_tcp_recv(struct iperf_stream *sp)
|
int iperf_tcp_recv(struct iperf_stream *sp)
|
||||||
{
|
{
|
||||||
int result, message;
|
int result, message;
|
||||||
|
char ch;
|
||||||
int size = sp->settings->blksize;
|
int size = sp->settings->blksize;
|
||||||
char *buf = (char *) malloc(size);
|
char *buf = (char *) malloc(size);
|
||||||
if(!buf)
|
if(!buf)
|
||||||
@ -276,21 +276,24 @@ int iperf_tcp_recv(struct iperf_stream *sp)
|
|||||||
perror("malloc: unable to allocate receive buffer");
|
perror("malloc: unable to allocate receive buffer");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tcp_datagram *tcp = (struct tcp_datagram *) buf;
|
|
||||||
|
|
||||||
do{
|
do{
|
||||||
result = recv(sp->socket, buf, size, 0);
|
result = recv(sp->socket, buf, size, MSG_WAITALL);
|
||||||
|
|
||||||
} while (result == -1 && errno == EINTR);
|
} while (result == -1 && errno == EINTR);
|
||||||
|
|
||||||
//interprete the type of message in packet
|
//interprete the type of message in packet
|
||||||
if(result > 0)
|
if(result > 0)
|
||||||
{
|
{
|
||||||
message = ntohl(tcp->state);
|
ch = buf[0];
|
||||||
|
message = (int) ch;
|
||||||
|
|
||||||
|
// CHECK: packet length and state
|
||||||
|
// printf("result = %d state = %d\n",result, buf[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(message == 3 || message == 9 || message == 8)
|
if(message == 3 || message == 8 || message == 9 )
|
||||||
{
|
{
|
||||||
|
// printf("count = %ld result = %d\n", strlen(buf), result);
|
||||||
printf("Recieved %d from client\n", message);
|
printf("Recieved %d from client\n", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,10 +326,10 @@ int iperf_udp_recv(struct iperf_stream *sp)
|
|||||||
//interprete the type of message in packet
|
//interprete the type of message in packet
|
||||||
if(result > 0)
|
if(result > 0)
|
||||||
{
|
{
|
||||||
message = ntohl(udp->state);
|
message = udp->state;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(message != STREAM_END && message != STREAM_BEGIN && (sp->stream_id == udp->stream_id))
|
if(message == STREAM_RUNNING && (sp->stream_id == udp->stream_id))
|
||||||
{
|
{
|
||||||
sp->result->bytes_received+= result;
|
sp->result->bytes_received+= result;
|
||||||
if(udp->packet_count == sp->packet_count + 1)
|
if(udp->packet_count == sp->packet_count + 1)
|
||||||
@ -384,52 +387,43 @@ int iperf_tcp_send(struct iperf_stream *sp)
|
|||||||
perror("malloc: unable to allocate transmit buffer");
|
perror("malloc: unable to allocate transmit buffer");
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(buf,0, size);
|
|
||||||
|
|
||||||
struct tcp_datagram *tcp = (struct tcp_datagram *) buf;
|
|
||||||
|
|
||||||
switch(sp->settings->state)
|
switch(sp->settings->state)
|
||||||
{
|
{
|
||||||
case STREAM_BEGIN:
|
case STREAM_BEGIN:
|
||||||
tcp->state = htonl(STREAM_BEGIN);
|
buf[0]= (STREAM_BEGIN);
|
||||||
tcp->stream_id = htonl((int)sp);
|
for(i=1; i < size; i++)
|
||||||
|
buf[i] = 97;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STREAM_END:
|
case STREAM_END:
|
||||||
tcp->state = htonl(STREAM_END);
|
buf[0]= (STREAM_END);
|
||||||
printf("sent stream_end\n");
|
for(i=1; i < size; i++)
|
||||||
tcp->stream_id = htonl((int)sp);
|
buf[i] = 97;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RESULT_REQUEST:
|
case RESULT_REQUEST:
|
||||||
tcp->state = htonl(RESULT_REQUEST);
|
buf[0]= (RESULT_REQUEST);
|
||||||
tcp->stream_id = htonl((int)sp);
|
for(i=1; i < size; i++)
|
||||||
|
buf[i] = 97;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALL_STREAMS_END:
|
case ALL_STREAMS_END:
|
||||||
tcp->state = htonl(ALL_STREAMS_END);
|
buf[0]= (ALL_STREAMS_END);
|
||||||
tcp->stream_id = htonl((int)sp);
|
for(i=1; i < size; i++)
|
||||||
|
buf[i] = 97;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case STREAM_RUNNING:
|
||||||
|
buf[0]= STREAM_RUNNING;
|
||||||
|
for(i=1; i < size; i++)
|
||||||
|
buf[i] = 97;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
tcp->state = htonl(0);
|
printf("State of the stream can't be determined\n");
|
||||||
tcp->stream_id = htonl((int)sp);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if(sp->settings->state == RESULT_REQUEST)
|
|
||||||
{
|
|
||||||
FILE *fp;
|
|
||||||
fp = fopen("send.txt", "w+");
|
|
||||||
buf[size] = '\0';
|
|
||||||
fwrite(buf, 1, size, fp);
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
//applicable for 1st packet sent
|
//applicable for 1st packet sent
|
||||||
if(sp->settings->state == STREAM_BEGIN)
|
if(sp->settings->state == STREAM_BEGIN)
|
||||||
@ -437,9 +431,9 @@ int iperf_tcp_send(struct iperf_stream *sp)
|
|||||||
sp->settings->state = STREAM_RUNNING;
|
sp->settings->state = STREAM_RUNNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = send(sp->socket, buf, size, 0);
|
result = send(sp->socket, buf, size , 0);
|
||||||
|
|
||||||
if(sp->settings->state != STREAM_END)
|
if(buf[0] != STREAM_END)
|
||||||
sp->result->bytes_sent+= size;
|
sp->result->bytes_sent+= size;
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
@ -477,28 +471,28 @@ int iperf_udp_send(struct iperf_stream *sp)
|
|||||||
switch(sp->settings->state)
|
switch(sp->settings->state)
|
||||||
{
|
{
|
||||||
case STREAM_BEGIN:
|
case STREAM_BEGIN:
|
||||||
udp->state = htonl(STREAM_BEGIN);
|
udp->state = STREAM_BEGIN;
|
||||||
udp->stream_id = htonl((int)sp);
|
udp->stream_id = (int)sp;
|
||||||
//udp->packet_count = ++sp->packet_count;
|
//udp->packet_count = ++sp->packet_count;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STREAM_END:
|
case STREAM_END:
|
||||||
udp->state = htonl(STREAM_END);
|
udp->state = STREAM_END;
|
||||||
udp->stream_id = htonl((int)sp);
|
udp->stream_id = (int) sp;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RESULT_REQUEST:
|
case RESULT_REQUEST:
|
||||||
udp->state = htonl(RESULT_REQUEST);
|
udp->state = RESULT_REQUEST;
|
||||||
udp->stream_id = htonl((int)sp);
|
udp->stream_id = (int) sp;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALL_STREAMS_END:
|
case ALL_STREAMS_END:
|
||||||
udp->state = htonl(ALL_STREAMS_END);
|
udp->state = ALL_STREAMS_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case STREAM_RUNNING:
|
||||||
udp->state = htonl(0);
|
udp->state = STREAM_RUNNING;
|
||||||
udp->stream_id = htonl((int)sp);
|
udp->stream_id = (int) sp;
|
||||||
udp->packet_count = ++sp->packet_count;
|
udp->packet_count = ++sp->packet_count;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -517,8 +511,9 @@ int iperf_udp_send(struct iperf_stream *sp)
|
|||||||
//else
|
//else
|
||||||
result = send(sp->socket, buf, size, 0);
|
result = send(sp->socket, buf, size, 0);
|
||||||
|
|
||||||
if(sp->settings->state == STREAM_RUNNING)
|
// CHECK: Packet length and ID
|
||||||
// printf("State = %d Outgoing packet = %d AND SP = %d\n",sp->settings->state, sp->packet_count, sp->socket);
|
//if(sp->settings->state == STREAM_RUNNING)
|
||||||
|
// printf("State = %d Outgoing packet = %d AND SP = %d\n",sp->settings->state, sp->packet_count, sp->socket);
|
||||||
|
|
||||||
if(sp->settings->state == STREAM_RUNNING)
|
if(sp->settings->state == STREAM_RUNNING)
|
||||||
sp->result->bytes_sent+= result;
|
sp->result->bytes_sent+= result;
|
||||||
@ -745,6 +740,7 @@ char *iperf_reporter_callback(struct iperf_test *test)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *message_final = (char *) malloc((count+1) * (strlen(report_bw_jitter_loss_header) + strlen(report_bw_jitter_loss_format) + strlen(report_sum_bw_jitter_loss_format)));
|
char *message_final = (char *) malloc((count+1) * (strlen(report_bw_jitter_loss_header) + strlen(report_bw_jitter_loss_format) + strlen(report_sum_bw_jitter_loss_format)));
|
||||||
|
memset(message_final,0, strlen(message_final));
|
||||||
|
|
||||||
struct iperf_interval_results *ip = test->streams->result->interval_results;
|
struct iperf_interval_results *ip = test->streams->result->interval_results;
|
||||||
|
|
||||||
@ -968,6 +964,9 @@ struct iperf_stream *iperf_new_stream(struct iperf_test *testp)
|
|||||||
sp->outoforder_packets = 0;
|
sp->outoforder_packets = 0;
|
||||||
sp->cnt_error = 0;
|
sp->cnt_error = 0;
|
||||||
|
|
||||||
|
sp->send_timer = NULL;
|
||||||
|
|
||||||
|
sp->result->interval_results = NULL;
|
||||||
sp->result->bytes_received = 0;
|
sp->result->bytes_received = 0;
|
||||||
sp->result->bytes_sent = 0;
|
sp->result->bytes_sent = 0;
|
||||||
gettimeofday(&sp->result->start_time, NULL);
|
gettimeofday(&sp->result->start_time, NULL);
|
||||||
@ -1310,7 +1309,8 @@ void iperf_run_server(struct iperf_test *test)
|
|||||||
np->settings->state = STREAM_END;
|
np->settings->state = STREAM_END;
|
||||||
gettimeofday(&np->result->end_time, NULL);
|
gettimeofday(&np->result->end_time, NULL);
|
||||||
}
|
}
|
||||||
np = np->next;
|
|
||||||
|
np = np->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is necessary to preserve reporting format
|
// This is necessary to preserve reporting format
|
||||||
@ -1426,7 +1426,7 @@ void iperf_run_client(struct iperf_test *test)
|
|||||||
|
|
||||||
}// while outer timer
|
}// while outer timer
|
||||||
|
|
||||||
// for last interval
|
// for last interval
|
||||||
test->stats_callback(test);
|
test->stats_callback(test);
|
||||||
read = test->reporter_callback(test);
|
read = test->reporter_callback(test);
|
||||||
puts(read);
|
puts(read);
|
||||||
|
Loading…
Reference in New Issue
Block a user