Subject: proper buffer size for libssh2_sftp_read()

proper buffer size for libssh2_sftp_read()

From: zl liu <xieepp_at_gmail.com>
Date: Wed, 15 Jun 2011 13:14:47 +0800

Hi!

I get a problem when i download a file about 20M bytes via non-blocking
mode.

the main code:
    do {
        /* loop until we fail */
        while ((rc = libssh2_sftp_read(sftp_handle, mem,
            sizeof(mem))) == LIBSSH2_ERROR_EAGAIN) {
                spin++;
                waitsocket(sock, session); /* now we wait */
        }
        if (rc > 0) {
            total += rc;
        } else {
            fprintf(stderr, "rc=%d\n", rc);
            break;
        }
    } while (1);

if the mem size if 1024 or 1024 * 10. it will success.
if the mem size is char mem[1024 * 100] or bigger, it is failed,the errno is
-9 or -25.

after enable debug trace£¬it print many error messages:
[libssh2] 6.535906 Failure Event: -7 - Unable to send transfer-window
adjustment
packet, deferring
....
[libssh2] 6.515906 Failure Event: -24 - Remote sent more data than current
windo
w allows, truncating
....

finally ,it print£º
[libssh2] 6.546907 Failure Event: -25 - SFTP packet too large
[libssh2] 6.546907 Failure Event: -25 - Error waiting for FXP_READ ACK
rc=-25
11718000 bytes in 7 seconds makes 1674000.0 bytes/sec,spin: 9
[libssh2] 6.549907 Failure Event: -7 - Unable to send FXP_CLOSE command

what is the reason£¿

another question , why not define the MACRO :LIBSSH2DEBUG in the debug mode.
when i want to enable trace£¬i must define the macro LIBSSH2DEBUG manually
and compile it again.

best regards

zlliu

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