[vlc-commits] cli: add per-client thread function

Rémi Denis-Courmont git at videolan.org
Sun Nov 29 14:55:55 CET 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov 28 21:09:56 2020 +0200| [aa00154c369853285b7cb878e7c2b119d9998a35] | committer: Rémi Denis-Courmont

cli: add per-client thread function

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=aa00154c369853285b7cb878e7c2b119d9998a35
---

 modules/control/cli/cli.c | 48 +++++++++++++++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 16 deletions(-)

diff --git a/modules/control/cli/cli.c b/modules/control/cli/cli.c
index f1cc53a9a1..d8237423e3 100644
--- a/modules/control/cli/cli.c
+++ b/modules/control/cli/cli.c
@@ -415,6 +415,35 @@ void msg_print(intf_thread_t *intf, const char *fmt, ...)
     va_end(ap);
 }
 
+static void *cli_client_thread(void *data)
+{
+    struct cli_client *cl = data;
+    intf_thread_t *intf = cl->intf;
+
+    while (cl->stream != NULL)
+    {
+        char cmd[MAX_LINE_LENGTH + 1];
+
+        if (fgets(cmd, sizeof (cmd), cl->stream) == NULL)
+            break;
+
+        int canc = vlc_savecancel();
+        if (cmd[0] != '\0')
+            cmd[strlen(cmd) - 1] = '\0'; /* remove trailing LF */
+        Process(intf, cl, cmd);
+        vlc_restorecancel(canc);
+    }
+
+    if (cl->stream == stdin)
+    {
+        int canc = vlc_savecancel();
+        libvlc_Quit(vlc_object_instance(intf));
+        vlc_restorecancel(canc);
+    }
+
+    return NULL;
+}
+
 static void *Run(void *data)
 {
     intf_thread_t *intf = data;
@@ -422,7 +451,6 @@ static void *Run(void *data)
 
     for (;;)
     {
-        char buf[MAX_LINE_LENGTH + 1];
         struct cli_client *cl = &sys->client;
 
         while (cl->stream == NULL)
@@ -449,24 +477,12 @@ static void *Run(void *data)
             vlc_restorecancel(canc);
         }
 
-        char *cmd = fgets(buf, sizeof (buf), cl->stream);
-        if (cmd != NULL)
-        {
-            int canc = vlc_savecancel();
-            if (cmd[0] != '\0')
-                cmd[strlen(cmd) - 1] = '\0'; /* remove trailing LF */
-            Process(intf, cl, cmd);
-            vlc_restorecancel(canc);
-        }
-        else if (sys->pi_socket_listen == NULL)
+        cli_client_thread(cl);
+
+        if (sys->pi_socket_listen == NULL)
             break;
-        else
-            LogOut(cl, NULL, 0, intf);
     }
 
-    int canc = vlc_savecancel();
-    libvlc_Quit(vlc_object_instance(intf));
-    vlc_restorecancel(canc);
     return NULL;
 }
 



More information about the vlc-commits mailing list