gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r6406 - GNUnet/src/applications/chat


From: gnunet
Subject: [GNUnet-SVN] r6406 - GNUnet/src/applications/chat
Date: Thu, 21 Feb 2008 17:58:44 -0700 (MST)

Author: nevans
Date: 2008-02-21 17:58:44 -0700 (Thu, 21 Feb 2008)
New Revision: 6406

Modified:
   GNUnet/src/applications/chat/chat.c
   GNUnet/src/applications/chat/clientapi.c
Log:


Modified: GNUnet/src/applications/chat/chat.c
===================================================================
--- GNUnet/src/applications/chat/chat.c 2008-02-21 21:56:42 UTC (rev 6405)
+++ GNUnet/src/applications/chat/chat.c 2008-02-22 00:58:44 UTC (rev 6406)
@@ -115,7 +115,7 @@
   /*TODO: we have received a message intended for some room, check current 
client contexts for matching room and send to those clients */
   /*TODO: p2p messages will need to be sent as well at some point */
 
-  tempClient = &client_list;
+  tempClient = client_list_head;
   while ((tempClient->next != NULL) && (tempClient->client != NULL))
     {
       if (memcmp
@@ -269,12 +269,10 @@
   return GNUNET_OK;
 }
 
-/* WHY HAVE A LEAVE REQUEST AT ALL? => CLIENT EXIT HANDLER */
-static int
-csHandleChatLeaveRequest (struct GNUNET_ClientHandle *client,
-                          const GNUNET_MessageHeader * message)
+
+static void
+chatClientExitHandler (struct GNUNET_ClientHandle *client)
 {
-  /*GNUNET_RSA_PublicKey *client_key; *//*May use later for extra verification 
*/
   int tempCount;
 
   struct GNUNET_CS_chat_client * pos;
@@ -291,17 +289,15 @@
   GNUNET_mutex_lock (chatMutex);
 
   /*TODO: delete client context on the server */
-  /* YUCK */
   pos = client_list_head;
   prev = NULL;
-  while ( (pos != NULL) &&
-         (pos->client != client) )
-    {
+  while ( (pos != NULL) && (pos->client != client) )
+       {
       prev = pos;
       pos = pos->next;
     }
   if (pos != NULL)
-    {
+       {
       if (prev == NULL)
        client_list_head = pos->next;
       else
@@ -324,32 +320,19 @@
 
   GNUNET_mutex_unlock (chatMutex);
   fprintf (stderr, "End of handleChatLeave\n");
-  return GNUNET_OK;
+  return;
 }
 
 
-static void
-chatClientExitHandler (struct GNUNET_ClientHandle *client)
-{
-  GNUNET_mutex_lock (chatMutex);
-
-
-  GNUNET_mutex_unlock (chatMutex);
-}
-
-
 int
 initialize_module_chat (GNUNET_CoreAPIForPlugins * capi)
 {
   int ok = GNUNET_OK;
-  clientCount = 0;
 
-  lastMsgs = GNUNET_malloc (sizeof (GNUNET_HashCode) * MAX_LAST_MESSAGES);
-
   GNUNET_GE_ASSERT (ectx,
                     sizeof (P2P_chat_MESSAGE) == sizeof (CS_chat_MESSAGE));
   chatMutex = GNUNET_mutex_create (GNUNET_NO);
-  clientCount = 0;
+  
   coreAPI = capi;
   GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
                  _("`%s' registering handlers %d and %d\n"),
@@ -367,11 +350,6 @@
                                    &csHandleChatRequest))
     ok = GNUNET_SYSERR;
 
-  if (GNUNET_SYSERR ==
-      capi->registerClientHandler (GNUNET_CS_PROTO_CHAT_LEAVE_MSG,
-                                   &csHandleChatLeaveRequest))
-    ok = GNUNET_SYSERR;
-
   if (GNUNET_SYSERR == capi->registerClientHandler (GNUNET_CS_PROTO_CHAT_MSG,
                                                     &csHandleChatMSG))
     ok = GNUNET_SYSERR;
@@ -395,8 +373,7 @@
                                     &csHandleChatMSG);
   coreAPI->unregisterClientHandler (GNUNET_CS_PROTO_CHAT_JOIN_MSG,
                                     &csHandleChatRequest);
-  coreAPI->unregisterClientHandler (GNUNET_CS_PROTO_CHAT_LEAVE_MSG,
-                                    &csHandleChatLeaveRequest);
+
   GNUNET_mutex_destroy (chatMutex);
   coreAPI = NULL;
 }

Modified: GNUnet/src/applications/chat/clientapi.c
===================================================================
--- GNUnet/src/applications/chat/clientapi.c    2008-02-21 21:56:42 UTC (rev 
6405)
+++ GNUnet/src/applications/chat/clientapi.c    2008-02-22 00:58:44 UTC (rev 
6406)
@@ -31,8 +31,6 @@
 #include "gnunet_chat_lib.h"
 #include "chat.h"
 
-#define MAX_RETRIES 5
-
 /**
  * Handle for a (joined) chat room.
  */
@@ -61,6 +59,8 @@
   char *memberInfo;
 
   GNUNET_CHAT_MessageCallback callback;
+  
+  int shutdown_flag;
 
   void *callback_cls;
 
@@ -85,24 +85,25 @@
   char *nick;
   char *message_content;
   char *room_name;
+  int disconnected;
 
   ret = GNUNET_OK;
-  /* CHECK FOR SHUTDOWN! */
+
   while (room->shutdown_flag != GNUNET_YES)
     {
       if (disconnected)
        {
-         if (GNUNET_client_connection_ensure_connected (room->sock) == 
GNUNET_OK)
+         if (GNUNET_client_connection_ensure_connected (room->sock) != 
GNUNET_OK)
            {
-             disconnected = 0;
+             disconnected = GNUNET_YES;
              /* send join! */
            }
          else
            {
              GNUNET_thread_sleep(5 * GNUNET_CRON_SECONDS);
              continue;
-            }
         }
+    }
 
       reply = NULL;
 
@@ -280,8 +281,8 @@
   void * unused;
   chat_room->shutdown_flag = GNUNET_YES;
   GNUNET_client_connection_close_forever (chat_room->sock);
-  GNUNET_stop_sleep(room->listen_thread);
-  GNUNET_pthread_join(room->listen_thread, &unused);
+  GNUNET_thread_stop_sleep(chat_room->listen_thread);
+  GNUNET_thread_join(chat_room->listen_thread, &unused);
   GNUNET_free (chat_room->nickname);
   GNUNET_free (chat_room->memberInfo);
   GNUNET_client_connection_destroy (chat_room->sock);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]