cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to pause ftp upload?

From: m. allan noah <kitno455_at_gmail.com>
Date: Tue, 26 May 2009 21:31:26 -0400

On Tue, May 26, 2009 at 5:45 PM, m. allan noah <kitno455_at_gmail.com> wrote:
> On Tue, May 26, 2009 at 5:28 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:
>> On Tue, 26 May 2009, m. allan noah wrote:
>>
>>> I'm trying to upload data to two ftp:// urls concurrently using the
>>> easy interface.
>>
>> In two different threads then I presume?
>
> ah, no. I was hoping that pausing each transfer would let me work on the other.
>
>>> The data for both files comes interlaced from a single source, and is
>>> produced more slowly than libcurl calls the read callback. The computer does
>>> not have enough memory to buffer all of the data prior to transmit, and
>>> there is no disk to spool it to temporarily.
>>
>> And just having the callbacks wait until they have some data to return is
>> not fine enough?
>>
>>> What i would like to do is to feed data to each handle as I get it, and
>>> tell the handle to send that data.
>>
>> That's not very easily done with the easy interface. I would claim the multi
>> interface fits that way of thinking better. And if you used multi, you could
>> even do this without using threads.
>
> I have already started a multi interface version, and it does work
> better, but it's async nature means some changes to my code, since I
> was hoping to fill and then drain a small buffer serially.
>
>>> I think I can do it with repeated connections and appending, but the data
>>> does not come slowly enough to warrant that kind of overhead. I tried using
>>> CURL_READFUNC_PAUSE, but that seems to just hang the program.
>>
>> Uh? It passes the reading, so that will of course in a sense "hang" the
>> program. But you must then unpause it again when you have data you want to
>> send. Did you?
>
> If you are using a single threaded program, there is nothing to un-pause you?

Well, I guess what I was looking for was an interface like zlib, where
you provide a buffer, and the library drains it at your request, and
then we refill the buffer. But it seems like I cannot do that with a
single-threaded program and the easy interface, since
curl_easy_perform wants to complete the entire job. Though, it would
seem that multi has the ability to step each of its easy handles the
way I want? Is my understanding correct?

I switched to multi interface, and return CURL_READFUNC_PAUSE from my
callback, and call curl_easy_pause directly on the easy handle when I
have some more data to send. Does that seem safe?

Semantically, I dont want to 'pause' exactly, i just want a way to
return 'no data now', without curl closing the connection. Perhaps
something like CURL_READFUNC_RETRY (-2)?

Oh- and thanks loads for libcurl, its a real life-saver. (rock-box
ain't bad either :)

allan

-- 
"The truth is an offense, but not a sin"
Received on 2009-05-27