2 This file is part of GNUnet
3 Copyright (C) 2009-2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @author Christian Grothoff
25 * API to schedule computations using continuation passing style
27 * @defgroup scheduler Scheduler library
28 * Event loop (scheduler)
30 * Schedule computations using continuation passing style.
35 #ifndef GNUNET_SCHEDULER_LIB_H
36 #define GNUNET_SCHEDULER_LIB_H
41 #if 0 /* keep Emacsens' auto-indent happy */
47 * Opaque reference to a task.
49 struct GNUNET_SCHEDULER_Task;
52 * Reasons why the schedule may have triggered
55 enum GNUNET_SCHEDULER_Reason
58 * This task is not ready.
60 GNUNET_SCHEDULER_REASON_NONE = 0,
63 * This is the very first task run during startup.
65 GNUNET_SCHEDULER_REASON_STARTUP = 1,
68 * We are shutting down and are running all shutdown-related tasks.
70 GNUNET_SCHEDULER_REASON_SHUTDOWN = 2,
73 * The specified timeout has expired.
74 * (also set if the delay given was 0).
76 GNUNET_SCHEDULER_REASON_TIMEOUT = 4,
79 * The reading socket is ready.
81 GNUNET_SCHEDULER_REASON_READ_READY = 8,
84 * The writing socket is ready.
86 GNUNET_SCHEDULER_REASON_WRITE_READY = 16,
89 * The prerequisite task is done.
91 GNUNET_SCHEDULER_REASON_PREREQ_DONE = 32
95 #include "gnunet_time_lib.h"
96 #include "gnunet_network_lib.h"
100 * Possible events on FDs, used as a bitmask.
101 * Modelled after GPollFD.
103 enum GNUNET_SCHEDULER_EventType
107 * No event (useful for timeout).
109 GNUNET_SCHEDULER_ET_NONE = 0,
112 * Data available for reading.
114 GNUNET_SCHEDULER_ET_IN = 1,
117 * Buffer available for writing.
119 GNUNET_SCHEDULER_ET_OUT = 2,
124 GNUNET_SCHEDULER_ET_HUP = 4,
129 GNUNET_SCHEDULER_ET_ERR = 8,
134 GNUNET_SCHEDULER_ET_PRI = 16,
139 GNUNET_SCHEDULER_ET_NVAL = 32
145 * Information about an event relating to a file descriptor/socket.
147 struct GNUNET_SCHEDULER_FdInfo
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.
155 const struct GNUNET_NETWORK_Handle *fd;
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.
162 const struct GNUNET_DISK_FileHandle *fh;
165 * Type of the event that was generated related to @e sock.
167 enum GNUNET_SCHEDULER_EventType et;
170 * Underlying OS handle the event was about.
178 * Context information passed to each scheduler task.
180 struct GNUNET_SCHEDULER_TaskContext
183 * Reason why the task is run now
185 enum GNUNET_SCHEDULER_Reason reason;
188 * Length of the following array.
190 unsigned int fds_len;
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.
198 const struct GNUNET_SCHEDULER_FdInfo *fds;
201 * Set of file descriptors ready for reading; note that additional
202 * bits may be set that were not in the original request.
205 const struct GNUNET_NETWORK_FDSet *read_ready;
208 * Set of file descriptors ready for writing; note that additional
209 * bits may be set that were not in the original request.
212 const struct GNUNET_NETWORK_FDSet *write_ready;
218 * Function used by event-loop implementations to signal the scheduler
219 * that a particular @a task is ready due to an event specified in the
220 * et field of @a fdi.
222 * This function will then queue the task to notify the application
223 * that the task is ready (with the respective priority).
225 * @param task the task that is ready
226 * @param fdi information about the related FD
229 GNUNET_SCHEDULER_task_ready (struct GNUNET_SCHEDULER_Task *task,
230 struct GNUNET_SCHEDULER_FdInfo *fdi);
234 * Handle to the scheduler's state to be used by the driver.
236 struct GNUNET_SCHEDULER_Handle;
240 * Function called by external event loop implementations to tell the
241 * scheduler to run some of the tasks that are ready. Must be called
242 * only after #GNUNET_SCHEDULER_driver_init has been called and before
243 * #GNUNET_SCHEDULER_driver_done is called.
244 * This function may return even though there are tasks left to run
245 * just to give other tasks a chance as well. If we return #GNUNET_YES,
246 * the event loop implementation should call this function again as
247 * soon as possible, while if we return #GNUNET_NO it must block until
248 * either the operating system has more work (the scheduler has no more
249 * work to do right now) or the timeout set by the scheduler (using the
250 * set_wakeup callback) is reached.
252 * @param sh scheduler handle that was returned by
253 * #GNUNET_SCHEDULER_driver_init
254 * @return #GNUNET_YES if there are more tasks that are ready,
255 * and thus we would like to run more (yield to avoid
256 * blocking other activities for too long) #GNUNET_NO
257 * if we are done running tasks (yield to block)
260 GNUNET_SCHEDULER_do_work (struct GNUNET_SCHEDULER_Handle *sh);
264 * API an external event loop has to implement for
265 * #GNUNET_SCHEDULER_driver_init.
267 struct GNUNET_SCHEDULER_Driver
271 * Closure to pass to the functions in this struct.
276 * Add a @a task to be run if the conditions specified in the
277 * et field of the given @a fdi are satisfied. The et field will
278 * be cleared after this call and the driver is expected to set
279 * the type of the actual event before passing @a fdi to
280 * #GNUNET_SCHEDULER_task_ready.
283 * @param task task to add
284 * @param fdi conditions to watch for
285 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
286 * (i.e. @a fdi too high or invalid)
290 struct GNUNET_SCHEDULER_Task *task,
291 struct GNUNET_SCHEDULER_FdInfo *fdi);
294 * Delete a @a task from the set of tasks to be run. A task may
295 * comprise multiple FdInfo entries previously added with the add
296 * function. The driver is expected to delete them all.
299 * @param task task to delete
300 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
301 * (i.e. @a task does not match prior @e add call)
305 struct GNUNET_SCHEDULER_Task *task);
308 * Set time at which we definitively want to get a wakeup call.
311 * @param dt time when we want to wake up next
314 (*set_wakeup)(void *cls,
315 struct GNUNET_TIME_Absolute dt);
321 * Signature of the main function of a task.
326 (*GNUNET_SCHEDULER_TaskCallback) (void *cls);
330 * Function called by external event loop implementations to initialize
331 * the scheduler. An external implementation has to provide @a driver
332 * which contains callbacks for the scheduler (see definition of struct
333 * #GNUNET_SCHEDULER_Driver). The callbacks are used to instruct the
334 * external implementation to watch for events. If it detects any of
335 * those events it is expected to call #GNUNET_SCHEDULER_do_work to let
336 * the scheduler handle it. If an event is related to a specific task
337 * (e.g. the scheduler gave instructions to watch a file descriptor),
338 * the external implementation is expected to mark that task ready
339 * before by calling #GNUNET_SCHEDULER_task_ready.
341 * This function has to be called before any tasks are scheduled and
342 * before GNUNET_SCHEDULER_do_work is called for the first time. It
343 * allocates resources that have to be freed again by calling
344 * #GNUNET_SCHEDULER_driver_done.
346 * This function installs the same signal handlers as
347 * #GNUNET_SCHEDULER_run. This means SIGTERM (and other similar signals)
348 * will induce a call to #GNUNET_SCHEDULER_shutdown during the next
349 * call to #GNUNET_SCHEDULER_do_work. As a result, SIGTERM causes all
350 * active tasks to be scheduled with reason
351 * #GNUNET_SCHEDULER_REASON_SHUTDOWN. (However, tasks added afterwards
352 * will execute normally!). Note that any particular signal will only
353 * shut down one scheduler; applications should always only create a
356 * @param driver to use for the event loop
357 * @return handle to be passed to #GNUNET_SCHEDULER_do_work and
358 * #GNUNET_SCHEDULER_driver_done
360 struct GNUNET_SCHEDULER_Handle *
361 GNUNET_SCHEDULER_driver_init (const struct GNUNET_SCHEDULER_Driver *driver);
365 * Counter-part of #GNUNET_SCHEDULER_driver_init. Has to be called
366 * by external event loop implementations after the scheduler has
367 * shut down. This is the case if both of the following conditions
370 * - all tasks the scheduler has added through the driver's add
371 * callback have been removed again through the driver's del
373 * - the timeout the scheduler has set through the driver's
374 * add_wakeup callback is FOREVER
376 * @param sh the handle returned by #GNUNET_SCHEDULER_driver_init
379 GNUNET_SCHEDULER_driver_done (struct GNUNET_SCHEDULER_Handle *sh);
383 * Obtain the driver for using select() as the event loop.
385 * @return NULL on error
387 struct GNUNET_SCHEDULER_Driver *
388 GNUNET_SCHEDULER_driver_select (void);
392 * Signature of the select function used by the scheduler.
393 * #GNUNET_NETWORK_socket_select matches it.
396 * @param rfds set of sockets to be checked for readability
397 * @param wfds set of sockets to be checked for writability
398 * @param efds set of sockets to be checked for exceptions
399 * @param timeout relative value when to return
400 * @return number of selected sockets, #GNUNET_SYSERR on error
403 (*GNUNET_SCHEDULER_select) (void *cls,
404 struct GNUNET_NETWORK_FDSet *rfds,
405 struct GNUNET_NETWORK_FDSet *wfds,
406 struct GNUNET_NETWORK_FDSet *efds,
407 struct GNUNET_TIME_Relative timeout);
411 * Initialize and run scheduler. This function will return when all
412 * tasks have completed. On systems with signals, receiving a SIGTERM
413 * (and other similar signals) will cause #GNUNET_SCHEDULER_shutdown
414 * to be run after the active task is complete. As a result, SIGTERM
415 * causes all shutdown tasks to be scheduled with reason
416 * #GNUNET_SCHEDULER_REASON_SHUTDOWN. (However, tasks added
417 * afterwards will execute normally!). Note that any particular
418 * signal will only shut down one scheduler; applications should
419 * always only create a single scheduler.
421 * @param task task to run first (and immediately)
422 * @param task_cls closure of @a task
425 GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
429 * Initialize and run scheduler. This function will return when all
430 * tasks have completed. When @ install_signals is GNUNET_YES, then
431 * this function behaves in the same was as GNUNET_SCHEDULER_run does.
432 * If @ install_signals is GNUNET_NO then no signal handlers are
435 * @param install_signals whether to install signals (GNUNET_YES/NO)
436 * @param task task to run first (and immediately)
437 * @param task_cls closure of @a task
440 GNUNET_SCHEDULER_run_with_optional_signals (int install_signals,
441 GNUNET_SCHEDULER_TaskCallback task,
446 * Request the shutdown of a scheduler. Marks all tasks
447 * awaiting shutdown as ready. Note that tasks
448 * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call
449 * will be delayed until the next shutdown signal.
452 GNUNET_SCHEDULER_shutdown (void);
456 * Get information about the current load of this scheduler. Use this
457 * function to determine if an elective task should be added or simply
458 * dropped (if the decision should be made based on the number of
459 * tasks ready to run).
461 * @param p priority-level to query, use KEEP to query the level
462 * of the current task, use COUNT to get the sum over
463 * all priority levels
464 * @return number of tasks pending right now
467 GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p);
471 * Obtain the reasoning why the current task was
474 * @return task context with information why the current task is run
476 const struct GNUNET_SCHEDULER_TaskContext *
477 GNUNET_SCHEDULER_get_task_context (void);
481 * Cancel the task with the specified identifier.
482 * The task must not yet have run. Only allowed to be called as long as the
483 * scheduler is running, that is one of the following conditions is met:
485 * - #GNUNET_SCHEDULER_run has been called and has not returned yet
486 * - #GNUNET_SCHEDULER_driver_init has been run and
487 * #GNUNET_SCHEDULER_driver_done has not been called yet
489 * @param task id of the task to cancel
490 * @return original closure of the task
493 GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task);
497 * Continue the current execution with the given function. This is
498 * similar to the other "add" functions except that there is no delay
499 * and the reason code can be specified.
501 * @param task main function of the task
502 * @param task_cls closure for @a task
503 * @param reason reason for task invocation
504 * @param priority priority to use for the task
507 GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback task,
509 enum GNUNET_SCHEDULER_Reason reason,
510 enum GNUNET_SCHEDULER_Priority priority);
514 * Schedule a new task to be run with a specified priority.
516 * @param prio how important is the new task?
517 * @param task main function of the task
518 * @param task_cls closure of @a task
519 * @return unique task identifier for the job
520 * only valid until @a task is started!
522 struct GNUNET_SCHEDULER_Task *
523 GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
524 GNUNET_SCHEDULER_TaskCallback task,
529 * Schedule a new task to be run as soon as possible. Note that this
530 * does not guarantee that this will be the next task that is being
531 * run, as other tasks with higher priority (or that are already ready
532 * to run) might get to run first. Just as with delays, clients must
533 * not rely on any particular order of execution between tasks
534 * scheduled concurrently.
536 * The task will be run with the DEFAULT priority.
538 * @param task main function of the task
539 * @param task_cls closure of @a task
540 * @return unique task identifier for the job
541 * only valid until @a task is started!
543 struct GNUNET_SCHEDULER_Task *
544 GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task,
549 * Schedule a new task to be run on shutdown, that is when a CTRL-C
550 * signal is received, or when #GNUNET_SCHEDULER_shutdown() is being
553 * @param task main function of the task
554 * @param task_cls closure of @a task
555 * @return unique task identifier for the job
556 * only valid until @a task is started!
558 struct GNUNET_SCHEDULER_Task *
559 GNUNET_SCHEDULER_add_shutdown (GNUNET_SCHEDULER_TaskCallback task,
564 * Schedule a new task to be run as soon as possible with the
565 * (transitive) ignore-shutdown flag either explicitly set or
566 * explicitly enabled. This task (and all tasks created from it,
567 * other than by another call to this function) will either count or
568 * not count for the 'lifeness' of the process. This API is only
569 * useful in a few special cases.
571 * @param lifeness #GNUNET_YES if the task counts for lifeness, #GNUNET_NO if not.
572 * @param task main function of the task
573 * @param task_cls closure of @a task
574 * @return unique task identifier for the job
575 * only valid until @a task is started!
577 struct GNUNET_SCHEDULER_Task *
578 GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
579 GNUNET_SCHEDULER_TaskCallback task,
584 * Schedule a new task to be run with a specified delay. The task
585 * will be scheduled for execution once the delay has expired. It
586 * will be run with the DEFAULT priority.
588 * @param delay with which the operation should be run
589 * @param task main function of the task
590 * @param task_cls closure of @a task
591 * @return unique task identifier for the job
592 * only valid until @a task is started!
594 struct GNUNET_SCHEDULER_Task *
595 GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
596 GNUNET_SCHEDULER_TaskCallback task,
601 * Schedule a new task to be run at the specified time. The task
602 * will be scheduled for execution once specified time has been
603 * reached. It will be run with the DEFAULT priority.
605 * @param at time at which this operation should run
606 * @param task main function of the task
607 * @param task_cls closure of @a task
608 * @return unique task identifier for the job
609 * only valid until @a task is started!
611 struct GNUNET_SCHEDULER_Task *
612 GNUNET_SCHEDULER_add_at (struct GNUNET_TIME_Absolute at,
613 GNUNET_SCHEDULER_TaskCallback task,
618 * Schedule a new task to be run with a specified delay. The task
619 * will be scheduled for execution once the delay has expired.
621 * @param delay when should this operation time out?
622 * @param priority priority to use for the task
623 * @param task main function of the task
624 * @param task_cls closure of @a task
625 * @return unique task identifier for the job
626 * only valid until @a task is started!
628 struct GNUNET_SCHEDULER_Task *
629 GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
630 enum GNUNET_SCHEDULER_Priority priority,
631 GNUNET_SCHEDULER_TaskCallback task,
636 * Schedule a new task to be run at the specified time. The task
637 * will be scheduled for execution at time @a at.
639 * @param at time when the operation should run
640 * @param priority priority to use for the task
641 * @param task main function of the task
642 * @param task_cls closure of @a task
643 * @return unique task identifier for the job
644 * only valid until @a task is started!
646 struct GNUNET_SCHEDULER_Task *
647 GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at,
648 enum GNUNET_SCHEDULER_Priority priority,
649 GNUNET_SCHEDULER_TaskCallback task,
654 * Schedule a new task to be run with a specified delay or when the
655 * specified file descriptor is ready for reading. The delay can be
656 * used as a timeout on the socket being ready. The task will be
657 * scheduled for execution once either the delay has expired or the
658 * socket operation is ready. It will be run with the DEFAULT priority.
659 * Only allowed to be called as long as the scheduler is running, that
660 * is one of the following conditions is met:
662 * - #GNUNET_SCHEDULER_run has been called and has not returned yet
663 * - #GNUNET_SCHEDULER_driver_init has been run and
664 * #GNUNET_SCHEDULER_driver_done has not been called yet
666 * @param delay when should this operation time out?
667 * @param rfd read file-descriptor
668 * @param task main function of the task
669 * @param task_cls closure of @a task
670 * @return unique task identifier for the job
671 * only valid until @a task is started!
673 struct GNUNET_SCHEDULER_Task *
674 GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
675 struct GNUNET_NETWORK_Handle *rfd,
676 GNUNET_SCHEDULER_TaskCallback task,
681 * Schedule a new task to be run with a specified priority and to be
682 * run after the specified delay or when the specified file descriptor
683 * is ready for reading. The delay can be used as a timeout on the
684 * socket being ready. The task will be scheduled for execution once
685 * either the delay has expired or the socket operation is ready. It
686 * will be run with the DEFAULT priority.
687 * Only allowed to be called as long as the scheduler is running, that
688 * is one of the following conditions is met:
690 * - #GNUNET_SCHEDULER_run has been called and has not returned yet
691 * - #GNUNET_SCHEDULER_driver_init has been run and
692 * #GNUNET_SCHEDULER_driver_done has not been called yet
694 * @param delay when should this operation time out?
695 * @param priority priority to use for the task
696 * @param rfd read file-descriptor
697 * @param task main function of the task
698 * @param task_cls closure of @a task
699 * @return unique task identifier for the job
700 * only valid until @a task is started!
702 struct GNUNET_SCHEDULER_Task *
703 GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay,
704 enum GNUNET_SCHEDULER_Priority priority,
705 struct GNUNET_NETWORK_Handle *rfd,
706 GNUNET_SCHEDULER_TaskCallback task,
711 * Schedule a new task to be run with a specified delay or when the
712 * specified file descriptor is ready for writing. The delay can be
713 * used as a timeout on the socket being ready. The task will be
714 * scheduled for execution once either the delay has expired or the
715 * socket operation is ready. It will be run with the priority of
717 * Only allowed to be called as long as the scheduler is running, that
718 * is one of the following conditions is met:
720 * - #GNUNET_SCHEDULER_run has been called and has not returned yet
721 * - #GNUNET_SCHEDULER_driver_init has been run and
722 * #GNUNET_SCHEDULER_driver_done has not been called yet
724 * @param delay when should this operation time out?
725 * @param wfd write file-descriptor
726 * @param task main function of the task
727 * @param task_cls closure of @a task
728 * @return unique task identifier for the job
729 * only valid until @a task is started!
731 struct GNUNET_SCHEDULER_Task *
732 GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
733 struct GNUNET_NETWORK_Handle *wfd,
734 GNUNET_SCHEDULER_TaskCallback task,
739 * Schedule a new task to be run with a specified delay or when the
740 * specified file descriptor is ready. The delay can be
741 * used as a timeout on the socket being ready. The task will be
742 * scheduled for execution once either the delay has expired or the
743 * socket operation is ready.
744 * Only allowed to be called as long as the scheduler is running, that
745 * is one of the following conditions is met:
747 * - #GNUNET_SCHEDULER_run has been called and has not returned yet
748 * - #GNUNET_SCHEDULER_driver_init has been run and
749 * #GNUNET_SCHEDULER_driver_done has not been called yet
751 * @param delay when should this operation time out?
752 * @param priority priority of the task
753 * @param fd file-descriptor
754 * @param on_read whether to poll the file-descriptor for readability
755 * @param on_write whether to poll the file-descriptor for writability
756 * @param task main function of the task
757 * @param task_cls closure of task
758 * @return unique task identifier for the job
759 * only valid until "task" is started!
761 struct GNUNET_SCHEDULER_Task *
762 GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay,
763 enum GNUNET_SCHEDULER_Priority priority,
764 struct GNUNET_NETWORK_Handle *fd,
767 GNUNET_SCHEDULER_TaskCallback task,
772 * Schedule a new task to be run with a specified delay or when the
773 * specified file descriptor is ready for reading. The delay can be
774 * used as a timeout on the socket being ready. The task will be
775 * scheduled for execution once either the delay has expired or the
776 * socket operation is ready. It will be run with the DEFAULT priority.
777 * Only allowed to be called as long as the scheduler is running, that
778 * is one of the following conditions is met:
780 * - #GNUNET_SCHEDULER_run has been called and has not returned yet
781 * - #GNUNET_SCHEDULER_driver_init has been run and
782 * #GNUNET_SCHEDULER_driver_done has not been called yet
784 * @param delay when should this operation time out?
785 * @param rfd read file-descriptor
786 * @param task main function of the task
787 * @param task_cls closure of @a task
788 * @return unique task identifier for the job
789 * only valid until @a task is started!
791 struct GNUNET_SCHEDULER_Task *
792 GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
793 const struct GNUNET_DISK_FileHandle *rfd,
794 GNUNET_SCHEDULER_TaskCallback task,
799 * Schedule a new task to be run with a specified delay or when the
800 * specified file descriptor is ready for writing. The delay can be
801 * used as a timeout on the socket being ready. The task will be
802 * scheduled for execution once either the delay has expired or the
803 * socket operation is ready. It will be run with the DEFAULT priority.
804 * Only allowed to be called as long as the scheduler is running, that
805 * is one of the following conditions is met:
807 * - #GNUNET_SCHEDULER_run has been called and has not returned yet
808 * - #GNUNET_SCHEDULER_driver_init has been run and
809 * #GNUNET_SCHEDULER_driver_done has not been called yet
811 * @param delay when should this operation time out?
812 * @param wfd write file-descriptor
813 * @param task main function of the task
814 * @param task_cls closure of @a task
815 * @return unique task identifier for the job
816 * only valid until @a task is started!
818 struct GNUNET_SCHEDULER_Task *
819 GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
820 const struct GNUNET_DISK_FileHandle *wfd,
821 GNUNET_SCHEDULER_TaskCallback task,
826 * Schedule a new task to be run with a specified delay or when the
827 * specified file descriptor is ready. The delay can be
828 * used as a timeout on the socket being ready. The task will be
829 * scheduled for execution once either the delay has expired or the
830 * socket operation is ready.
831 * Only allowed to be called as long as the scheduler is running, that
832 * is one of the following conditions is met:
834 * - #GNUNET_SCHEDULER_run has been called and has not returned yet
835 * - #GNUNET_SCHEDULER_driver_init has been run and
836 * #GNUNET_SCHEDULER_driver_done has not been called yet
838 * @param delay when should this operation time out?
839 * @param priority priority of the task
840 * @param fd file-descriptor
841 * @param on_read whether to poll the file-descriptor for readability
842 * @param on_write whether to poll the file-descriptor for writability
843 * @param task main function of the task
844 * @param task_cls closure of @a task
845 * @return unique task identifier for the job
846 * only valid until @a task is started!
848 struct GNUNET_SCHEDULER_Task *
849 GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
850 enum GNUNET_SCHEDULER_Priority priority,
851 const struct GNUNET_DISK_FileHandle *fd,
852 int on_read, int on_write,
853 GNUNET_SCHEDULER_TaskCallback task,
858 * Schedule a new task to be run with a specified delay or when any of
859 * the specified file descriptor sets is ready. The delay can be used
860 * as a timeout on the socket(s) being ready. The task will be
861 * scheduled for execution once either the delay has expired or any of
862 * the socket operations is ready. This is the most general
863 * function of the "add" family. Note that the "prerequisite_task"
864 * must be satisfied in addition to any of the other conditions. In
865 * other words, the task will be started when
872 * Only allowed to be called as long as the scheduler is running, that
873 * is one of the following conditions is met:
875 * - #GNUNET_SCHEDULER_run has been called and has not returned yet
876 * - #GNUNET_SCHEDULER_driver_init has been run and
877 * #GNUNET_SCHEDULER_driver_done has not been called yet
879 * @param prio how important is this task?
880 * @param delay how long should we wait?
881 * @param rs set of file descriptors we want to read (can be NULL)
882 * @param ws set of file descriptors we want to write (can be NULL)
883 * @param task main function of the task
884 * @param task_cls closure of @a task
885 * @return unique task identifier for the job
886 * only valid until @a task is started!
888 struct GNUNET_SCHEDULER_Task *
889 GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
890 struct GNUNET_TIME_Relative delay,
891 const struct GNUNET_NETWORK_FDSet *rs,
892 const struct GNUNET_NETWORK_FDSet *ws,
893 GNUNET_SCHEDULER_TaskCallback task,
897 * Sets the select function to use in the scheduler (scheduler_select).
899 * @param new_select new select function to use (NULL to reset to default)
900 * @param new_select_cls closure for @a new_select
903 GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select,
904 void *new_select_cls);
907 #if 0 /* keep Emacsens' auto-indent happy */
916 /** @} */ /* end of group scheduler */