aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_communicator_basic.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-12-25 15:27:25 +0100
committerChristian Grothoff <christian@grothoff.org>2019-12-25 15:27:25 +0100
commit362288ecbadeaf827a0a29908d42407ce1e2700a (patch)
tree04bb7f15531a33353d63ecf7cd71a00e5566a48d /src/transport/test_communicator_basic.c
parentf98ace798dbb16e6af57e823c30e96031c7df3e0 (diff)
downloadgnunet-362288ecbadeaf827a0a29908d42407ce1e2700a.tar.gz
gnunet-362288ecbadeaf827a0a29908d42407ce1e2700a.zip
avoid constantly adding/removing timeout task
Diffstat (limited to 'src/transport/test_communicator_basic.c')
-rw-r--r--src/transport/test_communicator_basic.c58
1 files changed, 22 insertions, 36 deletions
diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c
index 5d69b21b3..7dac3bc24 100644
--- a/src/transport/test_communicator_basic.c
+++ b/src/transport/test_communicator_basic.c
@@ -64,6 +64,8 @@ static struct GNUNET_TIME_Absolute start_short;
64 64
65static struct GNUNET_TIME_Absolute start_long; 65static struct GNUNET_TIME_Absolute start_long;
66 66
67static struct GNUNET_TIME_Absolute timeout;
68
67static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc; 69static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc;
68 70
69#define SHORT_MESSAGE_SIZE 128 71#define SHORT_MESSAGE_SIZE 128
@@ -196,9 +198,18 @@ static void
196latency_timeout (void *cls) 198latency_timeout (void *cls)
197{ 199{
198 to_task = NULL; 200 to_task = NULL;
201 if (GNUNET_TIME_absolute_get_remaining (timeout).rel_value_us > 0)
202 {
203 to_task = GNUNET_SCHEDULER_add_at (timeout,
204 &latency_timeout,
205 NULL);
206 return;
207 }
208
199 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
200 "Latency too high. Test failed. (Phase: %d. Received: %lu\n", 210 "Latency too high. Test failed. (Phase: %d. Received: %lu\n",
201 phase, num_received); 211 phase,
212 num_received);
202 ret = 2; 213 ret = 2;
203 GNUNET_SCHEDULER_shutdown (); 214 GNUNET_SCHEDULER_shutdown ();
204} 215}
@@ -220,10 +231,7 @@ size_test (void *cls)
220 GNUNET_free (payload); 231 GNUNET_free (payload);
221 ack += 5; 232 ack += 5;
222 num_sent++; 233 num_sent++;
223 if (NULL == to_task) 234 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
224 to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
225 &latency_timeout,
226 NULL);
227 if (ack < 64000) 235 if (ack < 64000)
228 active_task = GNUNET_SCHEDULER_add_now (&size_test, 236 active_task = GNUNET_SCHEDULER_add_now (&size_test,
229 NULL); 237 NULL);
@@ -242,10 +250,7 @@ long_test (void *cls)
242 LONG_MESSAGE_SIZE); 250 LONG_MESSAGE_SIZE);
243 num_sent++; 251 num_sent++;
244 GNUNET_free (payload); 252 GNUNET_free (payload);
245 if (NULL == to_task) 253 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
246 to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
247 &latency_timeout,
248 NULL);
249 if (num_sent == BURST_PACKETS) 254 if (num_sent == BURST_PACKETS)
250 return; 255 return;
251 active_task = GNUNET_SCHEDULER_add_now (&long_test, 256 active_task = GNUNET_SCHEDULER_add_now (&long_test,
@@ -265,10 +270,7 @@ short_test (void *cls)
265 SHORT_MESSAGE_SIZE); 270 SHORT_MESSAGE_SIZE);
266 num_sent++; 271 num_sent++;
267 GNUNET_free (payload); 272 GNUNET_free (payload);
268 if (NULL == to_task) 273 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
269 to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
270 &latency_timeout,
271 NULL);
272 if (num_sent >= BURST_PACKETS) 274 if (num_sent >= BURST_PACKETS)
273 return; 275 return;
274 active_task = GNUNET_SCHEDULER_add_now (&short_test, 276 active_task = GNUNET_SCHEDULER_add_now (&short_test,
@@ -300,6 +302,11 @@ add_queue_cb (void *cls,
300 start_short = GNUNET_TIME_absolute_get (); 302 start_short = GNUNET_TIME_absolute_get ();
301 my_tc = tc_queue; 303 my_tc = tc_queue;
302 phase = TP_BURST_SHORT; 304 phase = TP_BURST_SHORT;
305 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
306 GNUNET_assert (NULL == to_task);
307 to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
308 &latency_timeout,
309 NULL);
303 GNUNET_assert (NULL == active_task); 310 GNUNET_assert (NULL == active_task);
304 active_task = GNUNET_SCHEDULER_add_now (&short_test, 311 active_task = GNUNET_SCHEDULER_add_now (&short_test,
305 NULL); 312 NULL);
@@ -347,6 +354,8 @@ incoming_message_cb (void *cls,
347 "unexpected receiver...\n"); 354 "unexpected receiver...\n");
348 return; 355 return;
349 } 356 }
357 /* Reset timeout */
358 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
350 switch (phase) 359 switch (phase)
351 { 360 {
352 case TP_BURST_SHORT: 361 case TP_BURST_SHORT:
@@ -374,11 +383,6 @@ incoming_message_cb (void *cls,
374 num_sent = 0; 383 num_sent = 0;
375 avg_latency = 0; 384 avg_latency = 0;
376 num_received = 0; 385 num_received = 0;
377 if (NULL != to_task)
378 {
379 GNUNET_SCHEDULER_cancel (to_task);
380 to_task = NULL;
381 }
382 active_task = GNUNET_SCHEDULER_add_now (&long_test, 386 active_task = GNUNET_SCHEDULER_add_now (&long_test,
383 NULL); 387 NULL);
384 } 388 }
@@ -414,11 +418,6 @@ incoming_message_cb (void *cls,
414 num_received = 0; 418 num_received = 0;
415 num_sent = 0; 419 num_sent = 0;
416 avg_latency = 0; 420 avg_latency = 0;
417 if (NULL != to_task)
418 {
419 GNUNET_SCHEDULER_cancel (to_task);
420 to_task = NULL;
421 }
422 active_task = GNUNET_SCHEDULER_add_now (&size_test, 421 active_task = GNUNET_SCHEDULER_add_now (&size_test,
423 NULL); 422 NULL);
424 } 423 }
@@ -440,11 +439,6 @@ incoming_message_cb (void *cls,
440 num_received = 0; 439 num_received = 0;
441 num_sent = 0; 440 num_sent = 0;
442 avg_latency = 0; 441 avg_latency = 0;
443 if (NULL != to_task)
444 {
445 GNUNET_SCHEDULER_cancel (to_task);
446 to_task = NULL;
447 }
448 iterations_left--; 442 iterations_left--;
449 if (0 != iterations_left) 443 if (0 != iterations_left)
450 { 444 {
@@ -460,14 +454,6 @@ incoming_message_cb (void *cls,
460 break; 454 break;
461 } 455 }
462 } 456 }
463 /* Reset timeout */
464 if (NULL != to_task)
465 {
466 GNUNET_SCHEDULER_cancel (to_task);
467 to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
468 &latency_timeout,
469 NULL);
470 }
471} 457}
472 458
473 459