attempting to fix #5006
[oweals/gnunet.git] / src / include / gnunet_scheduler_lib.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2009-2016 GNUnet e.V.
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18       Boston, MA 02110-1301, USA.
19  */
20
21 /**
22  * @author Christian Grothoff
23  *
24  * @file
25  * API to schedule computations using continuation passing style
26  *
27  * @defgroup scheduler  Scheduler library
28  * Event loop (scheduler)
29  *
30  * Schedule computations using continuation passing style.
31  *
32  * @{
33  */
34
35 #ifndef GNUNET_SCHEDULER_LIB_H
36 #define GNUNET_SCHEDULER_LIB_H
37
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #if 0                           /* keep Emacsens' auto-indent happy */
42 }
43 #endif
44 #endif
45
46 /**
47  * Opaque reference to a task.
48  */
49 struct GNUNET_SCHEDULER_Task;
50
51 /**
52  * Reasons why the schedule may have triggered
53  * the task now.
54  */
55 enum GNUNET_SCHEDULER_Reason
56 {
57   /**
58    * This task is not ready.
59    */
60   GNUNET_SCHEDULER_REASON_NONE = 0,
61
62   /**
63    * This is the very first task run during startup.
64    */
65   GNUNET_SCHEDULER_REASON_STARTUP = 1,
66
67   /**
68    * We are shutting down and are running all shutdown-related tasks.
69    */
70   GNUNET_SCHEDULER_REASON_SHUTDOWN = 2,
71
72   /**
73    * The specified timeout has expired.
74    * (also set if the delay given was 0).
75    */
76   GNUNET_SCHEDULER_REASON_TIMEOUT = 4,
77
78   /**
79    * The reading socket is ready.
80    */
81   GNUNET_SCHEDULER_REASON_READ_READY = 8,
82
83   /**
84    * The writing socket is ready.
85    */
86   GNUNET_SCHEDULER_REASON_WRITE_READY = 16,
87
88   /**
89    * The prerequisite task is done.
90    */
91   GNUNET_SCHEDULER_REASON_PREREQ_DONE = 32
92 };
93
94
95 #include "gnunet_time_lib.h"
96 #include "gnunet_network_lib.h"
97
98
99 /**
100  * Possible events on FDs, used as a bitmask.
101  * Modelled after GPollFD.
102  */
103 enum GNUNET_SCHEDULER_EventType
104 {
105
106   /**
107    * No event (useful for timeout).
108    */
109   GNUNET_SCHEDULER_ET_NONE = 0,
110
111   /**
112    * Data available for reading.
113    */
114   GNUNET_SCHEDULER_ET_IN = 1,
115
116   /**
117    * Buffer available for writing.
118    */
119   GNUNET_SCHEDULER_ET_OUT = 2,
120
121   /**
122    *
123    */
124   GNUNET_SCHEDULER_ET_HUP = 4,
125
126   /**
127    *
128    */
129   GNUNET_SCHEDULER_ET_ERR = 8,
130
131   /**
132    *
133    */
134   GNUNET_SCHEDULER_ET_PRI = 16,
135
136   /**
137    *
138    */
139   GNUNET_SCHEDULER_ET_NVAL = 32
140
141 };
142
143
144 /**
145  * Information about an event relating to a file descriptor/socket.
146  */
147 struct GNUNET_SCHEDULER_FdInfo
148 {
149
150   /**
151    * GNUnet network socket the event is about, matches @a sock,
152    * NULL if this is about a file handle or if no network
153    * handle was given to the scheduler originally.
154    */
155   struct GNUNET_NETWORK_Handle *fd;
156
157   /**
158    * GNUnet file handle the event is about, matches @a sock,
159    * NULL if this is about a network socket or if no network
160    * handle was given to the scheduler originally.
161    */
162   struct GNUNET_DISK_FileHandle *fh;
163
164   /**
165    * Type of the event that was generated related to @e sock.
166    */
167   enum GNUNET_SCHEDULER_EventType et;
168
169   /**
170    * Underlying OS handle the event was about.
171    */
172   int sock;
173
174 };
175
176
177 /**
178  * Context information passed to each scheduler task.
179  */
180 struct GNUNET_SCHEDULER_TaskContext
181 {
182   /**
183    * Reason why the task is run now
184    */
185   enum GNUNET_SCHEDULER_Reason reason;
186
187   /**
188    * Length of the following array.
189    */
190   unsigned int fds_len;
191
192   /**
193    * Array of length @e fds_len with information about ready FDs.
194    * Note that we use the same format regardless of the internal
195    * event loop that was used.  The given array should only contain
196    * information about file descriptors relevant to the current task.
197    */
198   const struct GNUNET_SCHEDULER_FdInfo *fds;
199
200   /**
201    * Set of file descriptors ready for reading; note that additional
202    * bits may be set that were not in the original request.
203    * @deprecated
204    */
205   const struct GNUNET_NETWORK_FDSet *read_ready;
206
207   /**
208    * Set of file descriptors ready for writing; note that additional
209    * bits may be set that were not in the original request.
210    * @deprecated
211    */
212   const struct GNUNET_NETWORK_FDSet *write_ready;
213
214 };
215
216
217 /**
218  * Function used by event-loop implementations to signal the scheduler
219  * that a particular @a task is ready due to an event of type @a et.
220  *
221  * This function will then queue the task to notify the application
222  * that the task is ready (with the respective priority).
223  *
224  * @param task the task that is ready
225  * @param et information about why the task is ready
226  */
227 void
228 GNUNET_SCHEDULER_task_ready (struct GNUNET_SCHEDULER_Task *task,
229                              enum GNUNET_SCHEDULER_EventType et);
230
231
232 /**
233  * Handle to the scheduler's state to be used by the driver.
234  */
235 struct GNUNET_SCHEDULER_Handle;
236
237
238 /**
239  * Function called by the driver to tell the scheduler to run some of
240  * the tasks that are ready.  This function may return even though
241  * there are tasks left to run just to give other tasks a chance as
242  * well.  If we return #GNUNET_YES, the driver should call this
243  * function again as soon as possible, while if we return #GNUNET_NO
244  * it must block until the operating system has more work as the
245  * scheduler has no more work to do right now.
246  *
247  * @param sh scheduler handle that was given to the `loop`
248  * @return #GNUNET_OK if there are more tasks that are ready,
249  *          and thus we would like to run more (yield to avoid
250  *          blocking other activities for too long)
251  *         #GNUNET_NO if we are done running tasks (yield to block)
252  *         #GNUNET_SYSERR on error
253  */
254 int
255 GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh);
256
257
258 /**
259  * API a driver has to implement for
260  * #GNUNET_SCHEDULER_run_with_driver().
261  */
262 struct GNUNET_SCHEDULER_Driver
263 {
264
265   /**
266    * Closure to pass to the functions in this struct.
267    */
268   void *cls;
269
270   /**
271    * Add a @a task to be run if the conditions given
272    * in @a fdi are satisfied.
273    *
274    * @param cls closure
275    * @param task task to add
276    * @param fdi conditions to watch for
277    * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
278    *   (i.e. @a fdi too high or invalid)
279    */
280   int
281   (*add)(void *cls,
282          struct GNUNET_SCHEDULER_Task *task,
283          struct GNUNET_SCHEDULER_FdInfo *fdi);
284
285   /**
286    * Delete a @a task from the set of tasks to be run.
287    *
288    * @param cls closure
289    * @param task task to delete
290    * @param fdi conditions to watch for (must match @e add call)
291    * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
292    *   (i.e. @a task or @a fdi do not match prior @e add call)
293    */
294   int
295   (*del)(void *cls,
296          struct GNUNET_SCHEDULER_Task *task,
297          const struct GNUNET_SCHEDULER_FdInfo *fdi);
298
299   /**
300    * Set time at which we definitively want to get a wakeup call.
301    *
302    * @param cls closure
303    * @param dt time when we want to wake up next
304    */
305   void
306   (*set_wakeup)(void *cls,
307                 struct GNUNET_TIME_Absolute dt);
308
309   /**
310    * Event loop's "main" function, to be called from
311    * #GNUNET_SCHEDULER_run_with_driver() to actually
312    * launch the loop.
313    *
314    * @param cls closure
315    * @param sh scheduler handle to pass to
316    *     #GNUNET_SCHEDULER_run_from_driver()
317    * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
318    */
319   int
320   (*loop)(void *cls,
321           struct GNUNET_SCHEDULER_Handle *sh);
322
323 };
324
325
326 /**
327  * Signature of the main function of a task.
328  *
329  * @param cls closure
330  */
331 typedef void
332 (*GNUNET_SCHEDULER_TaskCallback) (void *cls);
333
334
335 /**
336  * Initialize and run scheduler.  This function will return when all
337  * tasks have completed.  On systems with signals, receiving a SIGTERM
338  * (and other similar signals) will cause #GNUNET_SCHEDULER_shutdown
339  * to be run after the active task is complete.  As a result, SIGTERM
340  * causes all shutdown tasks to be scheduled with reason
341  * #GNUNET_SCHEDULER_REASON_SHUTDOWN.  (However, tasks added
342  * afterwards will execute normally!).  Note that any particular
343  * signal will only shut down one scheduler; applications should
344  * always only create a single scheduler.
345  *
346  * @param driver drive to use for the event loop
347  * @param task task to run first (and immediately)
348  * @param task_cls closure of @a task
349  * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
350  */
351 int
352 GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver,
353                                   GNUNET_SCHEDULER_TaskCallback task,
354                                   void *task_cls);
355
356
357 /**
358  * Obtain the driver for using select() as the event loop.
359  *
360  * @return NULL on error
361  */
362 const struct GNUNET_SCHEDULER_Driver *
363 GNUNET_SCHEDULER_driver_select (void);
364
365
366 /**
367  * Signature of the select function used by the scheduler.
368  * #GNUNET_NETWORK_socket_select matches it.
369  *
370  * @param cls closure
371  * @param rfds set of sockets to be checked for readability
372  * @param wfds set of sockets to be checked for writability
373  * @param efds set of sockets to be checked for exceptions
374  * @param timeout relative value when to return
375  * @return number of selected sockets, #GNUNET_SYSERR on error
376  */
377 typedef int
378 (*GNUNET_SCHEDULER_select) (void *cls,
379                             struct GNUNET_NETWORK_FDSet *rfds,
380                             struct GNUNET_NETWORK_FDSet *wfds,
381                             struct GNUNET_NETWORK_FDSet *efds,
382                             struct GNUNET_TIME_Relative timeout);
383
384
385 /**
386  * Initialize and run scheduler.  This function will return when all
387  * tasks have completed.  On systems with signals, receiving a SIGTERM
388  * (and other similar signals) will cause #GNUNET_SCHEDULER_shutdown
389  * to be run after the active task is complete.  As a result, SIGTERM
390  * causes all shutdown tasks to be scheduled with reason
391  * #GNUNET_SCHEDULER_REASON_SHUTDOWN.  (However, tasks added
392  * afterwards will execute normally!).  Note that any particular
393  * signal will only shut down one scheduler; applications should
394  * always only create a single scheduler.
395  *
396  * @param task task to run first (and immediately)
397  * @param task_cls closure of @a task
398  */
399 void
400 GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
401                       void *task_cls);
402
403
404 /**
405  * Request the shutdown of a scheduler.  Marks all tasks
406  * awaiting shutdown as ready. Note that tasks
407  * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call
408  * will be delayed until the next shutdown signal.
409  */
410 void
411 GNUNET_SCHEDULER_shutdown (void);
412
413
414 /**
415  * Get information about the current load of this scheduler.  Use this
416  * function to determine if an elective task should be added or simply
417  * dropped (if the decision should be made based on the number of
418  * tasks ready to run).
419  *
420  * @param p priority-level to query, use KEEP to query the level
421  *          of the current task, use COUNT to get the sum over
422  *          all priority levels
423  * @return number of tasks pending right now
424  */
425 unsigned int
426 GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p);
427
428
429 /**
430  * Obtain the reasoning why the current task was
431  * started.
432  *
433  * @return task context with information why the current task is run
434  */
435 const struct GNUNET_SCHEDULER_TaskContext *
436 GNUNET_SCHEDULER_get_task_context (void);
437
438
439 /**
440  * Cancel the task with the specified identifier.
441  * The task must not yet have run.
442  *
443  * @param task id of the task to cancel
444  * @return the closure of the callback of the cancelled task
445  */
446 void *
447 GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task);
448
449
450 /**
451  * Continue the current execution with the given function.  This is
452  * similar to the other "add" functions except that there is no delay
453  * and the reason code can be specified.
454  *
455  * @param task main function of the task
456  * @param task_cls closure for @a task
457  * @param reason reason for task invocation
458  * @param priority priority to use for the task
459  */
460 void
461 GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback task,
462                                                void *task_cls,
463                                                enum GNUNET_SCHEDULER_Reason reason,
464                                                enum GNUNET_SCHEDULER_Priority priority);
465
466
467 /**
468  * Schedule a new task to be run with a specified priority.
469  *
470  * @param prio how important is the new task?
471  * @param task main function of the task
472  * @param task_cls closure of @a task
473  * @return unique task identifier for the job
474  *         only valid until @a task is started!
475  */
476 struct GNUNET_SCHEDULER_Task *
477 GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
478                                     GNUNET_SCHEDULER_TaskCallback task,
479                                     void *task_cls);
480
481
482 /**
483  * Schedule a new task to be run as soon as possible. Note that this
484  * does not guarantee that this will be the next task that is being
485  * run, as other tasks with higher priority (or that are already ready
486  * to run) might get to run first.  Just as with delays, clients must
487  * not rely on any particular order of execution between tasks
488  * scheduled concurrently.
489  *
490  * The task will be run with the DEFAULT priority.
491  *
492  * @param task main function of the task
493  * @param task_cls closure of @a task
494  * @return unique task identifier for the job
495  *         only valid until @a task is started!
496  */
497 struct GNUNET_SCHEDULER_Task *
498 GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task,
499                           void *task_cls);
500
501
502 /**
503  * Schedule a new task to be run on shutdown, that is when a CTRL-C
504  * signal is received, or when #GNUNET_SCHEDULER_shutdown() is being
505  * invoked.
506  *
507  * @param task main function of the task
508  * @param task_cls closure of @a task
509  * @return unique task identifier for the job
510  *         only valid until @a task is started!
511  */
512 struct GNUNET_SCHEDULER_Task *
513 GNUNET_SCHEDULER_add_shutdown (GNUNET_SCHEDULER_TaskCallback task,
514                                void *task_cls);
515
516
517 /**
518  * Schedule a new task to be run as soon as possible with the
519  * (transitive) ignore-shutdown flag either explicitly set or
520  * explicitly enabled.  This task (and all tasks created from it,
521  * other than by another call to this function) will either count or
522  * not count for the 'lifeness' of the process.  This API is only
523  * useful in a few special cases.
524  *
525  * @param lifeness #GNUNET_YES if the task counts for lifeness, #GNUNET_NO if not.
526  * @param task main function of the task
527  * @param task_cls closure of @a task
528  * @return unique task identifier for the job
529  *         only valid until @a task is started!
530  */
531 struct GNUNET_SCHEDULER_Task *
532 GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
533                                         GNUNET_SCHEDULER_TaskCallback task,
534                                         void *task_cls);
535
536
537 /**
538  * Schedule a new task to be run with a specified delay.  The task
539  * will be scheduled for execution once the delay has expired. It
540  * will be run with the DEFAULT priority.
541  *
542  * @param delay with which the operation should be run
543  * @param task main function of the task
544  * @param task_cls closure of @a task
545  * @return unique task identifier for the job
546  *         only valid until @a task is started!
547  */
548 struct GNUNET_SCHEDULER_Task *
549 GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
550                               GNUNET_SCHEDULER_TaskCallback task,
551                               void *task_cls);
552
553
554 /**
555  * Schedule a new task to be run at the specified time.  The task
556  * will be scheduled for execution once specified time has been
557  * reached. It will be run with the DEFAULT priority.
558  *
559  * @param at time at which this operation should run
560  * @param task main function of the task
561  * @param task_cls closure of @a task
562  * @return unique task identifier for the job
563  *         only valid until @a task is started!
564  */
565 struct GNUNET_SCHEDULER_Task *
566 GNUNET_SCHEDULER_add_at (struct GNUNET_TIME_Absolute at,
567                          GNUNET_SCHEDULER_TaskCallback task,
568                          void *task_cls);
569
570
571 /**
572  * Schedule a new task to be run with a specified delay.  The task
573  * will be scheduled for execution once the delay has expired.
574  *
575  * @param delay when should this operation time out?
576  * @param priority priority to use for the task
577  * @param task main function of the task
578  * @param task_cls closure of @a task
579  * @return unique task identifier for the job
580  *         only valid until @a task is started!
581  */
582 struct GNUNET_SCHEDULER_Task *
583 GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
584                                             enum GNUNET_SCHEDULER_Priority priority,
585                                             GNUNET_SCHEDULER_TaskCallback task,
586                                             void *task_cls);
587
588
589 /**
590  * Schedule a new task to be run at the specified time.  The task
591  * will be scheduled for execution at time @a at.
592  *
593  * @param at time when the operation should run
594  * @param priority priority to use for the task
595  * @param task main function of the task
596  * @param task_cls closure of @a task
597  * @return unique task identifier for the job
598  *         only valid until @a task is started!
599  */
600 struct GNUNET_SCHEDULER_Task *
601 GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at,
602                                        enum GNUNET_SCHEDULER_Priority priority,
603                                        GNUNET_SCHEDULER_TaskCallback task,
604                                        void *task_cls);
605
606
607 /**
608  * Schedule a new task to be run with a specified delay or when the
609  * specified file descriptor is ready for reading.  The delay can be
610  * used as a timeout on the socket being ready.  The task will be
611  * scheduled for execution once either the delay has expired or the
612  * socket operation is ready.  It will be run with the DEFAULT priority.
613  *
614  * @param delay when should this operation time out?
615  * @param rfd read file-descriptor
616  * @param task main function of the task
617  * @param task_cls closure of @a task
618  * @return unique task identifier for the job
619  *         only valid until @a task is started!
620  */
621 struct GNUNET_SCHEDULER_Task *
622 GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
623                                struct GNUNET_NETWORK_Handle *rfd,
624                                GNUNET_SCHEDULER_TaskCallback task,
625                                void *task_cls);
626
627
628 /**
629  * Schedule a new task to be run with a specified priority and to be
630  * run after the specified delay or when the specified file descriptor
631  * is ready for reading.  The delay can be used as a timeout on the
632  * socket being ready.  The task will be scheduled for execution once
633  * either the delay has expired or the socket operation is ready.  It
634  * will be run with the DEFAULT priority.
635  *
636  * @param delay when should this operation time out?
637  * @param priority priority to use for the task
638  * @param rfd read file-descriptor
639  * @param task main function of the task
640  * @param task_cls closure of @a task
641  * @return unique task identifier for the job
642  *         only valid until @a task is started!
643  */
644 struct GNUNET_SCHEDULER_Task *
645 GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay,
646                                              enum GNUNET_SCHEDULER_Priority priority,
647                                              struct GNUNET_NETWORK_Handle *rfd,
648                                              GNUNET_SCHEDULER_TaskCallback task,
649                                              void *task_cls);
650
651
652 /**
653  * Schedule a new task to be run with a specified delay or when the
654  * specified file descriptor is ready for writing.  The delay can be
655  * used as a timeout on the socket being ready.  The task will be
656  * scheduled for execution once either the delay has expired or the
657  * socket operation is ready.  It will be run with the DEFAULT priority.
658  *
659  * * @param delay when should this operation time out?
660  * @param wfd write file-descriptor
661  * @param task main function of the task
662  * @param task_cls closure of @a task
663  * @return unique task identifier for the job
664  *         only valid until @a task is started!
665  */
666 struct GNUNET_SCHEDULER_Task *
667 GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
668                                 struct GNUNET_NETWORK_Handle *wfd,
669                                 GNUNET_SCHEDULER_TaskCallback task,
670                                 void *task_cls);
671
672
673 /**
674  * Schedule a new task to be run with a specified delay or when the
675  * specified file descriptor is ready.  The delay can be
676  * used as a timeout on the socket being ready.  The task will be
677  * scheduled for execution once either the delay has expired or the
678  * socket operation is ready.
679  *
680  * @param delay when should this operation time out?
681  * @param priority priority of the task
682  * @param fd file-descriptor
683  * @param on_read whether to poll the file-descriptor for readability
684  * @param on_write whether to poll the file-descriptor for writability
685  * @param task main function of the task
686  * @param task_cls closure of @a task
687  * @return unique task identifier for the job
688  *         only valid until "task" is started!
689  */
690 struct GNUNET_SCHEDULER_Task *
691 GNUNET_SCHEDULER_add_net_with_priority  (struct GNUNET_TIME_Relative delay,
692                                          enum GNUNET_SCHEDULER_Priority priority,
693                                          struct GNUNET_NETWORK_Handle *fd,
694                                          int on_read,
695                                          int on_write,
696                                          GNUNET_SCHEDULER_TaskCallback task,
697                                          void *task_cls);
698
699 /**
700  * Schedule a new task to be run with a specified delay or when the
701  * specified file descriptor is ready for reading.  The delay can be
702  * used as a timeout on the socket being ready.  The task will be
703  * scheduled for execution once either the delay has expired or the
704  * socket operation is ready. It will be run with the DEFAULT priority.
705  *
706  * * @param delay when should this operation time out?
707  * @param rfd read file-descriptor
708  * @param task main function of the task
709  * @param task_cls closure of @a task
710  * @return unique task identifier for the job
711  *         only valid until "task" is started!
712  */
713 struct GNUNET_SCHEDULER_Task *
714 GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
715                                 const struct GNUNET_DISK_FileHandle *rfd,
716                                 GNUNET_SCHEDULER_TaskCallback task,
717                                 void *task_cls);
718
719
720 /**
721  * Schedule a new task to be run with a specified delay or when the
722  * specified file descriptor is ready for writing.  The delay can be
723  * used as a timeout on the socket being ready.  The task will be
724  * scheduled for execution once either the delay has expired or the
725  * socket operation is ready. It will be run with the DEFAULT priority.
726  *
727  * * @param delay when should this operation time out?
728  * @param wfd write file-descriptor
729  * @param task main function of the task
730  * @param task_cls closure of @a task
731  * @return unique task identifier for the job
732  *         only valid until @a task is started!
733  */
734 struct GNUNET_SCHEDULER_Task *
735 GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
736                                  const struct GNUNET_DISK_FileHandle *wfd,
737                                  GNUNET_SCHEDULER_TaskCallback task,
738                                  void *task_cls);
739
740
741 /**
742  * Schedule a new task to be run with a specified delay or when the
743  * specified file descriptor is ready.  The delay can be
744  * used as a timeout on the socket being ready.  The task will be
745  * scheduled for execution once either the delay has expired or the
746  * socket operation is ready.
747  *
748  * @param delay when should this operation time out?
749  * @param priority priority of the task
750  * @param fd file-descriptor
751  * @param on_read whether to poll the file-descriptor for readability
752  * @param on_write whether to poll the file-descriptor for writability
753  * @param task main function of the task
754  * @param task_cls closure of @a task
755  * @return unique task identifier for the job
756  *         only valid until @a task is started!
757  */
758 struct GNUNET_SCHEDULER_Task *
759 GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
760                                          enum GNUNET_SCHEDULER_Priority priority,
761                                          const struct GNUNET_DISK_FileHandle *fd,
762                                          int on_read, int on_write,
763                                          GNUNET_SCHEDULER_TaskCallback task,
764                                          void *task_cls);
765
766
767 /**
768  * Schedule a new task to be run with a specified delay or when any of
769  * the specified file descriptor sets is ready.  The delay can be used
770  * as a timeout on the socket(s) being ready.  The task will be
771  * scheduled for execution once either the delay has expired or any of
772  * the socket operations is ready.  This is the most general
773  * function of the "add" family.  Note that the "prerequisite_task"
774  * must be satisfied in addition to any of the other conditions.  In
775  * other words, the task will be started when
776  * <code>
777  * (prerequisite-run)
778  * && (delay-ready
779  *     || any-rs-ready
780  *     || any-ws-ready)
781  * </code>
782  *
783  * @param prio how important is this task?
784  * @param delay how long should we wait?
785  * @param rs set of file descriptors we want to read (can be NULL)
786  * @param ws set of file descriptors we want to write (can be NULL)
787  * @param task main function of the task
788  * @param task_cls closure of @a task
789  * @return unique task identifier for the job
790  *         only valid until "task" is started!
791  */
792 struct GNUNET_SCHEDULER_Task *
793 GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
794                              struct GNUNET_TIME_Relative delay,
795                              const struct GNUNET_NETWORK_FDSet *rs,
796                              const struct GNUNET_NETWORK_FDSet *ws,
797                              GNUNET_SCHEDULER_TaskCallback task,
798                              void *task_cls);
799
800 /**
801  * Sets the select function to use in the scheduler (scheduler_select).
802  *
803  * @param new_select new select function to use (NULL to reset to default)
804  * @param new_select_cls closure for @a new_select
805  */
806 void
807 GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select,
808                              void *new_select_cls);
809
810
811 #if 0                           /* keep Emacsens' auto-indent happy */
812 {
813 #endif
814 #ifdef __cplusplus
815 }
816 #endif
817
818 #endif
819
820 /** @} */ /* end of group scheduler */