aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-14 11:08:43 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-14 11:08:43 +0000
commit53da062e08f1d1d4392b3a40396bb45cc093e2ac (patch)
tree40b132f38c1d6b46476bfd9c1917070956ce4861 /src/util
parent1debac4608e78f4a7800252ba9a91b4f5a376b42 (diff)
downloadgnunet-53da062e08f1d1d4392b3a40396bb45cc093e2ac.tar.gz
gnunet-53da062e08f1d1d4392b3a40396bb45cc093e2ac.zip
LRN: Added-the-ability-to-substitute-scheduler-select.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/disk.h45
-rw-r--r--src/util/network.c23
-rw-r--r--src/util/scheduler.c35
3 files changed, 40 insertions, 63 deletions
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 */
35struct 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 */
77int GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle 42int 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
68struct 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;
246static int current_lifeness; 246static 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 */
252GNUNET_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 */
260GNUNET_SCHEDULER_select
261GNUNET_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 */
275GNUNET_SCHEDULER_select
276GNUNET_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)