LRN: Added-the-ability-to-substitute-scheduler-select.
authorChristian Grothoff <christian@grothoff.org>
Sun, 14 Aug 2011 11:08:43 +0000 (11:08 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 14 Aug 2011 11:08:43 +0000 (11:08 +0000)
src/include/gnunet_disk_lib.h
src/include/gnunet_network_lib.h
src/include/gnunet_scheduler_lib.h
src/include/gnunet_transport_plugin.h
src/util/disk.h
src/util/network.c
src/util/scheduler.c

index 5403d256bf4e6185c06dc9ef6daac0c9f887fe67..fdccebab09500a3f1d670956fbbd81abbcf0761c 100644 (file)
@@ -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
index 1945d210f8d5ba849707063892b0e4a1999d85cd..aed4cabbf18b459f450494d66feb6ee81e94c015 100644 (file)
@@ -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"
index ce3261f0a4cbe4d48f7941425880d20a51bf8006..6b927bba8730f1665abddcd06d7f8a4b541f4100 100644 (file)
@@ -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
index b4784318843f7a4fa1b80a2dedf8d702de42845f..37eef94274c1ff07f27d549e217fc271d7360757 100644 (file)
@@ -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")
index f287834b809137cdf64fc3ddd86d621cc09f3dd5..fee43abb8761aa50c1d71645f7d45eb4f42427fd 100644 (file)
  * @file util/disk.h
  * @brief Internal DISK related helper functions
  * @author Nils Durner
- */ 
-  \r
+ */
 #ifndef GNUNET_DISK_H_
 #define GNUNET_DISK_H_
   
 #include "gnunet_disk_lib.h"
-  \r
-/**
- * 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                          /* \r */
 };
-\r\r\r
+
 /**
  * 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, \rvoid *dst, \rsize_t dst_len);
-\r
+                                       *fh, 
+                                      void *dst, 
+                                      size_t dst_len);
+
 #endif  /* GNUNET_DISK_H_ */
index 98eeb7b0ce405ec6bfef6d6b8efc11e07f90e05a..6ce3df1c2f6828a65b2bf03e4e783e9a9e715951 100644 (file)
@@ -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 */
index dd0ce6054915d6ac82fdc5dd81b28be6fbf8c246..692c4f0b7a3656df5b0a3d6f89d151b1dde4a0ad 100644 (file)
@@ -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)