On Thu, 20 Jan 2011, zl liu wrote:

Thank you for reminding me! I read the new code of libssh2-1.2.8-20110118, I am excited, But i have one question about the following note: *- On following call, the 'buffer' is expected to have advanced TOTAL ** bytes.* I can not send another buffer before the current buffer is totally sent off, even i know it has been copied by sftp_write(). Can i reuse the buffer which has been copied by sftp_write()? if not why have such a restriction. thank you!

Sorry, the description was a bit off and I've now updated it to be more on par with what the code actually does.

What it tried to explain is that a typical app does this:

  retcode = sftp_write(buffer, 10000); /* call A */

assuming a part of the buffer was sent off, 'retcode' is positive number and the app will call the function again with buffer advanced. Perhaps like this:

  buffer += retcode;
  retcode = sftp_write(buffer, 10000 - retcode); /* call B */

In this case, libssh2 has already copied 10000 bytes in call A, so when the app does call B the lib will skip the amount of bytes from the start of the buffer that it already has copied. In this exact example, libssh2 won't copy a single byte in call B as it doesn't provide any new data.

This also illustrates a performance bottle-neck because if you loop like this until the buffer is completely sent off, you don't allow libssh2 to pre-send data beyond this single buffer. The sliding example code shows a way to make the app provide a full buffer as much as possible which allows libssh2 to better "keep the pipe full".

--

 / daniel.haxx.se
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Reply via email to