vlc/vlc-3.0 | branch: master | Marvin Scholz <[email protected]> | Sun May 6 01:29:22 2018 +0200| [c7e395b7234e5b787f7e149f203991695a2269f6] | committer: Jean-Baptiste Kempf
access: old http: Do not read all requested data The old http module Read function would try to read the full amount of requested data, which would result in a long loading time for some streams. Instead return early with the actual amount of data read. Signed-off-by: Rémi Denis-Courmont <[email protected]> (cherry picked from commit 84bcad6bc3481fa9399682ec291dcba16cc46c88) Signed-off-by: Jean-Baptiste Kempf <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=c7e395b7234e5b787f7e149f203991695a2269f6 --- modules/access/http.c | 73 +++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/modules/access/http.c b/modules/access/http.c index f5b4eacbd1..1d58a034b8 100644 --- a/modules/access/http.c +++ b/modules/access/http.c @@ -408,61 +408,54 @@ static int ReadICYMeta( stream_t *p_access ); static ssize_t Read( stream_t *p_access, void *p_buffer, size_t i_len ) { access_sys_t *p_sys = p_access->p_sys; - int i_total_read = 0; - int i_remain_toread = i_len; if( p_sys->fd == -1 ) return 0; - while( i_remain_toread > 0 ) - { - int i_chunk = i_remain_toread; + int i_chunk = i_len; - if( p_sys->i_icy_meta > 0 ) - { - if( UINT64_MAX - i_chunk < p_sys->offset ) - i_chunk = i_remain_toread = UINT64_MAX - p_sys->offset; + if( p_sys->i_icy_meta > 0 ) + { + if( UINT64_MAX - i_chunk < p_sys->offset ) + i_chunk = UINT64_MAX - p_sys->offset; - if( p_sys->offset + i_chunk > p_sys->i_icy_offset ) - i_chunk = p_sys->i_icy_offset - p_sys->offset; - } + if( p_sys->offset + i_chunk > p_sys->i_icy_offset ) + i_chunk = p_sys->i_icy_offset - p_sys->offset; + } - int i_read = 0; - if( ReadData( p_access, &i_read, &((uint8_t*)p_buffer)[i_total_read], i_chunk ) ) - return 0; + int i_read = 0; + if( ReadData( p_access, &i_read, (uint8_t*)p_buffer, i_chunk ) ) + return 0; - if( i_read < 0 ) - return -1; /* EINTR / EAGAIN */ + if( i_read < 0 ) + return -1; /* EINTR / EAGAIN */ - if( i_read == 0 ) + if( i_read == 0 ) + { + Disconnect( p_access ); + if( p_sys->b_reconnect ) { - Disconnect( p_access ); - if( p_sys->b_reconnect ) - { - msg_Dbg( p_access, "got disconnected, trying to reconnect" ); - if( Connect( p_access ) ) - msg_Dbg( p_access, "reconnection failed" ); - else - return -1; - } - return 0; + msg_Dbg( p_access, "got disconnected, trying to reconnect" ); + if( Connect( p_access ) ) + msg_Dbg( p_access, "reconnection failed" ); + else + return -1; } + return 0; + } - assert( i_read >= 0 ); - p_sys->offset += i_read; - i_total_read += i_read; - i_remain_toread -= i_read; + assert( i_read >= 0 ); + p_sys->offset += i_read; - if( p_sys->i_icy_meta > 0 && - p_sys->offset == p_sys->i_icy_offset ) - { - if( ReadICYMeta( p_access ) ) - return 0; - p_sys->i_icy_offset = p_sys->offset + p_sys->i_icy_meta; - } + if( p_sys->i_icy_meta > 0 && + p_sys->offset == p_sys->i_icy_offset ) + { + if( ReadICYMeta( p_access ) ) + return 0; + p_sys->i_icy_offset = p_sys->offset + p_sys->i_icy_meta; } - return i_total_read; + return i_read; } static int ReadICYMeta( stream_t *p_access ) _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
