diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-14 11:08:43 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-14 11:08:43 +0000 |
commit | 53da062e08f1d1d4392b3a40396bb45cc093e2ac (patch) | |
tree | 40b132f38c1d6b46476bfd9c1917070956ce4861 /src | |
parent | 1debac4608e78f4a7800252ba9a91b4f5a376b42 (diff) | |
download | gnunet-53da062e08f1d1d4392b3a40396bb45cc093e2ac.tar.gz gnunet-53da062e08f1d1d4392b3a40396bb45cc093e2ac.zip |
LRN: Added-the-ability-to-substitute-scheduler-select.
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_disk_lib.h | 42 | ||||
-rw-r--r-- | src/include/gnunet_network_lib.h | 23 | ||||
-rw-r--r-- | src/include/gnunet_scheduler_lib.h | 31 | ||||
-rw-r--r-- | src/include/gnunet_transport_plugin.h | 3 | ||||
-rw-r--r-- | src/util/disk.h | 45 | ||||
-rw-r--r-- | src/util/network.c | 23 | ||||
-rw-r--r-- | 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; | |||
36 | struct GNUNET_DISK_PipeHandle; | 36 | struct GNUNET_DISK_PipeHandle; |
37 | 37 | ||
38 | 38 | ||
39 | enum GNUNET_FILE_Type { | ||
40 | GNUNET_DISK_FILE, GNUNET_PIPE | ||
41 | }; | ||
42 | |||
43 | /** | ||
44 | * Handle used to access files (and pipes). | ||
45 | */ | ||
46 | struct GNUNET_DISK_FileHandle | ||
47 | { | ||
48 | |||
49 | #if WINDOWS | ||
50 | /** | ||
51 | * File handle under W32. | ||
52 | */ | ||
53 | HANDLE h; | ||
54 | |||
55 | /** | ||
56 | * Type | ||
57 | */ | ||
58 | enum GNUNET_FILE_Type type; | ||
59 | |||
60 | /** | ||
61 | * Structure for overlapped reading (for pipes) | ||
62 | */ | ||
63 | OVERLAPPED *oOverlapRead; | ||
64 | |||
65 | /** | ||
66 | * Structure for overlapped writing (for pipes) | ||
67 | */ | ||
68 | OVERLAPPED *oOverlapWrite; | ||
69 | #else | ||
70 | |||
71 | /** | ||
72 | * File handle on other OSes. | ||
73 | */ | ||
74 | int fd; | ||
75 | |||
76 | #endif /* | ||
77 | */ | ||
78 | }; | ||
79 | |||
80 | |||
39 | /* we need size_t, and since it can be both unsigned int | 81 | /* we need size_t, and since it can be both unsigned int |
40 | or unsigned long long, this IS platform dependent; | 82 | or unsigned long long, this IS platform dependent; |
41 | but "stdlib.h" should be portable 'enough' to be | 83 | 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; | |||
45 | /** | 45 | /** |
46 | * @brief collection of IO descriptors | 46 | * @brief collection of IO descriptors |
47 | */ | 47 | */ |
48 | struct GNUNET_NETWORK_FDSet; | 48 | struct GNUNET_NETWORK_FDSet |
49 | { | ||
50 | |||
51 | /** | ||
52 | * Maximum number of any socket socket descriptor in the set (plus one) | ||
53 | */ | ||
54 | int nsds; | ||
55 | |||
56 | /** | ||
57 | * Bitset with the descriptors. | ||
58 | */ | ||
59 | fd_set sds; | ||
60 | |||
61 | #ifdef WINDOWS | ||
62 | /** | ||
63 | * Linked list of handles | ||
64 | */ | ||
65 | struct GNUNET_CONTAINER_SList *handles; | ||
66 | #endif | ||
67 | |||
68 | }; | ||
69 | |||
49 | 70 | ||
50 | 71 | ||
51 | #include "gnunet_disk_lib.h" | 72 | #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 | |||
@@ -195,6 +195,20 @@ typedef void (*GNUNET_SCHEDULER_Task) (void *cls, | |||
195 | 195 | ||
196 | 196 | ||
197 | /** | 197 | /** |
198 | * Signature of the select function used by the scheduler. | ||
199 | * GNUNET_NETWORK_socket_select matches it. | ||
200 | * | ||
201 | * @param rfds set of sockets to be checked for readability | ||
202 | * @param wfds set of sockets to be checked for writability | ||
203 | * @param efds set of sockets to be checked for exceptions | ||
204 | * @param timeout relative value when to return | ||
205 | * @return number of selected sockets, GNUNET_SYSERR on error | ||
206 | */ | ||
207 | typedef int (*GNUNET_SCHEDULER_select) (struct GNUNET_NETWORK_FDSet *rfds, | ||
208 | struct GNUNET_NETWORK_FDSet *wfds, | ||
209 | struct GNUNET_NETWORK_FDSet *efds, | ||
210 | struct GNUNET_TIME_Relative timeout); | ||
211 | /** | ||
198 | * Initialize and run scheduler. This function will return when all | 212 | * Initialize and run scheduler. This function will return when all |
199 | * tasks have completed. On systems with signals, receiving a SIGTERM | 213 | * tasks have completed. On systems with signals, receiving a SIGTERM |
200 | * (and other similar signals) will cause "GNUNET_SCHEDULER_shutdown" | 214 | * (and other similar signals) will cause "GNUNET_SCHEDULER_shutdown" |
@@ -494,6 +508,23 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
494 | GNUNET_SCHEDULER_Task task, | 508 | GNUNET_SCHEDULER_Task task, |
495 | void *task_cls); | 509 | void *task_cls); |
496 | 510 | ||
511 | /** | ||
512 | * Sets the select function to use in the scheduler (scheduler_select). | ||
513 | * | ||
514 | * @param new_select new select function to use | ||
515 | * @return previously used select function | ||
516 | */ | ||
517 | GNUNET_SCHEDULER_select | ||
518 | GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select); | ||
519 | |||
520 | /** | ||
521 | * Gets the select function currently used in the scheduler. | ||
522 | * | ||
523 | * @return currently used select function | ||
524 | */ | ||
525 | GNUNET_SCHEDULER_select | ||
526 | GNUNET_SCHEDULER_get_select (); | ||
527 | |||
497 | #if 0 /* keep Emacsens' auto-indent happy */ | 528 | #if 0 /* keep Emacsens' auto-indent happy */ |
498 | { | 529 | { |
499 | #endif | 530 | #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, | |||
92 | * @param cls closure | 92 | * @param cls closure |
93 | * @param peer (claimed) identity of the other peer | 93 | * @param peer (claimed) identity of the other peer |
94 | * @param message the message, NULL if we only care about | 94 | * @param message the message, NULL if we only care about |
95 | * learning about the delay until we should receive again -- FIXME! | 95 | * learning about the delay until we should receive again |
96 | * @param distance in overlay hops; use 1 unless DV (or 0 if message == NULL) | ||
97 | * @param session identifier used for this session (NULL for plugins | 96 | * @param session identifier used for this session (NULL for plugins |
98 | * that do not offer bi-directional communication to the sender | 97 | * that do not offer bi-directional communication to the sender |
99 | * using the same "connection") | 98 | * 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 @@ | |||
22 | * @file util/disk.h | 22 | * @file util/disk.h |
23 | * @brief Internal DISK related helper functions | 23 | * @brief Internal DISK related helper functions |
24 | * @author Nils Durner | 24 | * @author Nils Durner |
25 | */ | 25 | */ |
26 | |||
27 | #ifndef GNUNET_DISK_H_ | 26 | #ifndef GNUNET_DISK_H_ |
28 | #define GNUNET_DISK_H_ | 27 | #define GNUNET_DISK_H_ |
29 | 28 | ||
30 | #include "gnunet_disk_lib.h" | 29 | #include "gnunet_disk_lib.h" |
31 | |||
32 | /** | ||
33 | * Handle used to access files (and pipes). | ||
34 | */ | ||
35 | struct GNUNET_DISK_FileHandle | ||
36 | { | ||
37 | |||
38 | #ifdef MINGW | ||
39 | /** | ||
40 | * File handle under W32. | ||
41 | */ | ||
42 | HANDLE h; | ||
43 | |||
44 | /** | ||
45 | * Type | ||
46 | */ | ||
47 | enum {GNUNET_DISK_FILE, GNUNET_PIPE} type; | ||
48 | 30 | ||
49 | /** | ||
50 | * Structure for overlapped reading (for pipes) | ||
51 | */ | ||
52 | OVERLAPPED *oOverlapRead; | ||
53 | |||
54 | /** | ||
55 | * Structure for overlapped writing (for pipes) | ||
56 | */ | ||
57 | OVERLAPPED *oOverlapWrite; | ||
58 | #else | ||
59 | |||
60 | /** | ||
61 | * File handle on other OSes. | ||
62 | */ | ||
63 | int fd; | ||
64 | |||
65 | #endif /* */ | ||
66 | }; | 31 | }; |
67 | 32 | ||
68 | /** | 33 | /** |
69 | * Retrieve OS file handle | 34 | * Retrieve OS file handle |
70 | * | 35 | * |
@@ -75,6 +40,8 @@ struct GNUNET_DISK_FileHandle | |||
75 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | 40 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise |
76 | */ | 41 | */ |
77 | int GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle | 42 | int GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle |
78 | *fh, void *dst, size_t dst_len); | 43 | *fh, |
79 | 44 | void *dst, | |
45 | size_t dst_len); | ||
46 | |||
80 | #endif /* GNUNET_DISK_H_ */ | 47 | #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 | |||
65 | }; | 65 | }; |
66 | 66 | ||
67 | 67 | ||
68 | struct GNUNET_NETWORK_FDSet | ||
69 | { | ||
70 | |||
71 | /** | ||
72 | * Maximum number of any socket socket descriptor in the set (plus one) | ||
73 | */ | ||
74 | int nsds; | ||
75 | |||
76 | /** | ||
77 | * Bitset with the descriptors. | ||
78 | */ | ||
79 | fd_set sds; | ||
80 | |||
81 | #ifdef WINDOWS | ||
82 | /** | ||
83 | * Linked list of handles | ||
84 | */ | ||
85 | struct GNUNET_CONTAINER_SList *handles; | ||
86 | #endif | ||
87 | |||
88 | }; | ||
89 | |||
90 | #ifndef FD_COPY | 68 | #ifndef FD_COPY |
91 | #define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set))) | 69 | #define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set))) |
92 | #endif | 70 | #endif |
@@ -1620,5 +1598,4 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1620 | return 0; | 1598 | return 0; |
1621 | } | 1599 | } |
1622 | 1600 | ||
1623 | |||
1624 | /* end of network.c */ | 1601 | /* 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 | |||
@@ -246,6 +246,39 @@ static enum GNUNET_SCHEDULER_Priority max_priority_added; | |||
246 | static int current_lifeness; | 246 | static int current_lifeness; |
247 | 247 | ||
248 | /** | 248 | /** |
249 | * Function to use as a select() in the scheduler. | ||
250 | * Defaults to GNUNET_NETWORK_socket_select () | ||
251 | */ | ||
252 | GNUNET_SCHEDULER_select scheduler_select = GNUNET_NETWORK_socket_select; | ||
253 | |||
254 | /** | ||
255 | * Sets the select function to use in the scheduler (scheduler_select). | ||
256 | * | ||
257 | * @param new_select new select function to use | ||
258 | * @return previously used select function | ||
259 | */ | ||
260 | GNUNET_SCHEDULER_select | ||
261 | GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select) | ||
262 | { | ||
263 | GNUNET_SCHEDULER_select old_select = scheduler_select; | ||
264 | scheduler_select = new_select; | ||
265 | if (scheduler_select == NULL) | ||
266 | scheduler_select = GNUNET_NETWORK_socket_select; | ||
267 | return old_select; | ||
268 | } | ||
269 | |||
270 | /** | ||
271 | * Gets the select function currently used in the scheduler. | ||
272 | * | ||
273 | * @return currently used select function | ||
274 | */ | ||
275 | GNUNET_SCHEDULER_select | ||
276 | GNUNET_SCHEDULER_get_select () | ||
277 | { | ||
278 | return scheduler_select; | ||
279 | } | ||
280 | |||
281 | /** | ||
249 | * Check that the given priority is legal (and return it). | 282 | * Check that the given priority is legal (and return it). |
250 | * | 283 | * |
251 | * @param p priority value to check | 284 | * @param p priority value to check |
@@ -806,7 +839,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
806 | /* no blocking, more work already ready! */ | 839 | /* no blocking, more work already ready! */ |
807 | timeout = GNUNET_TIME_UNIT_ZERO; | 840 | timeout = GNUNET_TIME_UNIT_ZERO; |
808 | } | 841 | } |
809 | ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); | 842 | ret = scheduler_select (rs, ws, NULL, timeout); |
810 | if (ret == GNUNET_SYSERR) | 843 | if (ret == GNUNET_SYSERR) |
811 | { | 844 | { |
812 | if (errno == EINTR) | 845 | if (errno == EINTR) |