www.libssh2.org | Daily snapshots | Mailing list archive | Docs | Examples | github

Archive Index This month's Index

Subject: Re: libssh2-1.2.8-20110111 issue

Re: libssh2-1.2.8-20110111 issue

From: zl liu <xieepp_at_gmail.com>
Date: Fri, 21 Jan 2011 09:37:57 +0800

2011/1/20 Daniel Stenberg <daniel_at_haxx.se>

> 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".
>
> If i change the code in sftp_write_sliding.c like this:

        if(memuse - rc) {
          /* make room for more data at the end of the buffer */
          /* the mem has been copied by sftp_write() in the previous call,
just move the count not really memory*/
          // memmove(&mem[0], &mem[rc], memuse - rc);
          memuse -= rc;
        }
        else
          /* 'mem' was consumed fully */
          memuse = 0;

        does it work normally? even like this, i think the memory from 0
to memuse has been waste.

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

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2011-01-21

the libssh2 team