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

sftp_async_* and file offset


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().

Regards
Tilo

Follow-Ups:
Re: sftp_async_* and file offsetAndreas Schneider <asn@xxxxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org