[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r21256 - gnunet/src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r21256 - gnunet/src/util |
Date: |
Thu, 3 May 2012 19:52:14 +0200 |
Author: grothoff
Date: 2012-05-03 19:52:14 +0200 (Thu, 03 May 2012)
New Revision: 21256
Modified:
gnunet/src/util/server_nc.c
Log:
-code cleanup
Modified: gnunet/src/util/server_nc.c
===================================================================
--- gnunet/src/util/server_nc.c 2012-05-03 17:46:55 UTC (rev 21255)
+++ gnunet/src/util/server_nc.c 2012-05-03 17:52:14 UTC (rev 21256)
@@ -73,11 +73,16 @@
{
/**
- * This is a linked list.
+ * This is a doubly linked list.
*/
struct ClientList *next;
/**
+ * This is a doubly linked list.
+ */
+ struct ClientList *prev;
+
+ /**
* Overall context this client belongs to.
*/
struct GNUNET_SERVER_NotificationContext *nc;
@@ -127,11 +132,16 @@
struct GNUNET_SERVER_Handle *server;
/**
- * List of clients receiving notifications.
+ * Head of list of clients receiving notifications.
*/
- struct ClientList *clients;
+ struct ClientList *clients_head;
/**
+ * Tail of list of clients receiving notifications.
+ */
+ struct ClientList *clients_tail;
+
+ /**
* Maximum number of optional messages to queue per client.
*/
unsigned int queue_length;
@@ -150,39 +160,31 @@
{
struct GNUNET_SERVER_NotificationContext *nc = cls;
struct ClientList *pos;
- struct ClientList *prev;
struct PendingMessageList *pml;
- if (client == NULL)
+ if (NULL == client)
{
nc->server = NULL;
return;
}
- prev = NULL;
- pos = nc->clients;
- while (NULL != pos)
- {
+ for (pos = nc->clients_head; NULL != pos; pos = pos->next)
if (pos->client == client)
break;
- prev = pos;
- pos = pos->next;
- }
- if (pos == NULL)
+ if (NULL == pos)
return;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Client disconnected, cleaning up %u messages in NC queue\n",
pos->num_pending);
- if (prev == NULL)
- nc->clients = pos->next;
- else
- prev->next = pos->next;
+ GNUNET_CONTAINER_DLL_remove (nc->clients_head,
+ nc->clients_tail,
+ pos);
while (NULL != (pml = pos->pending_head))
{
GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml);
GNUNET_free (pml);
pos->num_pending--;
}
- if (pos->th != NULL)
+ if (NULL != pos->th)
{
GNUNET_SERVER_notify_transmit_ready_cancel (pos->th);
pos->th = NULL;
@@ -229,9 +231,11 @@
struct ClientList *pos;
struct PendingMessageList *pml;
- while (NULL != (pos = nc->clients))
+ while (NULL != (pos = nc->clients_head))
{
- nc->clients = pos->next;
+ GNUNET_CONTAINER_DLL_remove (nc->clients_head,
+ nc->clients_tail,
+ pos);
GNUNET_SERVER_client_drop (pos->client);
while (NULL != (pml = pos->pending_head))
{
@@ -242,7 +246,7 @@
GNUNET_assert (0 == pos->num_pending);
GNUNET_free (pos);
}
- if (nc->server != NULL)
+ if (NULL != nc->server)
GNUNET_SERVER_disconnect_notify_cancel (nc->server,
&handle_client_disconnect, nc);
GNUNET_free (nc);
@@ -262,15 +266,16 @@
{
struct ClientList *cl;
- for (cl = nc->clients; NULL != cl; cl = cl->next)
+ for (cl = nc->clients_head; NULL != cl; cl = cl->next)
if (cl->client == client)
return; /* already present */
cl = GNUNET_malloc (sizeof (struct ClientList));
- cl->next = nc->clients;
+ GNUNET_CONTAINER_DLL_insert (nc->clients_head,
+ nc->clients_tail,
+ cl);
cl->nc = nc;
cl->client = client;
GNUNET_SERVER_client_keep (client);
- nc->clients = cl;
}
@@ -294,7 +299,7 @@
size_t ret;
cl->th = NULL;
- if (buf == NULL)
+ if (NULL == buf)
{
/* 'cl' should be freed via disconnect notification shortly */
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -404,14 +409,10 @@
{
struct ClientList *pos;
- pos = nc->clients;
- while (NULL != pos)
- {
+ for (pos = nc->clients_head; NULL != pos; pos = pos->next)
if (pos->client == client)
break;
- pos = pos->next;
- }
- GNUNET_assert (pos != NULL);
+ GNUNET_assert (NULL != pos);
do_unicast (nc, pos, msg, can_drop);
}
@@ -432,12 +433,8 @@
{
struct ClientList *pos;
- pos = nc->clients;
- while (NULL != pos)
- {
+ for (pos = nc->clients_head; NULL != pos; pos = pos->next)
do_unicast (nc, pos, msg, can_drop);
- pos = pos->next;
- }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r21256 - gnunet/src/util,
gnunet <=