cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Curl::easy

From: Georg Horn <horn_at_koblenz-net.de>
Date: Mon, 19 Mar 2001 12:33:31 +0100

Hi,

fullquote because of xpost to curl mailinglist...

On Sun, Mar 18, 2001 at 12:45:48PM -0500, Jack Leitch wrote:

> I've been trying to implement calls to libcurl under Perl using your
> Curl::easy module, but I've hit a snag. I'd like to read the data from a
> remote server into memory rather than into a file. This is discussed in
> the Curl FAQ in section 5.2 for C, but I can't seem to find similar
> instructions for Perl. I've tried using IO::Scalar to tie a filehandle to
> a scalar and then using that filehandle:
>
> ...
> my $foo;
> tie *FH, 'IO::Scalar', \$foo;
> $curl = Curl::easy::curl_easy_init();
> ...
> $result =
> Curl::easy::curl_easy_setopt($curl,Curl:easy::CURLOPT_FILE,FH);
> Curl::easy::curl_easy_perform($curl);
> ...
>
> (Other curl_easy_setopt calls are omitted above.) So, this should read the
> data into $foo using the filehandle FH. However, when I execute the
> script, I get "Bad filehandle: FH at getbins.pl line 77." Do you have any
> suggestions as to why I might be getting this error? Perhaps the
> solution should be added to the Curl FAQ.

Hm, i would also like to have a function within libcurl that returns
a filedescriptor where you can read from, but due to some internal
issues in libcurl this is not so easy. (At least if you believe the
author of curl...) ;-) I can see that this is true because if you
want to read from an ssl connection for example, you have to use
special functions from the ssl-lib and cannot simply do a read from
a filedesc.

So the solution would be to use a callback function. Such a callback
is called every time libcurl wants to write data, and it can do
what it likes to do with that data, for example store it into a scalar.
Unfortunately, callback funcs are not yet implemented in the perl
module Curl::easy...

Perl hackers are welcome to implement this feature...

Bye,
Georg

PS: How does that IO:Scalar thing work?
Received on 2001-03-19