diff options
Diffstat (limited to 'src/lib/eventloop.c')
-rw-r--r-- | src/lib/eventloop.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/src/lib/eventloop.c b/src/lib/eventloop.c index 42a2b89d..cc0ab120 100644 --- a/src/lib/eventloop.c +++ b/src/lib/eventloop.c | |||
@@ -27,11 +27,11 @@ | |||
27 | 27 | ||
28 | #define DEBUG_EVENTLOOP GNUNET_NO | 28 | #define DEBUG_EVENTLOOP GNUNET_NO |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Initial size of our poll array cache. | 31 | * Initial size of our poll array cache. |
32 | * | 32 | * |
33 | * TODO: get some statistics, find the maximum number of fds ever | 33 | * TODO: get some statistics, find the maximum number of fds ever |
34 | * polled during normal gnunet-gtk operation, and set this to that number. | 34 | * polled during normal gnunet-gtk operation, and set this to that number. |
35 | */ | 35 | */ |
36 | #define INITIAL_POLL_ARRAY_SIZE 30 | 36 | #define INITIAL_POLL_ARRAY_SIZE 30 |
37 | 37 | ||
@@ -178,8 +178,12 @@ void | |||
178 | GNUNET_GTK_main_loop_quit (struct GNUNET_GTK_MainLoop *ml) | 178 | GNUNET_GTK_main_loop_quit (struct GNUNET_GTK_MainLoop *ml) |
179 | { | 179 | { |
180 | g_main_loop_quit (ml->gml); | 180 | g_main_loop_quit (ml->gml); |
181 | GNUNET_SCHEDULER_cancel (ml->dummy_task); | 181 | ml->gml = NULL; |
182 | ml->dummy_task = GNUNET_SCHEDULER_NO_TASK; | 182 | if (GNUNET_SCHEDULER_NO_TASK != ml->dummy_task) |
183 | { | ||
184 | GNUNET_SCHEDULER_cancel (ml->dummy_task); | ||
185 | ml->dummy_task = GNUNET_SCHEDULER_NO_TASK; | ||
186 | } | ||
183 | } | 187 | } |
184 | 188 | ||
185 | 189 | ||
@@ -546,18 +550,20 @@ gnunet_gtk_select (void *cls, struct GNUNET_NETWORK_FDSet *rfds, | |||
546 | #endif | 550 | #endif |
547 | 551 | ||
548 | /* combine with Gtk events */ | 552 | /* combine with Gtk events */ |
549 | g_main_context_prepare (ml->gmc, &max_priority); | 553 | if (NULL != ml->gmc) |
550 | while (1) | ||
551 | { | 554 | { |
552 | need_gfds = | 555 | g_main_context_prepare (ml->gmc, &max_priority); |
553 | g_main_context_query (ml->gmc, max_priority, &delay, | 556 | while (1) |
554 | &ml->cached_poll_array[fd_counter], | 557 | { |
555 | ml->cached_poll_array_size - fd_counter); | 558 | need_gfds = |
556 | if (ml->cached_poll_array_size >= need_gfds + fd_counter) | 559 | g_main_context_query (ml->gmc, max_priority, &delay, |
557 | break; | 560 | &ml->cached_poll_array[fd_counter], |
558 | resize_cached_poll_array (ml, fd_counter + need_gfds); | 561 | ml->cached_poll_array_size - fd_counter); |
562 | if (ml->cached_poll_array_size >= need_gfds + fd_counter) | ||
563 | break; | ||
564 | resize_cached_poll_array (ml, fd_counter + need_gfds); | ||
565 | } | ||
559 | } | 566 | } |
560 | |||
561 | if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) | 567 | if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) |
562 | { | 568 | { |
563 | if (delay >= 0) | 569 | if (delay >= 0) |
@@ -597,12 +603,14 @@ gnunet_gtk_select (void *cls, struct GNUNET_NETWORK_FDSet *rfds, | |||
597 | * from within a task (currently we're not in a task, but in a select() call, remember) | 603 | * from within a task (currently we're not in a task, but in a select() call, remember) |
598 | * Startup reason is used to pass the scheduler sanity check. | 604 | * Startup reason is used to pass the scheduler sanity check. |
599 | */ | 605 | */ |
600 | if (TRUE == | 606 | if (NULL != ml->gmc) |
601 | g_main_context_check (ml->gmc, max_priority, | 607 | { |
602 | &ml->cached_poll_array[fd_counter], need_gfds)) | 608 | if (TRUE == |
603 | GNUNET_SCHEDULER_add_continuation (&dispatch_gtk_task, ml, | 609 | g_main_context_check (ml->gmc, max_priority, |
604 | GNUNET_SCHEDULER_REASON_STARTUP); | 610 | &ml->cached_poll_array[fd_counter], need_gfds)) |
605 | 611 | GNUNET_SCHEDULER_add_continuation (&dispatch_gtk_task, ml, | |
612 | GNUNET_SCHEDULER_REASON_STARTUP); | ||
613 | } | ||
606 | /* Now map back GNUnet scheduler events ... */ | 614 | /* Now map back GNUnet scheduler events ... */ |
607 | #if !WINDOWS | 615 | #if !WINDOWS |
608 | if (NULL != rfds) | 616 | if (NULL != rfds) |