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

Archive Index This month's Index

Subject: Re: [SFTP] Is there a way to determine the maximum buffer len when reading.

Re: [SFTP] Is there a way to determine the maximum buffer len when reading.

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 23 Aug 2013 11:58:56 +0200 (CEST)

On Fri, 23 Aug 2013, Velichko Yuriy wrote:

> I tried to read data from file using function libssh2_sftp_read(3).
> The buffer_maxlen = 8000
> But the "Number of bytes actually populated into buffer" (the return value
> of function) is always 2000.

I don't think it is always 2000.

When you ask for data with this function from libssh2, the function will split
up the request into multiple requests for several pieces and as soon as the
first data has arrived it returns that. The subsequent data pieces can then be
returned in the next call to this function, should they have arrived then.

This is an optimization to help bite off the worst problems with the
request/response nature of the SFTP protocol and its small packets. You get
the first data available faster, and chances are that when you subsequently
ask for more data it might already have been received.

You should still ask for as much data as possible at once so that libssh2 will
send out requests for all of it, and thus make you get data faster. This is
especially important if you're on high latency connections.

  / daniel.haxx.se
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2013-08-23

the libssh2 team