cURL / Mailing Lists / curl-users / Single Mail

curl-users

libcurl and REALbasic... terrible mix (probably REALbasic's fault though)

From: Theodore H.Smith <delete_at_elfdata.com>
Date: Thu, 27 Nov 2008 00:23:37 +0000

Hi everyone,

I've been trying to get libcurl working with REALbasic, for Mac and PC.

It's really been a struggle. I've been struggling with this for 2
weeks now. It should be simple. But it hasn't been.

I've been trying all sorts of different approaches to figure out what
the problem is, when the problem occurs, trying all sorts of different
approaches, and getting knocked back with all sorts of different
problems each time.

First I tried using curl.exe for PC and curl for Mac. Worked great on
the Mac. But failed on the PC due to crappy shell interaction, the
shell itself wouldn't send the data sometimes. This may be REALbasic's
fault or maybe Windows's fault, but... it worked on the Mac and not on
PC.

So I tried using libcurl as a library. Better success, until I tried
making multiple connections. Then I found form data was being lost. I
thought it was a fault in libcurl, because it only happened when I
turned on NTLM rather than all the time.

So I tried using libcurl in plain old C. That worked better. In fact,
that worked perfectly. But that give me a bigger problem. Why would it
work in a pure C environment, and fail in REALbasic? I spent a long
time trying to replicate my RB code in C, but eventually found
everything just worked. I realised the flaw can't be in libcurl then!

So I tried replicating the C environment in RB. From this, I realised
that RB was causing curl lose data because of thread interaction.
Which is odd, because REALbasic people keep on saying that REALbasic
is SINGLE THREADED. And I only get problems when trying to use
multiple connections at once.

I tried multiple threads in C, using pthreads. Worked like a charm.
But doing the same thing in REALbasic failed. REALbasic can't do
pthreads inside of RB, it crashes if you pthread stuff. I tried making
a plugin (library written in C++ that works in REALbasic) to do
pthreads, that didn't crash, but I was back to where I was before.
libcurl was still not sending form-data when sending making multiple
connections and using NTLM. So that plugin didn't help.

I tried using plain old RB threads, which aren't pthreads, god knows
what they are internally (cooperative threads apparantly but even
then...). No help either. That just kills connections somehow.

So... after all that, I am faced with two choices.

1) Accept that REALbasic's poor threading model, kills off libcurl's
ability to make multiple connections no matter how good your
intentions are at respecting libcurl's thread design. And just use
libcurl one connection at a time. Makes for a worse UI experience...
but there you go.

2) Use some kind of external tool, NOT a shell tool because of my
terrible experience with Win32 shells and REALbasic. I think an tool
that uses IPC sockets (interprocess communication) that I can shuffle
data across between RB and the IPC tool, and have that one do the
pthreaded libcurl stuff!

I simply cannot do number 2). I don't have the time or patience after
all the previous disasters. There's only so many failiures a guy can
take. In fact if I was wiser, I probably would have given up long ago.

I don't suppose anyone has wrapped libcurl in some kind of IPC
socketed tool, already? :D Sort of like curl.exe only that it sends
and gets data over IPC sockets to the app instead of over the shell.

Actually, on second thoughts. Forget that. I think I'm trying too
hard. I need to just accept that REALbasic's thread model is terrible.
I think this is wiser.

--
http://elfdata.com/plugin/
"String processing, done right"
-------------------------------------------------------------------
List admin: http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-users
FAQ:        http://curl.haxx.se/docs/faq.html
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2008-11-27