vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Thu Jun 4 23:35:40 2015 +0300| [5885e88a769ae61c80f7176904b2a43e94b8de4a] | committer: Rémi Denis-Courmont
oldrc: fix reading from standard input > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5885e88a769ae61c80f7176904b2a43e94b8de4a --- modules/control/oldrc.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/modules/control/oldrc.c b/modules/control/oldrc.c index ee131de..1afbd78 100644 --- a/modules/control/oldrc.c +++ b/modules/control/oldrc.c @@ -1851,8 +1851,6 @@ static bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size ) bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size ) { - int i_read = 0; - #ifdef _WIN32 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet ) return ReadWin32( p_intf, p_buffer, pi_size ); @@ -1863,34 +1861,35 @@ 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 */ + if( net_Read( p_intf, p_intf->p_sys->i_socket, p_buffer + *pi_size, + 1, false ) <= 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 || _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
