diff --git a/src/iperf.h b/src/iperf.h index 9067b3b..31cc1b4 100644 --- a/src/iperf.h +++ b/src/iperf.h @@ -196,21 +196,19 @@ enum TEST_START = 1, TEST_RUNNING = 2, RESULT_REQUEST = 3, - RESULT_RESPOND = 4, - TEST_END = 5, - STREAM_BEGIN = 6, - STREAM_RUNNING = 7, - STREAM_END = 8, - ALL_STREAMS_END = 9, - PARAM_EXCHANGE = 10, - PARAM_EXCHANGE_ACK = 11, - CREATE_STREAMS = 12, - SERVER_TERMINATE = 13, - CLIENT_TERMINATE = 14, - EXCHANGE_RESULTS = 15, - DISPLAY_RESULTS = 16, - IPERF_START = 17, - IPERF_DONE = 18, + TEST_END = 4, + STREAM_BEGIN = 5, + STREAM_RUNNING = 6, + STREAM_END = 7, + ALL_STREAMS_END = 8, + PARAM_EXCHANGE = 9, + CREATE_STREAMS = 10, + SERVER_TERMINATE = 11, + CLIENT_TERMINATE = 12, + EXCHANGE_RESULTS = 13, + DISPLAY_RESULTS = 14, + IPERF_START = 15, + IPERF_DONE = 16, ACCESS_DENIED = -1, }; diff --git a/src/iperf_api.c b/src/iperf_api.c index f0c5b48..f7cbc25 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -136,8 +136,8 @@ iperf_send(struct iperf_test *test) reporter_interval = new_timer(test->reporter_interval, 0); test->state = TEST_RUNNING; - if (write(test->ctrl_sck, &test->state, sizeof(char)) < 0) { - perror("write TEST_RUNNING"); + if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) { + perror("Nwrite TEST_RUNNING"); exit(1); } @@ -178,8 +178,8 @@ iperf_send(struct iperf_test *test) free_timer(reporter_interval); test->state = TEST_END; - if (write(test->ctrl_sck, &test->state, sizeof(char)) < 0) { - perror("write TEST_END"); + if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) { + perror("Nwrite TEST_END"); return -1; } test->stats_callback(test); @@ -270,8 +270,8 @@ package_parameters(struct iperf_test *test) *pstring = (char) (strlen(pstring) - 1); - if (write(test->ctrl_sck, pstring, (size_t) strlen(pstring)) < 0) { - perror("write pstring"); + if (Nwrite(test->ctrl_sck, pstring, (size_t) strlen(pstring), Ptcp) < 0) { + perror("Nwrite pstring"); return -1; } @@ -363,7 +363,6 @@ iperf_exchange_parameters(struct iperf_test * test) package_parameters(test); } else { - parse_parameters(test); printf(" cookie: %s\n", test->default_settings->cookie); @@ -376,8 +375,8 @@ iperf_exchange_parameters(struct iperf_test * test) // Send the control message to create streams and start the test test->state = CREATE_STREAMS; - if (write(test->ctrl_sck, &test->state, sizeof(char)) < 0) { - perror("write CREATE_STREAMS"); + if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) { + perror("Nwrite CREATE_STREAMS"); return -1; } @@ -719,6 +718,9 @@ iperf_handle_message_client(struct iperf_test *test) } switch (test->state) { + case PARAM_EXCHANGE: + iperf_exchange_parameters(test); + break; case CREATE_STREAMS: iperf_create_streams(test); break; @@ -727,9 +729,11 @@ iperf_handle_message_client(struct iperf_test *test) case TEST_RUNNING: break; case TEST_END: - break; - case PARAM_EXCHANGE: - iperf_exchange_parameters(test); + if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) { + perror("Nwrite TEST_END\n"); + return -1; + } + test->stats_callback(test); break; case EXCHANGE_RESULTS: iperf_exchange_results(test); @@ -1146,8 +1150,8 @@ iperf_client_end(struct iperf_test *test) } test->state = IPERF_DONE; - if (write(test->ctrl_sck, &test->state, sizeof(char)) < 0) { - perror("write IPERF_DONE"); + if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) { + perror("Nwrite IPERF_DONE"); return -1; } @@ -1172,12 +1176,12 @@ iperf_run_client(struct iperf_test * test) // set error and return return -1; } - + signal(SIGINT, sig_handler); if (setjmp(env)) { fprintf(stderr, "Interrupt received. Exiting...\n"); test->state = CLIENT_TERMINATE; - if (write(test->ctrl_sck, &test->state, sizeof(char)) < 0) { + if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) { fprintf(stderr, "Unable to send CLIENT_TERMINATE message to serer\n"); } exit(1); diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c index 02e4890..337681e 100644 --- a/src/iperf_server_api.c +++ b/src/iperf_server_api.c @@ -160,8 +160,8 @@ iperf_accept(struct iperf_test *test) } } } else { - if (write(s, &rbuf, sizeof(int)) < 0) { - perror("write"); + if (Nwrite(s, &rbuf, sizeof(int), Ptcp) < 0) { + perror("Nwrite ACCESS_DENIED"); return -1; } close(s); @@ -183,9 +183,6 @@ iperf_handle_message_server(struct iperf_test *test) } switch(test->state) { - case PARAM_EXCHANGE: - iperf_exchange_parameters(test); - break; case TEST_START: break; case TEST_RUNNING: @@ -197,14 +194,14 @@ iperf_handle_message_server(struct iperf_test *test) close(sp->socket); } test->state = EXCHANGE_RESULTS; - if (write(test->ctrl_sck, &test->state, sizeof(char)) < 0) { - perror("write EXCHANGE_RESULTS"); + if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) { + perror("Nwrite EXCHANGE_RESULTS"); exit(1); } iperf_exchange_results(test); test->state = DISPLAY_RESULTS; - if (write(test->ctrl_sck, &test->state, sizeof(char)) < 0) { - perror("write DISPLAY_RESULTS"); + if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) { + perror("Nwrite DISPLAY_RESULTS"); exit(1); } test->stats_callback(test); @@ -283,7 +280,7 @@ iperf_run_server(struct iperf_test *test) fprintf(stderr, "Interrupt received. Exiting...\n"); test->state = SERVER_TERMINATE; if (test->ctrl_sck >= 0) { - if (write(test->ctrl_sck, &test->state, sizeof(char)) < 0) { + if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) { fprintf(stderr, "Unable to send SERVER_TERMINATE message to client\n"); } }