[vlc-commits] sftp: implement Read() rather than Block(), simplify
Rémi Denis-Courmont
git at videolan.org
Mon Aug 31 22:03:28 CEST 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Aug 31 22:51:44 2015 +0300| [8ede15478214ccabf10c7563194c27ea1175ce5c] | committer: Rémi Denis-Courmont
sftp: implement Read() rather than Block(), simplify
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8ede15478214ccabf10c7563194c27ea1175ce5c
---
modules/access/sftp.c | 38 +++++++++++---------------------------
1 file changed, 11 insertions(+), 27 deletions(-)
diff --git a/modules/access/sftp.c b/modules/access/sftp.c
index 2bd56d5..df917db 100644
--- a/modules/access/sftp.c
+++ b/modules/access/sftp.c
@@ -79,7 +79,7 @@ vlc_module_end ()
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-static block_t* Block( access_t * );
+static ssize_t Read( access_t *, void *, size_t );
static int Seek( access_t *, uint64_t );
static int Control( access_t *, int, va_list );
@@ -288,7 +288,7 @@ static int Open( vlc_object_t* p_this )
p_sys->file = libssh2_sftp_open( p_sys->sftp_session, psz_path, LIBSSH2_FXF_READ, 0 );
p_sys->filesize = attributes.filesize;
- ACCESS_SET_CALLBACKS( NULL, Block, Control, Seek );
+ ACCESS_SET_CALLBACKS( Read, NULL, Control, Seek );
}
else
{
@@ -357,41 +357,25 @@ static void Close( vlc_object_t* p_this )
}
-static block_t* Block( access_t* p_access )
+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 NULL;
- /* Allocate the buffer we need */
- size_t i_len = __MIN( p_sys->i_read_size,
- p_sys->filesize - p_access->info.i_pos );
- block_t* p_block = block_Alloc( i_len );
- if( !p_block )
- return NULL;
-
- /* Read the specified size */
- ssize_t i_ret = libssh2_sftp_read( p_access->p_sys->file, (char*)p_block->p_buffer, i_len );
-
- if( i_ret < 0 )
+ ssize_t val = libssh2_sftp_read( p_sys->file, buf, len );
+ if( val < 0 )
{
- block_Release( p_block );
+ p_access->info.b_eof = true;
msg_Err( p_access, "read failed" );
- return NULL;
+ return 0;
}
- else if( i_ret == 0 )
- {
+ else if( val == 0 )
p_access->info.b_eof = true;
- block_Release( p_block );
- return NULL;
- }
- else
- {
- p_block->i_buffer = i_ret;
- p_access->info.i_pos += i_ret;
- return p_block;
- }
+
+ p_access->info.i_pos += val;
+ return val;
}
More information about the vlc-commits
mailing list