added support for abrupt termination Ctrl+c
This commit is contained in:
parent
27a5c9f3ec
commit
702c882fe2
@ -17,6 +17,9 @@
|
|||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include<sys/resource.h>
|
#include<sys/resource.h>
|
||||||
|
#include<sched.h>
|
||||||
|
#include<signal.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
#include "iperf_api.h"
|
#include "iperf_api.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
@ -45,6 +48,7 @@ static struct option longopts[] =
|
|||||||
{ NULL, 0, NULL, 0 }
|
{ NULL, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
jmp_buf env;
|
||||||
|
|
||||||
int all_data_sent(struct iperf_test *test)
|
int all_data_sent(struct iperf_test *test)
|
||||||
{
|
{
|
||||||
@ -431,7 +435,7 @@ int iperf_tcp_recv(struct iperf_stream *sp)
|
|||||||
|
|
||||||
if(message != 7)
|
if(message != 7)
|
||||||
{
|
{
|
||||||
printf("result = %d state = %d, %d = error\n",result, sp->buffer[0], errno);
|
//printf("result = %d state = %d, %d = error\n",result, sp->buffer[0], errno);
|
||||||
message = param_received(sp, param);
|
message = param_received(sp, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,7 +471,7 @@ int iperf_udp_recv(struct iperf_stream *sp)
|
|||||||
|
|
||||||
if(message != 7)
|
if(message != 7)
|
||||||
{
|
{
|
||||||
printf("result = %d state = %d, %d = error\n",result, sp->buffer[0], errno);
|
//printf("result = %d state = %d, %d = error\n",result, sp->buffer[0], errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(message == STREAM_RUNNING && (sp->stream_id == udp->stream_id))
|
if(message == STREAM_RUNNING && (sp->stream_id == udp->stream_id))
|
||||||
@ -601,20 +605,11 @@ int iperf_udp_send(struct iperf_stream *sp)
|
|||||||
struct udp_datagram *udp = (struct udp_datagram *) sp->buffer;
|
struct udp_datagram *udp = (struct udp_datagram *) sp->buffer;
|
||||||
struct param_exchange *param =NULL;
|
struct param_exchange *param =NULL;
|
||||||
|
|
||||||
if(!sp->buffer)
|
|
||||||
{
|
|
||||||
perror("malloc: unable to allocate transmit buffer");
|
|
||||||
}
|
|
||||||
|
|
||||||
dtargus = (int64_t)(sp->settings->blksize) * SEC_TO_US * 8;
|
dtargus = (int64_t)(sp->settings->blksize) * SEC_TO_US * 8;
|
||||||
dtargus /= sp->settings->rate;
|
dtargus /= sp->settings->rate;
|
||||||
|
|
||||||
assert(dtargus != 0);
|
assert(dtargus != 0);
|
||||||
|
|
||||||
// record the packet sent time
|
|
||||||
if(gettimeofday(&udp->sent_time, 0) < 0)
|
|
||||||
perror("gettimeofday");
|
|
||||||
|
|
||||||
switch(sp->settings->state)
|
switch(sp->settings->state)
|
||||||
{
|
{
|
||||||
case STREAM_BEGIN:
|
case STREAM_BEGIN:
|
||||||
@ -644,7 +639,6 @@ int iperf_udp_send(struct iperf_stream *sp)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// applicable for 1st packet sent for each stream
|
|
||||||
if(sp->settings->state == STREAM_BEGIN)
|
if(sp->settings->state == STREAM_BEGIN)
|
||||||
{
|
{
|
||||||
sp->settings->state = STREAM_RUNNING;
|
sp->settings->state = STREAM_RUNNING;
|
||||||
@ -653,6 +647,8 @@ int iperf_udp_send(struct iperf_stream *sp)
|
|||||||
if(gettimeofday(&before, 0) < 0)
|
if(gettimeofday(&before, 0) < 0)
|
||||||
perror("gettimeofday");
|
perror("gettimeofday");
|
||||||
|
|
||||||
|
udp->sent_time = before;
|
||||||
|
|
||||||
// TEST: lost packet
|
// TEST: lost packet
|
||||||
//if(udp->packet_count == 4 || udp->packet_count == 5 || udp->packet_count == 6) ;
|
//if(udp->packet_count == 4 || udp->packet_count == 5 || udp->packet_count == 6) ;
|
||||||
//else
|
//else
|
||||||
@ -675,8 +671,6 @@ int iperf_udp_send(struct iperf_stream *sp)
|
|||||||
if( adjustus > 0) {
|
if( adjustus > 0) {
|
||||||
dtargus = adjustus;
|
dtargus = adjustus;
|
||||||
}
|
}
|
||||||
// else
|
|
||||||
// printf("adjust = %lld \n", adjustus);
|
|
||||||
|
|
||||||
// RESET THE TIMER
|
// RESET THE TIMER
|
||||||
update_timer(sp->send_timer, 0, dtargus);
|
update_timer(sp->send_timer, 0, dtargus);
|
||||||
@ -1499,7 +1493,7 @@ void iperf_run_server(struct iperf_test *test)
|
|||||||
test->default_settings->state = RESULT_REQUEST;
|
test->default_settings->state = RESULT_REQUEST;
|
||||||
read = test->reporter_callback(test);
|
read = test->reporter_callback(test);
|
||||||
puts(read);
|
puts(read);
|
||||||
printf("REPORTER CALL + ALL_STREAMS_END\n");
|
//printf("REPORTER CALL + ALL_STREAMS_END\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}// end if (FD_ISSET(j, &temp_set))
|
}// end if (FD_ISSET(j, &temp_set))
|
||||||
@ -1514,6 +1508,13 @@ void iperf_run_server(struct iperf_test *test)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void catcher(int sig)
|
||||||
|
{
|
||||||
|
longjmp(env,sig);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void iperf_run_client(struct iperf_test *test)
|
void iperf_run_client(struct iperf_test *test)
|
||||||
{
|
{
|
||||||
int i,result=0;
|
int i,result=0;
|
||||||
@ -1524,9 +1525,18 @@ void iperf_run_client(struct iperf_test *test)
|
|||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int ret=0;
|
int ret=0;
|
||||||
|
|
||||||
|
int returned_from_longjump;
|
||||||
|
struct sigaction sact;
|
||||||
|
|
||||||
tv.tv_sec = 15; // timeout interval in seconds
|
tv.tv_sec = 15; // timeout interval in seconds
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
|
sigemptyset( &sact.sa_mask );
|
||||||
|
sact.sa_flags = 0;
|
||||||
|
sact.sa_handler = catcher;
|
||||||
|
sigaction( SIGINT, &sact, NULL );
|
||||||
|
|
||||||
|
|
||||||
buf = (char *) malloc(test->default_settings->blksize);
|
buf = (char *) malloc(test->default_settings->blksize);
|
||||||
|
|
||||||
if (test->protocol == Pudp)
|
if (test->protocol == Pudp)
|
||||||
@ -1582,25 +1592,6 @@ void iperf_run_client(struct iperf_test *test)
|
|||||||
}// FD_ISSET
|
}// FD_ISSET
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
//result =0 hence no data sent, hence sleep
|
|
||||||
if(result == 0 && test->protocol == Pudp)
|
|
||||||
{
|
|
||||||
sp = test->streams;
|
|
||||||
min = timer_remaining(sp->send_timer);
|
|
||||||
while(sp)
|
|
||||||
{
|
|
||||||
remaining = timer_remaining(sp->send_timer);
|
|
||||||
min = min < remaining ? min : remaining;
|
|
||||||
sp = sp->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
usleep(min/10);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
result = 0;
|
|
||||||
*/
|
|
||||||
|
|
||||||
if((test->stats_interval!= 0) && stats_interval->expired(stats_interval))
|
if((test->stats_interval!= 0) && stats_interval->expired(stats_interval))
|
||||||
{
|
{
|
||||||
test->stats_callback(test);
|
test->stats_callback(test);
|
||||||
@ -1614,6 +1605,10 @@ void iperf_run_client(struct iperf_test *test)
|
|||||||
reporter_interval = new_timer(test->reporter_interval,0);
|
reporter_interval = new_timer(test->reporter_interval,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// detecting Ctrl+C
|
||||||
|
if (setjmp(env))
|
||||||
|
break;
|
||||||
|
|
||||||
}// while outer timer
|
}// while outer timer
|
||||||
|
|
||||||
// for last interval
|
// for last interval
|
||||||
@ -1688,6 +1683,9 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
//increasing the priority of the process to minimise packet generation
|
//increasing the priority of the process to minimise packet generation
|
||||||
//delay
|
//delay
|
||||||
|
int priority = getpriority(PRIO_PROCESS, 0);
|
||||||
|
printf("priority is already zero\n");
|
||||||
|
|
||||||
int rc = setpriority(PRIO_PROCESS,0, -15);
|
int rc = setpriority(PRIO_PROCESS,0, -15);
|
||||||
if(rc < 0)
|
if(rc < 0)
|
||||||
{
|
{
|
||||||
@ -1696,6 +1694,26 @@ main(int argc, char **argv)
|
|||||||
rc = setpriority(PRIO_PROCESS, 0, 0);
|
rc = setpriority(PRIO_PROCESS, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
//setting the affinity of the process
|
||||||
|
cpu_set_t cpu_set;
|
||||||
|
int affinity = -1;
|
||||||
|
int ncores = 1;
|
||||||
|
sched_getaffinity(0, sizeof(cpu_set_t),&cpu_set);
|
||||||
|
if (errno)
|
||||||
|
perror("couldn't get affinity:");
|
||||||
|
|
||||||
|
|
||||||
|
if ((ncores = sysconf(_SC_NPROCESSORS_CONF)) <= 0)
|
||||||
|
err("sysconf: couldn't get _SC_NPROCESSORS_CONF");
|
||||||
|
|
||||||
|
CPU_ZERO(&cpu_set);
|
||||||
|
CPU_SET(affinity, &cpu_set);
|
||||||
|
if (sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set) != 0)
|
||||||
|
err("couldn't change CPU affinity");
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
test = iperf_new_test();
|
test = iperf_new_test();
|
||||||
|
Loading…
Reference in New Issue
Block a user