cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: FTP upload issue

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Thu, 3 Nov 2016 07:45:32 +0100

On Wed, Nov 02, 2016 at 11:15:30AM -0700, Carlos Rimola wrote:
> Is there a way for me to know when it is time to send the data? That is, how do
> I know when libcurl has established the control and data socket connections,
> logged in and executed my FTP commands (slist).

libcurl provides a convenient way to tell when this state is reached—it calls
the read data callback. You could also parse the debug log strings to figure it
out, but that would be more brittle.

> As I understand it calling curl_multi-perform, my read_callback copies the data
> to the ptr (first) parameter to callback and return the amount of data copied.
> This all works fine in my code after the control and data sockets are setup (as
> shown by using the option CURLOPT_VERBOSE).
>
> It seems like I am calling curl_multi_perform prematurely but how do I know
> when libcurl is ready to send and can call curl_multi_perform knowing that my
> read_callback will be invoked?

You can't call curl_multi_perform "prematurely". I think you're
misunderstanding the use of curl_multi_perform. The application doesn't need to
care what happens when it is called, just that it is called, and is called
repeatedly (in a loop) until it doesn't need to be called any more. At some
point in the middle of that process, libcurl will take the application's data
and send it, but the exact point is pretty irrelevant.

> The "condition" refers to calling curl_multi_perform and my read_callback not
> being invoked, therefore - no data sent. 

That's perfectly normal. If it's not time to send the data yet,
curl_multi_perform will not trigger sending that data.

> I understand this and I don't need to know when libcurl is in its transfer
> state machine. I just need to know when it's safe to call curl_multi_perform
> knowing that libcurl is ready and the curl_multi_perform call will be sure to
> trigger the invocation to my read_callback so that it can provide the data and
> length to transfer.

Why do you need to know this? There's no standard way I can think of to get
this information. In the case of FTP, you could probably accomplish this by
parsing the debug logs or using some heuristics based on CURLINFO_LASTSOCKET
or CURLOPT_OPENSOCKETFUNCTION, but this is a hack and not how libcurl is
designed to be used.

>>> Dan
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-11-03