diff options
Diffstat (limited to 'src/util/nc.c')
-rw-r--r-- | src/util/nc.c | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/src/util/nc.c b/src/util/nc.c index ab7ef122d..9db321b8c 100644 --- a/src/util/nc.c +++ b/src/util/nc.c | |||
@@ -28,13 +28,14 @@ | |||
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | 30 | ||
31 | #define LOG(kind, ...) GNUNET_log_from(kind, "util-nc", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from (kind, "util-nc", __VA_ARGS__) |
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Lists of subscribers we manage for notifications. | 35 | * Lists of subscribers we manage for notifications. |
36 | */ | 36 | */ |
37 | struct SubscriberList { | 37 | struct SubscriberList |
38 | { | ||
38 | /** | 39 | /** |
39 | * This is a doubly linked list. | 40 | * This is a doubly linked list. |
40 | */ | 41 | */ |
@@ -71,7 +72,8 @@ struct SubscriberList { | |||
71 | * (notification) messages are queued up until the subscriber is able to | 72 | * (notification) messages are queued up until the subscriber is able to |
72 | * read them. | 73 | * read them. |
73 | */ | 74 | */ |
74 | struct GNUNET_NotificationContext { | 75 | struct GNUNET_NotificationContext |
76 | { | ||
75 | /** | 77 | /** |
76 | * Head of list of subscribers receiving notifications. | 78 | * Head of list of subscribers receiving notifications. |
77 | */ | 79 | */ |
@@ -95,15 +97,15 @@ struct GNUNET_NotificationContext { | |||
95 | * @param cls our `struct SubscriberList *` | 97 | * @param cls our `struct SubscriberList *` |
96 | */ | 98 | */ |
97 | static void | 99 | static void |
98 | handle_mq_destroy(void *cls) | 100 | handle_mq_destroy (void *cls) |
99 | { | 101 | { |
100 | struct SubscriberList *pos = cls; | 102 | struct SubscriberList *pos = cls; |
101 | struct GNUNET_NotificationContext *nc = pos->nc; | 103 | struct GNUNET_NotificationContext *nc = pos->nc; |
102 | 104 | ||
103 | GNUNET_CONTAINER_DLL_remove(nc->subscribers_head, | 105 | GNUNET_CONTAINER_DLL_remove (nc->subscribers_head, |
104 | nc->subscribers_tail, | 106 | nc->subscribers_tail, |
105 | pos); | 107 | pos); |
106 | GNUNET_free(pos); | 108 | GNUNET_free (pos); |
107 | } | 109 | } |
108 | 110 | ||
109 | 111 | ||
@@ -116,11 +118,11 @@ handle_mq_destroy(void *cls) | |||
116 | * @return handle to the notification context | 118 | * @return handle to the notification context |
117 | */ | 119 | */ |
118 | struct GNUNET_NotificationContext * | 120 | struct GNUNET_NotificationContext * |
119 | GNUNET_notification_context_create(unsigned int queue_length) | 121 | GNUNET_notification_context_create (unsigned int queue_length) |
120 | { | 122 | { |
121 | struct GNUNET_NotificationContext *nc; | 123 | struct GNUNET_NotificationContext *nc; |
122 | 124 | ||
123 | nc = GNUNET_new(struct GNUNET_NotificationContext); | 125 | nc = GNUNET_new (struct GNUNET_NotificationContext); |
124 | nc->queue_length = queue_length; | 126 | nc->queue_length = queue_length; |
125 | return nc; | 127 | return nc; |
126 | } | 128 | } |
@@ -132,19 +134,19 @@ GNUNET_notification_context_create(unsigned int queue_length) | |||
132 | * @param nc context to destroy. | 134 | * @param nc context to destroy. |
133 | */ | 135 | */ |
134 | void | 136 | void |
135 | GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc) | 137 | GNUNET_notification_context_destroy (struct GNUNET_NotificationContext *nc) |
136 | { | 138 | { |
137 | struct SubscriberList *pos; | 139 | struct SubscriberList *pos; |
138 | 140 | ||
139 | while (NULL != (pos = nc->subscribers_head)) | 141 | while (NULL != (pos = nc->subscribers_head)) |
140 | { | 142 | { |
141 | GNUNET_CONTAINER_DLL_remove(nc->subscribers_head, | 143 | GNUNET_CONTAINER_DLL_remove (nc->subscribers_head, |
142 | nc->subscribers_tail, | 144 | nc->subscribers_tail, |
143 | pos); | 145 | pos); |
144 | GNUNET_MQ_destroy_notify_cancel(pos->mq_nh); | 146 | GNUNET_MQ_destroy_notify_cancel (pos->mq_nh); |
145 | GNUNET_free(pos); | 147 | GNUNET_free (pos); |
146 | } | 148 | } |
147 | GNUNET_free(nc); | 149 | GNUNET_free (nc); |
148 | } | 150 | } |
149 | 151 | ||
150 | 152 | ||
@@ -155,8 +157,8 @@ GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc) | |||
155 | * @param mq message queue add | 157 | * @param mq message queue add |
156 | */ | 158 | */ |
157 | void | 159 | void |
158 | GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, | 160 | GNUNET_notification_context_add (struct GNUNET_NotificationContext *nc, |
159 | struct GNUNET_MQ_Handle *mq) | 161 | struct GNUNET_MQ_Handle *mq) |
160 | { | 162 | { |
161 | struct SubscriberList *cl; | 163 | struct SubscriberList *cl; |
162 | 164 | ||
@@ -164,15 +166,15 @@ GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, | |||
164 | if (cl->mq == mq) | 166 | if (cl->mq == mq) |
165 | return; | 167 | return; |
166 | /* already present */ | 168 | /* already present */ |
167 | cl = GNUNET_new(struct SubscriberList); | 169 | cl = GNUNET_new (struct SubscriberList); |
168 | GNUNET_CONTAINER_DLL_insert(nc->subscribers_head, | 170 | GNUNET_CONTAINER_DLL_insert (nc->subscribers_head, |
169 | nc->subscribers_tail, | 171 | nc->subscribers_tail, |
170 | cl); | 172 | cl); |
171 | cl->nc = nc; | 173 | cl->nc = nc; |
172 | cl->mq = mq; | 174 | cl->mq = mq; |
173 | cl->mq_nh = GNUNET_MQ_destroy_notify(cl->mq, | 175 | cl->mq_nh = GNUNET_MQ_destroy_notify (cl->mq, |
174 | &handle_mq_destroy, | 176 | &handle_mq_destroy, |
175 | cl); | 177 | cl); |
176 | } | 178 | } |
177 | 179 | ||
178 | 180 | ||
@@ -184,22 +186,22 @@ GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, | |||
184 | * @param can_drop can this message be dropped due to queue length limitations | 186 | * @param can_drop can this message be dropped due to queue length limitations |
185 | */ | 187 | */ |
186 | void | 188 | void |
187 | GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, | 189 | GNUNET_notification_context_broadcast (struct GNUNET_NotificationContext *nc, |
188 | const struct GNUNET_MessageHeader *msg, | 190 | const struct GNUNET_MessageHeader *msg, |
189 | int can_drop) | 191 | int can_drop) |
190 | { | 192 | { |
191 | struct SubscriberList *pos; | 193 | struct SubscriberList *pos; |
192 | struct GNUNET_MQ_Envelope *env; | 194 | struct GNUNET_MQ_Envelope *env; |
193 | 195 | ||
194 | for (pos = nc->subscribers_head; NULL != pos; pos = pos->next) | 196 | for (pos = nc->subscribers_head; NULL != pos; pos = pos->next) |
195 | { | 197 | { |
196 | if ((GNUNET_YES == can_drop) && | 198 | if ((GNUNET_YES == can_drop) && |
197 | (GNUNET_MQ_get_length(pos->mq) > nc->queue_length)) | 199 | (GNUNET_MQ_get_length (pos->mq) > nc->queue_length)) |
198 | continue; | 200 | continue; |
199 | env = GNUNET_MQ_msg_copy(msg); | 201 | env = GNUNET_MQ_msg_copy (msg); |
200 | GNUNET_MQ_send(pos->mq, | 202 | GNUNET_MQ_send (pos->mq, |
201 | env); | 203 | env); |
202 | } | 204 | } |
203 | } | 205 | } |
204 | 206 | ||
205 | 207 | ||
@@ -210,7 +212,7 @@ GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, | |||
210 | * @return number of current subscribers | 212 | * @return number of current subscribers |
211 | */ | 213 | */ |
212 | unsigned int | 214 | unsigned int |
213 | GNUNET_notification_context_get_size(struct GNUNET_NotificationContext *nc) | 215 | GNUNET_notification_context_get_size (struct GNUNET_NotificationContext *nc) |
214 | { | 216 | { |
215 | unsigned int num; | 217 | unsigned int num; |
216 | struct SubscriberList *pos; | 218 | struct SubscriberList *pos; |