From aa00154c369853285b7cb878e7c2b119d9998a35 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sat, 28 Nov 2020 21:09:56 +0200 Subject: [PATCH] cli: add per-client thread function --- 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; } -- 2.11.4.GIT