Commit de280a5d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

access: set EOF implicitly when read returns 0

parent 616a010c
......@@ -183,9 +183,13 @@ static inline bool vlc_access_Eof(const access_t *access)
*/
static inline ssize_t vlc_access_Read(access_t *access, void *buf, size_t len)
{
if (access->pf_read == NULL)
return -1;
return access->pf_read(access, buf, len);
int ret = -1;
if (access->pf_read != NULL)
ret = access->pf_read(access, buf, len);
if (len > 0 && ret == 0)
access->info.b_eof = true;
return ret;
}
/**
......
......@@ -58,9 +58,6 @@ static ssize_t Read(access_t *p_access, void *p_data, size_t i_size)
if (i_read < 0)
i_read = 0;
if (i_size > 0 && i_read <= 0)
p_access->info.b_eof = true;
return i_read;
}
......
......@@ -116,8 +116,7 @@ static ssize_t Read(access_t *access, void *buffer, size_t size)
access_sys_t *sys = access->p_sys;
input_attachment_t *a = sys->attachment;
access->info.b_eof = sys->offset >= (uint64_t)a->i_data;
if (access->info.b_eof)
if (sys->offset >= (uint64_t)a->i_data)
return 0;
const size_t copy = __MIN(size, a->i_data - sys->offset);
......
......@@ -306,10 +306,8 @@ void OutCloseAvio(vlc_object_t *object)
static ssize_t Read(access_t *access, void *data, size_t size)
{
int r = avio_read(access->p_sys->context, data, size);
if (r <= 0) {
access->info.b_eof = true;
if (r < 0)
r = 0;
}
return r;
}
......
......@@ -63,15 +63,11 @@ static access_t *GetAccess(access_t *access)
}
if (sys->next == NULL)
{
error:
access->info.b_eof = true;
return NULL;
}
a = vlc_access_NewMRL(VLC_OBJECT(access), sys->next->mrl);
if (a == NULL)
goto error;
return NULL;
sys->access = a;
sys->next = sys->next->next;
......@@ -88,10 +84,7 @@ static ssize_t Read(access_t *access, void *buf, size_t len)
* change. We need to check it. For instance, a path could point to a
* regular file during Open() yet point to a directory here and now. */
if (unlikely(a->pf_read == NULL))
{
access->info.b_eof = true;
return 0;
}
return vlc_access_Read(a, buf, len);
}
......
......@@ -461,8 +461,6 @@ static ssize_t Read( access_t *p_access, void *p_buffer, size_t i_len )
access_sys_t *p_sys = p_access->p_sys;
int i_read;
if( p_access->info.b_eof ) return 0;
i_read = smb_fread( p_sys->p_session, p_sys->i_fd, p_buffer, i_len );
if( i_read < 0 )
{
......@@ -470,8 +468,6 @@ static ssize_t Read( access_t *p_access, void *p_buffer, size_t i_len )
return -1;
}
if( i_read == 0 ) p_access->info.b_eof = true;
return i_read;
}
......
......@@ -295,7 +295,6 @@ static ssize_t Read (access_t *p_access, void *p_buffer, size_t i_len)
val = 0;
}
p_access->info.b_eof = !val;
return val;
}
......
......@@ -852,22 +852,17 @@ static ssize_t Read( access_t *p_access, void *p_buffer, size_t i_len )
assert( p_sys->data.fd != -1 );
assert( !p_sys->out );
if( p_access->info.b_eof )
return 0;
if( p_sys->data.p_tls != NULL )
i_read = vlc_tls_Read( p_sys->data.p_tls, p_buffer, i_len, false );
else
i_read = vlc_recv_i11e( p_sys->data.fd, p_buffer, i_len, 0 );
if( i_read > 0 )
if( i_read >= 0 )
p_sys->offset += i_read;
else if( i_read == 0 )
p_access->info.b_eof = true;
else if( errno != EINTR && errno != EAGAIN )
{
msg_Err( p_access, "receive error: %s", vlc_strerror_c(errno) );
p_access->info.b_eof = true;
i_read = 0;
}
return i_read;
......
......@@ -518,10 +518,10 @@ static ssize_t Read( access_t *p_access, void *p_buffer, size_t i_len )
int i_read;
if( p_sys->fd == -1 )
goto fatal;
return 0;
if( i_len == 0 )
goto fatal;
return 0;
if( p_sys->i_icy_meta > 0 && p_sys->offset - p_sys->i_icy_offset > 0 )
{
......@@ -531,14 +531,14 @@ static ssize_t Read( access_t *p_access, void *p_buffer, size_t i_len )
if( i_next == p_sys->i_icy_meta )
{
if( ReadICYMeta( p_access ) )
goto fatal;
return 0;
}
if( i_len > i_next )
i_len = i_next;
}
if( ReadData( p_access, &i_read, p_buffer, i_len ) )
goto fatal;
return 0;
if( i_read < 0 )
return -1; /* EINTR / EAGAIN */
......@@ -554,17 +554,13 @@ static ssize_t Read( access_t *p_access, void *p_buffer, size_t i_len )
else
return -1;
}
goto fatal;
return 0;
}
assert( i_read >= 0 );
p_sys->offset += i_read;
return i_read;
fatal:
p_access->info.b_eof = true;
return 0;
}
static int ReadICYMeta( access_t *p_access )
......@@ -793,7 +789,6 @@ static int Connect( access_t *p_access, uint64_t i_tell )
p_sys->b_has_size = false;
p_sys->offset = i_tell;
p_sys->size = 0;
p_access->info.b_eof = false;
/* Open connection */
assert( p_sys->fd == -1 ); /* No open sockets (leaking fds is BAD) */
......
......@@ -48,9 +48,6 @@ static ssize_t Read(access_t *access, void *buf, size_t len)
val = 0;
}
if (val <= 0)
access->info.b_eof = true;
return val;
}
......
......@@ -195,12 +195,9 @@ static ssize_t Read( access_t *p_access, void *p_buffer, size_t i_len )
vlc_dialog_display_error( p_access, _( "File reading failed" ),
_( "VLC could not read the file: %s" ),
vlc_strerror(errno) );
p_access->info.b_eof = true;
return 0;
}
}
else if( i_ret == 0 )
p_access->info.b_eof = true;
return i_ret;
}
......
......@@ -94,8 +94,6 @@ static ssize_t Read(access_t *access, void *data, size_t size)
Seek(access, sys->position))
break;
}
if (size > 0 && total <= 0)
access->info.b_eof = true;
return total;
}
......
......@@ -88,10 +88,7 @@ static ssize_t Read (access_t *access, void *buf, size_t len)
access_sys_t *sys = access->p_sys;
if (sys->offset >= sys->length)
{
access->info.b_eof = true;
return 0;
}
if (len > sys->length - sys->offset)
len = sys->length - sys->offset;
......
......@@ -388,18 +388,12 @@ static ssize_t Read( access_t *p_access, void *buf, size_t len )
{
access_sys_t *p_sys = p_access->p_sys;
if( p_access->info.b_eof )
return 0;
ssize_t val = libssh2_sftp_read( p_sys->file, buf, len );
if( val < 0 )
{
p_access->info.b_eof = true;
msg_Err( p_access, "read failed" );
return 0;
}
else if( val == 0 )
p_access->info.b_eof = true;
return val;
}
......
......@@ -323,18 +323,13 @@ static ssize_t Read( access_t *p_access, void *p_buffer, size_t i_len )
access_sys_t *p_sys = p_access->p_sys;
int i_read;
if( p_access->info.b_eof ) return 0;
i_read = smbc_read( p_sys->i_smb, p_buffer, i_len );
if( i_read < 0 )
{
msg_Err( p_access, "read failed (%s)", vlc_strerror_c(errno) );
p_access->info.b_eof = true;
return -1;
i_read = 0;
}
if( i_read == 0 ) p_access->info.b_eof = true;
return i_read;
}
......
......@@ -136,18 +136,14 @@ static ssize_t Read( access_t *p_access, void *p_buffer, size_t i_len )
access_sys_t *p_sys = p_access->p_sys;
int i_read;
if( p_access->info.b_eof )
return 0;
i_read = vlc_recv_i11e( p_sys->fd, p_buffer, i_len, 0 );
if( i_read > 0 )
;
else if( i_read == 0 )
p_access->info.b_eof = true;
else if( errno != EINTR && errno != EAGAIN )
if( i_read < 0 )
{
msg_Err( p_access, "receive error: %s", vlc_strerror_c(errno) );
p_access->info.b_eof = true;
if( errno != EINTR && errno != EAGAIN )
{
msg_Err( p_access, "receive error: %s", vlc_strerror_c(errno) );
i_read = 0;
}
}
return i_read;
......
......@@ -342,11 +342,8 @@ static ssize_t Read( access_t *p_access, void *p_buffer, size_t i_len )
access_sys_t *p_sys = p_access->p_sys;
if( p_sys->fd == -1 )
{
/* no more data */
p_access->info.b_eof = true;
return 0;
}
ssize_t i_ret = read( p_sys->fd, p_buffer, i_len );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment