set fds_len in all cases; call set_wakeup only in two places
authorlurchi <lurchi@strangeplace.net>
Fri, 11 Aug 2017 16:49:55 +0000 (18:49 +0200)
committerlurchi <lurchi@strangeplace.net>
Fri, 11 Aug 2017 16:49:55 +0000 (18:49 +0200)
src/testbed/gnunet-helper-testbed.c
src/util/scheduler.c

index 392f257dd9b263fafceb4cba013a7435ebba86f7..5a5cfa0d2f5f0eefe88677074f96c85fe56eedbf 100644 (file)
@@ -556,6 +556,10 @@ run (void *cls,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  FILE *f = FOPEN ("helper_output", "w");
+  FPRINTF (f, "run\n");
+  FCLOSE (f);
+
   LOG_DEBUG ("Starting testbed helper...\n");
   tokenizer = GNUNET_MST_create (&tokenizer_cb, NULL);
   stdin_fd = GNUNET_DISK_get_handle_from_native (stdin);
@@ -604,6 +608,8 @@ main (int argc,
   };
   int ret;
 
+  //sleep (10);
+
   status = GNUNET_OK;
   if (NULL == (sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO,
                                            GNUNET_NO, GNUNET_NO)))
index ba4176a0ae20e0a4a2f2cc5ecfdd89760d15adbb..89b6e41f338a665f83a58c0d8062d45aa7789830 100644 (file)
@@ -722,6 +722,7 @@ init_fd_info (struct GNUNET_SCHEDULER_Task *t,
     struct GNUNET_SCHEDULER_FdInfo read_fdi = {.fd = read_nh, .et = GNUNET_SCHEDULER_ET_IN, .sock = GNUNET_NETWORK_get_fd (read_nh)};
     t->fdx = read_fdi;
     t->fds = &t->fdx;
+    t->fds_len = 1;
     t->read_fd = t->fdx.sock;
   }
   else if (NULL != write_nh)
@@ -729,6 +730,7 @@ init_fd_info (struct GNUNET_SCHEDULER_Task *t,
     struct GNUNET_SCHEDULER_FdInfo write_fdi = {.fd = write_nh, .et = GNUNET_SCHEDULER_ET_OUT, .sock = GNUNET_NETWORK_get_fd (write_nh)};
     t->fdx = write_fdi;
     t->fds = &t->fdx;
+    t->fds_len = 1;
     t->write_fd = t->fdx.sock;
   }
   else if (NULL != read_fh)
@@ -736,6 +738,7 @@ init_fd_info (struct GNUNET_SCHEDULER_Task *t,
     struct GNUNET_SCHEDULER_FdInfo read_fdi = {.fh = read_fh, .et = GNUNET_SCHEDULER_ET_IN, .sock = read_fh->fd};
     t->fdx = read_fdi;
     t->fds = &t->fdx;
+    t->fds_len = 1;
     t->read_fd = t->fdx.sock;
   }
   else if (NULL != write_fh)
@@ -743,6 +746,7 @@ init_fd_info (struct GNUNET_SCHEDULER_Task *t,
     struct GNUNET_SCHEDULER_FdInfo write_fdi = {.fh = write_fh, .et = GNUNET_SCHEDULER_ET_OUT, .sock = write_fh->fd};
     t->fdx = write_fdi;
     t->fds = &t->fdx;
+    t->fds_len = 1;
     t->write_fd = t->fdx.sock;
   }
 }
@@ -815,9 +819,6 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task)
                                      task);
         if (pending_timeout_last == task)
           pending_timeout_last = NULL;
-        else
-          scheduler_driver->set_wakeup (scheduler_driver->cls,
-                                        get_timeout ());
       }
       //TODO check if this is redundant
       if (task == pending_timeout_last)
@@ -951,8 +952,6 @@ GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at,
     GNUNET_CONTAINER_DLL_insert (pending_timeout_head,
                                  pending_timeout_tail,
                                  t);
-    scheduler_driver->set_wakeup (scheduler_driver->cls,
-                                  at);
   }
   else
   {
@@ -1260,8 +1259,6 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
                                pending_tail,
                                t);
   scheduler_multi_function_call(t, scheduler_driver->add);
-  scheduler_driver->set_wakeup (scheduler_driver->cls,
-                                get_timeout ());
   max_priority_added = GNUNET_MAX (max_priority_added,
                                    t->priority);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1585,8 +1582,6 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
                                pending_tail,
                                t);
   scheduler_multi_function_call(t, scheduler_driver->add);
-  scheduler_driver->set_wakeup (scheduler_driver->cls,
-                                get_timeout ());
   max_priority_added = GNUNET_MAX (max_priority_added,
            t->priority);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1625,6 +1620,7 @@ GNUNET_SCHEDULER_task_ready (struct GNUNET_SCHEDULER_Task *task,
        (0 != (GNUNET_SCHEDULER_ET_OUT & et)) )
     reason |= GNUNET_SCHEDULER_REASON_WRITE_READY;
   reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE;
+  GNUNET_assert (1 == task->fds_len);
   task->reason = reason;
   task->fds = &task->fdx; // FIXME: if task contains a list of fds, this is wrong!
   task->fdx.et = et;
@@ -1836,6 +1832,8 @@ GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver,
                                                  GNUNET_SCHEDULER_REASON_STARTUP,
                                                  GNUNET_SCHEDULER_PRIORITY_DEFAULT);
   active_task = NULL;
+  scheduler_driver->set_wakeup (scheduler_driver->cls,
+                                get_timeout ());
   /* begin main event loop */
   sh.rs = GNUNET_NETWORK_fdset_create ();
   sh.ws = GNUNET_NETWORK_fdset_create ();
@@ -1858,6 +1856,7 @@ GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver,
 #endif
   GNUNET_DISK_pipe_close (shutdown_pipe_handle);
   shutdown_pipe_handle = NULL;
+  scheduler_driver = NULL;
   return ret;
 }