[vlc-commits] oldrc: fix reading from standard input

Rémi Denis-Courmont git at videolan.org
Thu Jun 4 22:36:16 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jun  4 23:35:40 2015 +0300| [8d0dde2823c8b9ab2970e2bc4d9b336de3a77489] | committer: Rémi Denis-Courmont

oldrc: fix reading from standard input

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

 modules/control/oldrc.c |   46 ++++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/modules/control/oldrc.c b/modules/control/oldrc.c
index ee131de..b547d1b 100644
--- a/modules/control/oldrc.c
+++ b/modules/control/oldrc.c
@@ -1863,34 +1863,36 @@ bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
     }
 #endif
 
-    while( *pi_size < MAX_LINE_LENGTH &&
-           (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
-                       0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket,
-                  (uint8_t *)p_buffer + *pi_size, 1, false ) ) > 0 )
-    {
-        if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
-            break;
 
-        (*pi_size)++;
-    }
-
-    /* Connection closed */
-    if( i_read <= 0 )
+    while( *pi_size < MAX_LINE_LENGTH )
     {
-        if( p_intf->p_sys->i_socket != -1 )
-        {
-            net_Close( p_intf->p_sys->i_socket );
-            p_intf->p_sys->i_socket = -1;
+        if( p_intf->p_sys->i_socket == -1 )
+        {
+            if( read( 0/*STDIN_FILENO*/, p_buffer + *pi_size, 1 ) <= 0)
+            {   /* Standard input closed: exit */
+                vlc_value_t empty;
+                Quit( VLC_OBJECT(p_intf), NULL, empty, empty, NULL );
+                p_buffer[*pi_size] = 0;
+                return true;
+            }
         }
         else
-        {
-            /* Standard input closed: exit */
-            vlc_value_t empty;
-            Quit( VLC_OBJECT(p_intf), NULL, empty, empty, NULL );
+        {   /* Connection closed */
+            i_read = net_Read( p_intf, p_intf->p_sys->i_socket,
+                               p_buffer + *pi_size, 1, false );
+            if( i_read <= 0 )
+            {
+                net_Close( p_intf->p_sys->i_socket );
+                p_intf->p_sys->i_socket = -1;
+                p_buffer[*pi_size] = 0;
+                return true;
+            }
         }
 
-        p_buffer[ *pi_size ] = 0;
-        return true;
+        if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
+            break;
+
+        (*pi_size)++;
     }
 
     if( *pi_size == MAX_LINE_LENGTH ||



More information about the vlc-commits mailing list