diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-05-03 17:52:14 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-05-03 17:52:14 +0000 |
commit | 2a9261aba30d231350d8487b53b347157e6f05a1 (patch) | |
tree | 4b0f9f910beb93d5400d62625ddf0aa8d9be149f /src/util/server_nc.c | |
parent | 1376117631d89151f5054f69c4f0356aad39916e (diff) | |
download | gnunet-2a9261aba30d231350d8487b53b347157e6f05a1.tar.gz gnunet-2a9261aba30d231350d8487b53b347157e6f05a1.zip |
-code cleanup
Diffstat (limited to 'src/util/server_nc.c')
-rw-r--r-- | src/util/server_nc.c | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/src/util/server_nc.c b/src/util/server_nc.c index 249b7ad40..f6b0d8e22 100644 --- a/src/util/server_nc.c +++ b/src/util/server_nc.c | |||
@@ -73,11 +73,16 @@ struct ClientList | |||
73 | { | 73 | { |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * This is a linked list. | 76 | * This is a doubly linked list. |
77 | */ | 77 | */ |
78 | struct ClientList *next; | 78 | struct ClientList *next; |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * This is a doubly linked list. | ||
82 | */ | ||
83 | struct ClientList *prev; | ||
84 | |||
85 | /** | ||
81 | * Overall context this client belongs to. | 86 | * Overall context this client belongs to. |
82 | */ | 87 | */ |
83 | struct GNUNET_SERVER_NotificationContext *nc; | 88 | struct GNUNET_SERVER_NotificationContext *nc; |
@@ -127,9 +132,14 @@ struct GNUNET_SERVER_NotificationContext | |||
127 | struct GNUNET_SERVER_Handle *server; | 132 | struct GNUNET_SERVER_Handle *server; |
128 | 133 | ||
129 | /** | 134 | /** |
130 | * List of clients receiving notifications. | 135 | * Head of list of clients receiving notifications. |
131 | */ | 136 | */ |
132 | struct ClientList *clients; | 137 | struct ClientList *clients_head; |
138 | |||
139 | /** | ||
140 | * Tail of list of clients receiving notifications. | ||
141 | */ | ||
142 | struct ClientList *clients_tail; | ||
133 | 143 | ||
134 | /** | 144 | /** |
135 | * Maximum number of optional messages to queue per client. | 145 | * Maximum number of optional messages to queue per client. |
@@ -150,39 +160,31 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
150 | { | 160 | { |
151 | struct GNUNET_SERVER_NotificationContext *nc = cls; | 161 | struct GNUNET_SERVER_NotificationContext *nc = cls; |
152 | struct ClientList *pos; | 162 | struct ClientList *pos; |
153 | struct ClientList *prev; | ||
154 | struct PendingMessageList *pml; | 163 | struct PendingMessageList *pml; |
155 | 164 | ||
156 | if (client == NULL) | 165 | if (NULL == client) |
157 | { | 166 | { |
158 | nc->server = NULL; | 167 | nc->server = NULL; |
159 | return; | 168 | return; |
160 | } | 169 | } |
161 | prev = NULL; | 170 | for (pos = nc->clients_head; NULL != pos; pos = pos->next) |
162 | pos = nc->clients; | ||
163 | while (NULL != pos) | ||
164 | { | ||
165 | if (pos->client == client) | 171 | if (pos->client == client) |
166 | break; | 172 | break; |
167 | prev = pos; | 173 | if (NULL == pos) |
168 | pos = pos->next; | ||
169 | } | ||
170 | if (pos == NULL) | ||
171 | return; | 174 | return; |
172 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 175 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
173 | "Client disconnected, cleaning up %u messages in NC queue\n", | 176 | "Client disconnected, cleaning up %u messages in NC queue\n", |
174 | pos->num_pending); | 177 | pos->num_pending); |
175 | if (prev == NULL) | 178 | GNUNET_CONTAINER_DLL_remove (nc->clients_head, |
176 | nc->clients = pos->next; | 179 | nc->clients_tail, |
177 | else | 180 | pos); |
178 | prev->next = pos->next; | ||
179 | while (NULL != (pml = pos->pending_head)) | 181 | while (NULL != (pml = pos->pending_head)) |
180 | { | 182 | { |
181 | GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml); | 183 | GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml); |
182 | GNUNET_free (pml); | 184 | GNUNET_free (pml); |
183 | pos->num_pending--; | 185 | pos->num_pending--; |
184 | } | 186 | } |
185 | if (pos->th != NULL) | 187 | if (NULL != pos->th) |
186 | { | 188 | { |
187 | GNUNET_SERVER_notify_transmit_ready_cancel (pos->th); | 189 | GNUNET_SERVER_notify_transmit_ready_cancel (pos->th); |
188 | pos->th = NULL; | 190 | pos->th = NULL; |
@@ -229,9 +231,11 @@ GNUNET_SERVER_notification_context_destroy (struct | |||
229 | struct ClientList *pos; | 231 | struct ClientList *pos; |
230 | struct PendingMessageList *pml; | 232 | struct PendingMessageList *pml; |
231 | 233 | ||
232 | while (NULL != (pos = nc->clients)) | 234 | while (NULL != (pos = nc->clients_head)) |
233 | { | 235 | { |
234 | nc->clients = pos->next; | 236 | GNUNET_CONTAINER_DLL_remove (nc->clients_head, |
237 | nc->clients_tail, | ||
238 | pos); | ||
235 | GNUNET_SERVER_client_drop (pos->client); | 239 | GNUNET_SERVER_client_drop (pos->client); |
236 | while (NULL != (pml = pos->pending_head)) | 240 | while (NULL != (pml = pos->pending_head)) |
237 | { | 241 | { |
@@ -242,7 +246,7 @@ GNUNET_SERVER_notification_context_destroy (struct | |||
242 | GNUNET_assert (0 == pos->num_pending); | 246 | GNUNET_assert (0 == pos->num_pending); |
243 | GNUNET_free (pos); | 247 | GNUNET_free (pos); |
244 | } | 248 | } |
245 | if (nc->server != NULL) | 249 | if (NULL != nc->server) |
246 | GNUNET_SERVER_disconnect_notify_cancel (nc->server, | 250 | GNUNET_SERVER_disconnect_notify_cancel (nc->server, |
247 | &handle_client_disconnect, nc); | 251 | &handle_client_disconnect, nc); |
248 | GNUNET_free (nc); | 252 | GNUNET_free (nc); |
@@ -262,15 +266,16 @@ GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext | |||
262 | { | 266 | { |
263 | struct ClientList *cl; | 267 | struct ClientList *cl; |
264 | 268 | ||
265 | for (cl = nc->clients; NULL != cl; cl = cl->next) | 269 | for (cl = nc->clients_head; NULL != cl; cl = cl->next) |
266 | if (cl->client == client) | 270 | if (cl->client == client) |
267 | return; /* already present */ | 271 | return; /* already present */ |
268 | cl = GNUNET_malloc (sizeof (struct ClientList)); | 272 | cl = GNUNET_malloc (sizeof (struct ClientList)); |
269 | cl->next = nc->clients; | 273 | GNUNET_CONTAINER_DLL_insert (nc->clients_head, |
274 | nc->clients_tail, | ||
275 | cl); | ||
270 | cl->nc = nc; | 276 | cl->nc = nc; |
271 | cl->client = client; | 277 | cl->client = client; |
272 | GNUNET_SERVER_client_keep (client); | 278 | GNUNET_SERVER_client_keep (client); |
273 | nc->clients = cl; | ||
274 | } | 279 | } |
275 | 280 | ||
276 | 281 | ||
@@ -294,7 +299,7 @@ transmit_message (void *cls, size_t size, void *buf) | |||
294 | size_t ret; | 299 | size_t ret; |
295 | 300 | ||
296 | cl->th = NULL; | 301 | cl->th = NULL; |
297 | if (buf == NULL) | 302 | if (NULL == buf) |
298 | { | 303 | { |
299 | /* 'cl' should be freed via disconnect notification shortly */ | 304 | /* 'cl' should be freed via disconnect notification shortly */ |
300 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 305 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -404,14 +409,10 @@ GNUNET_SERVER_notification_context_unicast (struct | |||
404 | { | 409 | { |
405 | struct ClientList *pos; | 410 | struct ClientList *pos; |
406 | 411 | ||
407 | pos = nc->clients; | 412 | for (pos = nc->clients_head; NULL != pos; pos = pos->next) |
408 | while (NULL != pos) | ||
409 | { | ||
410 | if (pos->client == client) | 413 | if (pos->client == client) |
411 | break; | 414 | break; |
412 | pos = pos->next; | 415 | GNUNET_assert (NULL != pos); |
413 | } | ||
414 | GNUNET_assert (pos != NULL); | ||
415 | do_unicast (nc, pos, msg, can_drop); | 416 | do_unicast (nc, pos, msg, can_drop); |
416 | } | 417 | } |
417 | 418 | ||
@@ -432,12 +433,8 @@ GNUNET_SERVER_notification_context_broadcast (struct | |||
432 | { | 433 | { |
433 | struct ClientList *pos; | 434 | struct ClientList *pos; |
434 | 435 | ||
435 | pos = nc->clients; | 436 | for (pos = nc->clients_head; NULL != pos; pos = pos->next) |
436 | while (NULL != pos) | ||
437 | { | ||
438 | do_unicast (nc, pos, msg, can_drop); | 437 | do_unicast (nc, pos, msg, can_drop); |
439 | pos = pos->next; | ||
440 | } | ||
441 | } | 438 | } |
442 | 439 | ||
443 | 440 | ||