aboutsummaryrefslogtreecommitdiff
path: root/src/util/server_nc.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
commit83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch)
treed0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/util/server_nc.c
parent28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff)
downloadgnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz
gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip
curly wars / auto-indentation
Diffstat (limited to 'src/util/server_nc.c')
-rw-r--r--src/util/server_nc.c205
1 files changed, 100 insertions, 105 deletions
diff --git a/src/util/server_nc.c b/src/util/server_nc.c
index cbe98a014..a36fa0c50 100644
--- a/src/util/server_nc.c
+++ b/src/util/server_nc.c
@@ -156,19 +156,19 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
156 struct PendingMessageList *pml; 156 struct PendingMessageList *pml;
157 157
158 if (client == NULL) 158 if (client == NULL)
159 { 159 {
160 nc->server = NULL; 160 nc->server = NULL;
161 return; 161 return;
162 } 162 }
163 prev = NULL; 163 prev = NULL;
164 pos = nc->clients; 164 pos = nc->clients;
165 while (NULL != pos) 165 while (NULL != pos)
166 { 166 {
167 if (pos->client == client) 167 if (pos->client == client)
168 break; 168 break;
169 prev = pos; 169 prev = pos;
170 pos = pos->next; 170 pos = pos->next;
171 } 171 }
172 if (pos == NULL) 172 if (pos == NULL)
173 return; 173 return;
174#if DEBUG_SERVER_NC 174#if DEBUG_SERVER_NC
@@ -181,15 +181,15 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
181 else 181 else
182 prev->next = pos->next; 182 prev->next = pos->next;
183 while (NULL != (pml = pos->pending_head)) 183 while (NULL != (pml = pos->pending_head))
184 { 184 {
185 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml); 185 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml);
186 GNUNET_free (pml); 186 GNUNET_free (pml);
187 } 187 }
188 if (pos->th != NULL) 188 if (pos->th != NULL)
189 { 189 {
190 GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th); 190 GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th);
191 pos->th = NULL; 191 pos->th = NULL;
192 } 192 }
193 GNUNET_SERVER_client_drop (client); 193 GNUNET_SERVER_client_drop (client);
194 GNUNET_free (pos); 194 GNUNET_free (pos);
195} 195}
@@ -205,8 +205,8 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
205 * @return handle to the notification context 205 * @return handle to the notification context
206 */ 206 */
207struct GNUNET_SERVER_NotificationContext * 207struct GNUNET_SERVER_NotificationContext *
208GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle 208GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server,
209 *server, unsigned int queue_length) 209 unsigned int queue_length)
210{ 210{
211 struct GNUNET_SERVER_NotificationContext *ret; 211 struct GNUNET_SERVER_NotificationContext *ret;
212 212
@@ -225,27 +225,26 @@ GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle
225 */ 225 */
226void 226void
227GNUNET_SERVER_notification_context_destroy (struct 227GNUNET_SERVER_notification_context_destroy (struct
228 GNUNET_SERVER_NotificationContext 228 GNUNET_SERVER_NotificationContext
229 *nc) 229 *nc)
230{ 230{
231 struct ClientList *pos; 231 struct ClientList *pos;
232 struct PendingMessageList *pml; 232 struct PendingMessageList *pml;
233 233
234 while (NULL != (pos = nc->clients)) 234 while (NULL != (pos = nc->clients))
235 {
236 nc->clients = pos->next;
237 GNUNET_SERVER_client_drop (pos->client);
238 while (NULL != (pml = pos->pending_head))
235 { 239 {
236 nc->clients = pos->next; 240 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml);
237 GNUNET_SERVER_client_drop (pos->client); 241 GNUNET_free (pml);
238 while (NULL != (pml = pos->pending_head))
239 {
240 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail,
241 pml);
242 GNUNET_free (pml);
243 }
244 GNUNET_free (pos);
245 } 242 }
243 GNUNET_free (pos);
244 }
246 if (nc->server != NULL) 245 if (nc->server != NULL)
247 GNUNET_SERVER_disconnect_notify_cancel (nc->server, 246 GNUNET_SERVER_disconnect_notify_cancel (nc->server,
248 &handle_client_disconnect, nc); 247 &handle_client_disconnect, nc);
249 GNUNET_free (nc); 248 GNUNET_free (nc);
250} 249}
251 250
@@ -257,9 +256,9 @@ GNUNET_SERVER_notification_context_destroy (struct
257 * @param client client to add 256 * @param client client to add
258 */ 257 */
259void 258void
260GNUNET_SERVER_notification_context_add (struct 259GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext
261 GNUNET_SERVER_NotificationContext *nc, 260 *nc,
262 struct GNUNET_SERVER_Client *client) 261 struct GNUNET_SERVER_Client *client)
263{ 262{
264 struct ClientList *cl; 263 struct ClientList *cl;
265 264
@@ -293,45 +292,44 @@ transmit_message (void *cls, size_t size, void *buf)
293 292
294 cl->th = NULL; 293 cl->th = NULL;
295 if (buf == NULL) 294 if (buf == NULL)
296 { 295 {
297 /* 'cl' should be freed via disconnect notification shortly */ 296 /* 'cl' should be freed via disconnect notification shortly */
298#if DEBUG_SERVER_NC 297#if DEBUG_SERVER_NC
299 LOG (GNUNET_ERROR_TYPE_DEBUG, 298 LOG (GNUNET_ERROR_TYPE_DEBUG,
300 "Failed to transmit message from NC queue to client\n"); 299 "Failed to transmit message from NC queue to client\n");
301#endif 300#endif
302 return 0; 301 return 0;
303 } 302 }
304 ret = 0; 303 ret = 0;
305 while (NULL != (pml = cl->pending_head)) 304 while (NULL != (pml = cl->pending_head))
306 { 305 {
307 msize = ntohs (pml->msg->size); 306 msize = ntohs (pml->msg->size);
308 if (size < msize) 307 if (size < msize)
309 break; 308 break;
310 GNUNET_CONTAINER_DLL_remove (cl->pending_head, cl->pending_tail, pml); 309 GNUNET_CONTAINER_DLL_remove (cl->pending_head, cl->pending_tail, pml);
311#if DEBUG_SERVER_NC 310#if DEBUG_SERVER_NC
312 LOG (GNUNET_ERROR_TYPE_DEBUG, 311 LOG (GNUNET_ERROR_TYPE_DEBUG,
313 "Copying message of type %u and size %u from pending queue to transmission buffer\n", 312 "Copying message of type %u and size %u from pending queue to transmission buffer\n",
314 ntohs (pml->msg->type), msize); 313 ntohs (pml->msg->type), msize);
315#endif 314#endif
316 memcpy (&cbuf[ret], pml->msg, msize); 315 memcpy (&cbuf[ret], pml->msg, msize);
317 ret += msize; 316 ret += msize;
318 size -= msize; 317 size -= msize;
319 GNUNET_free (pml); 318 GNUNET_free (pml);
320 cl->num_pending--; 319 cl->num_pending--;
321 } 320 }
322 if (pml != NULL) 321 if (pml != NULL)
323 { 322 {
324#if DEBUG_SERVER_NC 323#if DEBUG_SERVER_NC
325 LOG (GNUNET_ERROR_TYPE_DEBUG, 324 LOG (GNUNET_ERROR_TYPE_DEBUG,
326 "Have %u messages left in NC queue, will try transmission again\n", 325 "Have %u messages left in NC queue, will try transmission again\n",
327 cl->num_pending); 326 cl->num_pending);
328#endif 327#endif
329 cl->th = 328 cl->th =
330 GNUNET_SERVER_notify_transmit_ready (cl->client, 329 GNUNET_SERVER_notify_transmit_ready (cl->client, ntohs (pml->msg->size),
331 ntohs (pml->msg->size), 330 GNUNET_TIME_UNIT_FOREVER_REL,
332 GNUNET_TIME_UNIT_FOREVER_REL, 331 &transmit_message, cl);
333 &transmit_message, cl); 332 }
334 }
335 else 333 else
336 GNUNET_assert (cl->num_pending == 0); 334 GNUNET_assert (cl->num_pending == 0);
337 return ret; 335 return ret;
@@ -348,25 +346,24 @@ transmit_message (void *cls, size_t size, void *buf)
348 */ 346 */
349static void 347static void
350do_unicast (struct GNUNET_SERVER_NotificationContext *nc, 348do_unicast (struct GNUNET_SERVER_NotificationContext *nc,
351 struct ClientList *client, const struct GNUNET_MessageHeader *msg, 349 struct ClientList *client, const struct GNUNET_MessageHeader *msg,
352 int can_drop) 350 int can_drop)
353{ 351{
354 struct PendingMessageList *pml; 352 struct PendingMessageList *pml;
355 uint16_t size; 353 uint16_t size;
356 354
357 if ((client->num_pending > nc->queue_length) && (GNUNET_YES == can_drop)) 355 if ((client->num_pending > nc->queue_length) && (GNUNET_YES == can_drop))
358 { 356 {
359 LOG (GNUNET_ERROR_TYPE_INFO, 357 LOG (GNUNET_ERROR_TYPE_INFO,
360 "Dropping message of type %u and size %u due to full queue (%u entries)\n", 358 "Dropping message of type %u and size %u due to full queue (%u entries)\n",
361 ntohs (msg->type), ntohs (msg->size), 359 ntohs (msg->type), ntohs (msg->size), (unsigned int) nc->queue_length);
362 (unsigned int) nc->queue_length); 360 return; /* drop! */
363 return; /* drop! */ 361 }
364 }
365 if (client->num_pending > nc->queue_length) 362 if (client->num_pending > nc->queue_length)
366 { 363 {
367 /* FIXME: consider checking for other messages in the 364 /* FIXME: consider checking for other messages in the
368 * queue that are 'droppable' */ 365 * queue that are 'droppable' */
369 } 366 }
370 client->num_pending++; 367 client->num_pending++;
371 size = ntohs (msg->size); 368 size = ntohs (msg->size);
372 pml = GNUNET_malloc (sizeof (struct PendingMessageList) + size); 369 pml = GNUNET_malloc (sizeof (struct PendingMessageList) + size);
@@ -379,15 +376,15 @@ do_unicast (struct GNUNET_SERVER_NotificationContext *nc,
379#endif 376#endif
380 memcpy (&pml[1], msg, size); 377 memcpy (&pml[1], msg, size);
381 /* append */ 378 /* append */
382 GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, 379 GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, client->pending_tail,
383 client->pending_tail, pml); 380 pml);
384 if (client->th == NULL) 381 if (client->th == NULL)
385 client->th = 382 client->th =
386 GNUNET_SERVER_notify_transmit_ready (client->client, 383 GNUNET_SERVER_notify_transmit_ready (client->client,
387 ntohs (client->pending_head-> 384 ntohs (client->pending_head->
388 msg->size), 385 msg->size),
389 GNUNET_TIME_UNIT_FOREVER_REL, 386 GNUNET_TIME_UNIT_FOREVER_REL,
390 &transmit_message, client); 387 &transmit_message, client);
391} 388}
392 389
393 390
@@ -402,22 +399,21 @@ do_unicast (struct GNUNET_SERVER_NotificationContext *nc,
402 */ 399 */
403void 400void
404GNUNET_SERVER_notification_context_unicast (struct 401GNUNET_SERVER_notification_context_unicast (struct
405 GNUNET_SERVER_NotificationContext 402 GNUNET_SERVER_NotificationContext
406 *nc, 403 *nc,
407 struct GNUNET_SERVER_Client 404 struct GNUNET_SERVER_Client *client,
408 *client, 405 const struct GNUNET_MessageHeader
409 const struct GNUNET_MessageHeader 406 *msg, int can_drop)
410 *msg, int can_drop)
411{ 407{
412 struct ClientList *pos; 408 struct ClientList *pos;
413 409
414 pos = nc->clients; 410 pos = nc->clients;
415 while (NULL != pos) 411 while (NULL != pos)
416 { 412 {
417 if (pos->client == client) 413 if (pos->client == client)
418 break; 414 break;
419 pos = pos->next; 415 pos = pos->next;
420 } 416 }
421 GNUNET_assert (pos != NULL); 417 GNUNET_assert (pos != NULL);
422 do_unicast (nc, pos, msg, can_drop); 418 do_unicast (nc, pos, msg, can_drop);
423} 419}
@@ -432,20 +428,19 @@ GNUNET_SERVER_notification_context_unicast (struct
432 */ 428 */
433void 429void
434GNUNET_SERVER_notification_context_broadcast (struct 430GNUNET_SERVER_notification_context_broadcast (struct
435 GNUNET_SERVER_NotificationContext 431 GNUNET_SERVER_NotificationContext
436 *nc, 432 *nc,
437 const struct 433 const struct GNUNET_MessageHeader
438 GNUNET_MessageHeader *msg, 434 *msg, int can_drop)
439 int can_drop)
440{ 435{
441 struct ClientList *pos; 436 struct ClientList *pos;
442 437
443 pos = nc->clients; 438 pos = nc->clients;
444 while (NULL != pos) 439 while (NULL != pos)
445 { 440 {
446 do_unicast (nc, pos, msg, can_drop); 441 do_unicast (nc, pos, msg, can_drop);
447 pos = pos->next; 442 pos = pos->next;
448 } 443 }
449} 444}
450 445
451 446