curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder Daniel himself.

Solved: curl.exe runs fine, but same request hangs up in libcurl.dll (8.7.1-7 in Windows 10)

From: \[Quipsy\] Markus Karg via curl-library <curl-library_at_lists.haxx.se>
Date: Thu, 2 May 2024 11:39:16 +0000

Daniel,

thank you so much for your great ideas!

The option --libcurl is pretty cool (even if I did not needed it here)!

Cause: In fact, my read function was simply wrong. It was missing some bookkeeping, so it returned the same string length always, but never returned zero to stop.

Solution: For all in the same situation, here is my solution (feel free to copy it / the trick is to update the offset within the std::string between multiple invocations of the read function):

class UserData {
  public:
    const std::string& data;
    size_t offset;
    UserData(const std::string& data) : data(data), offset(0) {}
};

static size_t onSendRequestChunk(char* const ptr, const size_t size, const size_t nitems, UserData& userdata) {
  const size_t remaining = userdata.data.size() - userdata.offset;
  const size_t bytesToSend = min(remaining, size * nitems);
  memcpy(ptr, userdata.data.data() + userdata.offset, bytesToSend);
  userdata.offset += bytesToSend;
  return bytesToSend;
}

Regards
-Markus


-----Ursprüngliche Nachricht-----
Von: Daniel Stenberg <daniel_at_haxx.se>
Gesendet: Donnerstag, 2. Mai 2024 11:35
An: [Quipsy] Markus Karg via curl-library <curl-library_at_lists.haxx.se>
Cc: [Quipsy] Markus Karg <karg_at_quipsy.de>
Betreff: Re: curl.exe runs fine, but same request hangs up in libcurl.dll (8.7.1-7 in Windows 10)

On Thu, 2 May 2024, [Quipsy] Markus Karg via curl-library wrote:

> (Note that curl.exe created the content-length header on its own!)

If you use the --libcurl flag, you'll probably see that curl.exe sets some
option(s) that your application does not. Like CURLOPT_INFILESIZE.

> If needed, I can send the complete source code, just tell me! 😊

Do you set the presumed size? If not, do you return zero from the read callback at the end of data?

--

  / daniel.haxx.se
  | Commercial curl support up to 24x7 is available!
  | Private help, bug fixes, support, ports, new features
  | https://curl.se/support.html
-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2024-05-02