cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Read and write on the same cURL handle

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 27 Jun 2014 04:20:30 +0200 (CEST)

On Thu, 26 Jun 2014, Richard W.M. Jones wrote:

>> A curl handle can be re-used for any amount of requests so a read
>> (download) request can very well be followed by a write (upload) request.
>> But they are then two subsequent requests and you can't just switch at will
>> at a random point in time.
>
> Sorry, I'm confused by this paragraph. The sentences seem contradictory.
> I can or I cannot switch between download and upload on the same handle?

Sorry, that was a bit weirdly put by me. Let me try again:

A handle can be used for uploading or downloading and some requests even do
both. A handle can be re-used for any number of subsequent requests.

But a handle that is in use and with which you've already initiated a transfer
in either direction, would need some special care in case you'd suddenly like
to change it to a transfer in the other direction.

> pread (offset=0, count=512)
> pread (offset=512, count=1024)
> pwrite (offset=0, count=512)
> pread (offset=1024, count=512)
> pwrite (offset=0, count=512)
> pwrite (offset=1024, count=512)
> pread (offset=512, count=2048)
>
> The question is, how best to turn that lot into cURL API requests?
>
> Also what actual API calls do I need to use to switch the cURL handle
> into download and upload modes (assuming this is allowed)?
>
> My initial patch used this to switch to download mode:
>
> curl_easy_setopt (h->c, CURLOPT_NOBODY, 0);
> curl_easy_setopt (h->c, CURLOPT_HTTPGET, 1);
>
> and this to switch to upload mode:
>
> curl_easy_setopt (h->c, CURLOPT_UPLOAD, 1);
>
> Is that correct?

That seems correct. You can even skip setting the *NOBODY option there since
*HTTPGET implies that.

Speaking in HTTP terms, this will alter between GET requests and PUT requests.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2014-06-27