gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated: Avoid item duplication inside cli


From: gnunet
Subject: [libmicrohttpd] branch master updated: Avoid item duplication inside client list in the websocket example.
Date: Fri, 10 Apr 2020 19:11:05 +0200

This is an automated email from the git hooks/post-receive script.

silvioprog pushed a commit to branch master
in repository libmicrohttpd.

The following commit(s) were added to refs/heads/master by this push:
     new f4be5e01 Avoid item duplication inside client list in the websocket 
example.
f4be5e01 is described below

commit f4be5e015488659dc68dadbaca5a479e7b12d09c
Author: silvioprog <address@hidden>
AuthorDate: Fri Apr 10 14:05:57 2020 -0300

    Avoid item duplication inside client list in the websocket example.
---
 src/examples/websocket_threaded_example.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/examples/websocket_threaded_example.c 
b/src/examples/websocket_threaded_example.c
index ac4bb839..44cb3493 100644
--- a/src/examples/websocket_threaded_example.c
+++ b/src/examples/websocket_threaded_example.c
@@ -735,20 +735,20 @@ run_usock (void *cls)
       if (type == WS_OPCODE_CON_CLOSE_FRAME)
       {
         free (msg);
-        pthread_mutex_lock (&MUTEX);
-        for (i = 0; i < MAX_CLIENTS; i++)
-        {
-          if (CLIENT_SOCKS[i] == ws->sock)
-          {
-            CLIENT_SOCKS[i] = -1;
-            break;
-          }
-        }
-        pthread_mutex_unlock (&MUTEX);
         break;
       }
     }
   }
+  pthread_mutex_lock (&MUTEX);
+  for (i = 0; i < MAX_CLIENTS; i++)
+  {
+    if (CLIENT_SOCKS[i] == ws->sock)
+    {
+      CLIENT_SOCKS[i] = -1;
+      break;
+    }
+  }
+  pthread_mutex_unlock (&MUTEX);
   free (ws);
   MHD_upgrade_action (urh, MHD_UPGRADE_ACTION_CLOSE);
   return NULL;
@@ -771,14 +771,13 @@ uh_cb (void *cls, struct MHD_Connection *con, void 
*con_cls,
   (void) extra_in;       /* Unused. Silent compiler warning. */
   (void) extra_in_size;  /* Unused. Silent compiler warning. */
 
-  sock_overflow = MHD_YES;
   ws = malloc (sizeof (struct WsData));
   if (NULL == ws)
     abort ();
   memset (ws, 0, sizeof (struct WsData));
   ws->sock = sock;
   ws->urh = urh;
-
+  sock_overflow = MHD_YES;
   pthread_mutex_lock (&MUTEX);
   for (i = 0; i < MAX_CLIENTS; i++)
   {
@@ -789,13 +788,13 @@ uh_cb (void *cls, struct MHD_Connection *con, void 
*con_cls,
       break;
     }
   }
+  pthread_mutex_unlock (&MUTEX);
   if (sock_overflow)
   {
     free (ws);
     MHD_upgrade_action (urh, MHD_UPGRADE_ACTION_CLOSE);
     return;
   }
-  pthread_mutex_unlock (&MUTEX);
   if (0 != pthread_create (&pt, NULL, &run_usock, ws))
     abort ();
   /* Note that by detaching like this we make it impossible to ensure

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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