[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sftp_async_* and file offset


On Thursday 13 August 2015 13:00:42 Tilo Eckert wrote:
> Hi,
> 
> when reading files through the asynchronous SFTP methods, I see that you
> update the file offset in sftp_async_read_begin(). Is there any specific
> reason why you do it here and not in sftp_async_read()?
> 
> Due to this behavior, I am unable to use sftp_tell() in my read-ahead
> implementation. Since I request multiple buffers in advance, the offset
> stored in the sftp_file handle is always in the future as the requested
> buffers have not been read, yet. Also, the offset may be set to values
> beyond the end of the file.
> 
> Another thing that bugs me are the following lines in sftp_async_read():
>   /* Update the offset with the correct value */
>   file->offset = file->offset - (size - len);
> 
> This causes the difference of the size of the buffer passed as parameter
> and the received data's length to be subtracted from offset. I guess
> this is to fix the offset when reaching EOF? The problem is that the
> value of file->offset will become invalid if a buffer is passed to the
> function that is larger than the number of bytes requested (which is
> fine according to the docs). It will cause the offset to illegally
> decrease. When the buffer is more than twice the size of the original
> request, the offset value would even go backwards. So, I guess this is a
> bug.
> 
> My suggested fix is to replace this line by moving the offset+=len line
> from sftp_async_read_begin().

Tilo,

the sftp_async_* functions are a hack. This codes really needs to be 
rewritten. sftp should use the callback API and be async by default. We need 
to get rid of sftp_async_* functions.

It is on Aris his todo list but he doesn't have time for it. If you're 
interested to work on this, Aris can tell you what needs to be done. It 
shouldn't be too hard to implement ...


	-- andreas

-- 
Andreas Schneider                   GPG-ID: CC014E3D
www.cryptomilk.org                asn@xxxxxxxxxxxxxx


References:
sftp_async_* and file offsetTilo Eckert <tilo.eckert@xxxxxxx>
Archive administrator: postmaster@lists.cynapses.org