From 53da062e08f1d1d4392b3a40396bb45cc093e2ac Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 14 Aug 2011 11:08:43 +0000 Subject: [PATCH] LRN: Added-the-ability-to-substitute-scheduler-select. --- src/include/gnunet_disk_lib.h | 42 +++++++++++++++++++++++++ src/include/gnunet_network_lib.h | 23 +++++++++++++- src/include/gnunet_scheduler_lib.h | 31 ++++++++++++++++++ src/include/gnunet_transport_plugin.h | 3 +- src/util/disk.h | 45 ++++----------------------- src/util/network.c | 23 -------------- src/util/scheduler.c | 35 ++++++++++++++++++++- 7 files changed, 136 insertions(+), 66 deletions(-) diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h index 5403d256b..fdccebab0 100644 --- a/src/include/gnunet_disk_lib.h +++ b/src/include/gnunet_disk_lib.h @@ -36,6 +36,48 @@ struct GNUNET_DISK_FileHandle; struct GNUNET_DISK_PipeHandle; +enum GNUNET_FILE_Type { + GNUNET_DISK_FILE, GNUNET_PIPE +}; + +/** + * Handle used to access files (and pipes). + */ +struct GNUNET_DISK_FileHandle +{ + +#if WINDOWS + /** + * File handle under W32. + */ + HANDLE h; + + /** + * Type + */ + enum GNUNET_FILE_Type type; + + /** + * Structure for overlapped reading (for pipes) + */ + OVERLAPPED *oOverlapRead; + + /** + * Structure for overlapped writing (for pipes) + */ + OVERLAPPED *oOverlapWrite; +#else + + /** + * File handle on other OSes. + */ + int fd; + +#endif /* + */ +}; + + /* we need size_t, and since it can be both unsigned int or unsigned long long, this IS platform dependent; but "stdlib.h" should be portable 'enough' to be diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h index 1945d210f..aed4cabbf 100644 --- a/src/include/gnunet_network_lib.h +++ b/src/include/gnunet_network_lib.h @@ -45,7 +45,28 @@ struct GNUNET_NETWORK_Handle; /** * @brief collection of IO descriptors */ -struct GNUNET_NETWORK_FDSet; +struct GNUNET_NETWORK_FDSet +{ + + /** + * Maximum number of any socket socket descriptor in the set (plus one) + */ + int nsds; + + /** + * Bitset with the descriptors. + */ + fd_set sds; + +#ifdef WINDOWS + /** + * Linked list of handles + */ + struct GNUNET_CONTAINER_SList *handles; +#endif + +}; + #include "gnunet_disk_lib.h" diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h index ce3261f0a..6b927bba8 100644 --- a/src/include/gnunet_scheduler_lib.h +++ b/src/include/gnunet_scheduler_lib.h @@ -194,6 +194,20 @@ typedef void (*GNUNET_SCHEDULER_Task) (void *cls, GNUNET_SCHEDULER_TaskContext * tc); +/** + * Signature of the select function used by the scheduler. + * GNUNET_NETWORK_socket_select matches it. + * + * @param rfds set of sockets to be checked for readability + * @param wfds set of sockets to be checked for writability + * @param efds set of sockets to be checked for exceptions + * @param timeout relative value when to return + * @return number of selected sockets, GNUNET_SYSERR on error + */ +typedef int (*GNUNET_SCHEDULER_select) (struct GNUNET_NETWORK_FDSet *rfds, + struct GNUNET_NETWORK_FDSet *wfds, + struct GNUNET_NETWORK_FDSet *efds, + struct GNUNET_TIME_Relative timeout); /** * Initialize and run scheduler. This function will return when all * tasks have completed. On systems with signals, receiving a SIGTERM @@ -494,6 +508,23 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_Task task, void *task_cls); +/** + * Sets the select function to use in the scheduler (scheduler_select). + * + * @param new_select new select function to use + * @return previously used select function + */ +GNUNET_SCHEDULER_select +GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select); + +/** + * Gets the select function currently used in the scheduler. + * + * @return currently used select function + */ +GNUNET_SCHEDULER_select +GNUNET_SCHEDULER_get_select (); + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h index b47843188..37eef9427 100644 --- a/src/include/gnunet_transport_plugin.h +++ b/src/include/gnunet_transport_plugin.h @@ -92,8 +92,7 @@ typedef void (*GNUNET_TRANSPORT_SessionEnd) (void *cls, * @param cls closure * @param peer (claimed) identity of the other peer * @param message the message, NULL if we only care about - * learning about the delay until we should receive again -- FIXME! - * @param distance in overlay hops; use 1 unless DV (or 0 if message == NULL) + * learning about the delay until we should receive again * @param session identifier used for this session (NULL for plugins * that do not offer bi-directional communication to the sender * using the same "connection") diff --git a/src/util/disk.h b/src/util/disk.h index f287834b8..fee43abb8 100644 --- a/src/util/disk.h +++ b/src/util/disk.h @@ -22,49 +22,14 @@ * @file util/disk.h * @brief Internal DISK related helper functions * @author Nils Durner - */ - + */ #ifndef GNUNET_DISK_H_ #define GNUNET_DISK_H_ #include "gnunet_disk_lib.h" - -/** - * Handle used to access files (and pipes). - */ -struct GNUNET_DISK_FileHandle -{ - -#ifdef MINGW - /** - * File handle under W32. - */ - HANDLE h; - - /** - * Type - */ - enum {GNUNET_DISK_FILE, GNUNET_PIPE} type; - /** - * Structure for overlapped reading (for pipes) - */ - OVERLAPPED *oOverlapRead; - - /** - * Structure for overlapped writing (for pipes) - */ - OVERLAPPED *oOverlapWrite; -#else - - /** - * File handle on other OSes. - */ - int fd; - -#endif /* */ }; - + /** * Retrieve OS file handle * @@ -75,6 +40,8 @@ struct GNUNET_DISK_FileHandle * @return GNUNET_OK on success, GNUNET_SYSERR otherwise */ int GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle - *fh, void *dst, size_t dst_len); - + *fh, + void *dst, + size_t dst_len); + #endif /* GNUNET_DISK_H_ */ diff --git a/src/util/network.c b/src/util/network.c index 98eeb7b0c..6ce3df1c2 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -65,28 +65,6 @@ struct GNUNET_NETWORK_Handle }; -struct GNUNET_NETWORK_FDSet -{ - - /** - * Maximum number of any socket socket descriptor in the set (plus one) - */ - int nsds; - - /** - * Bitset with the descriptors. - */ - fd_set sds; - -#ifdef WINDOWS - /** - * Linked list of handles - */ - struct GNUNET_CONTAINER_SList *handles; -#endif - -}; - #ifndef FD_COPY #define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set))) #endif @@ -1620,5 +1598,4 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, return 0; } - /* end of network.c */ diff --git a/src/util/scheduler.c b/src/util/scheduler.c index dd0ce6054..692c4f0b7 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c @@ -245,6 +245,39 @@ static enum GNUNET_SCHEDULER_Priority max_priority_added; */ static int current_lifeness; +/** + * Function to use as a select() in the scheduler. + * Defaults to GNUNET_NETWORK_socket_select () + */ +GNUNET_SCHEDULER_select scheduler_select = GNUNET_NETWORK_socket_select; + +/** + * Sets the select function to use in the scheduler (scheduler_select). + * + * @param new_select new select function to use + * @return previously used select function + */ +GNUNET_SCHEDULER_select +GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select) +{ + GNUNET_SCHEDULER_select old_select = scheduler_select; + scheduler_select = new_select; + if (scheduler_select == NULL) + scheduler_select = GNUNET_NETWORK_socket_select; + return old_select; +} + +/** + * Gets the select function currently used in the scheduler. + * + * @return currently used select function + */ +GNUNET_SCHEDULER_select +GNUNET_SCHEDULER_get_select () +{ + return scheduler_select; +} + /** * Check that the given priority is legal (and return it). * @@ -806,7 +839,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) /* no blocking, more work already ready! */ timeout = GNUNET_TIME_UNIT_ZERO; } - ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); + ret = scheduler_select (rs, ws, NULL, timeout); if (ret == GNUNET_SYSERR) { if (errno == EINTR) -- 2.25.1