Re: WWW::Curl help
by Anonymous Monk on Aug 22, 2008 at 10:26 UTC
|
| [reply] |
|
|
Easy there, no need to be so hurtfull! :P hehe
I understand what libcurl is and what WWW::Curl is. I am also reading the tutorial you are refering to and have got something running, although not with the desired results. I ll read and see what a Callback function is in computer science. Thank you for your reply :)
Finally, are you saying your services are up for hire? :)
| [reply] |
|
|
The best phrase I can think of to describe what a callback is is this well known snippet ;-) :
Don't call us, we call you
A callback is a subroutine that isn't called directly by some code (the caller), but given as parameter to some other code/subroutine/process (the called), which eventually calls (back) that subroutine.
Look at sort() in perl. The comparision function you can give to sort is essentially a callback. You never call it yourself, sort calls it when it needs to. Callbacks are most commonly used in window managers where the callbacks react to asynchronous events like key presses and mouse clicks.
| [reply] |
|
|
|
|
:) Here's my adaptation minus the callback, untested
#!/usr/bin/perl -T --
use strict;
use warnings;
use WWW::Curl 4.05; # otherwise no WRITEDATA, other bugs ...
use WWW::Curl::Easy;
{
my $curl = WWW::Curl::Easy->new();
my $ftpfile = 'README.curl';
if( $curl ){
$curl->setopt(CURLOPT_URL,
"ftp://ftp.sunet.se/pub/www/utilities/curl/README.curl");
$curl->setopt(CURLOPT_WRITEDATA,$ftpfile);
$curl->setopt(CURLOPT_VERBOSE,1);
my $retcode = $curl->perform();
if ($retcode != 0) {
warn "An error happened: ", $curl->strerror($retcode), " (
+$retcode)\n";
warn "errbuf: ", $curl->errbuf;
}
# redundant since $curl goes out of scope
$curl->curl_easy_cleanup;
} else {
warn "DARN, , WWW::Curl::Easy->new() failed";
}
}
__END__
# ppm install WWW::Curl
# ppm install http://theoryx5.uwinnipeg.ca/ppms/WWW-Curl.ppd
# http://curl.haxx.se/libcurl/c/
# http://curl.haxx.se/libcurl/c/libcurl-tutorial.html
# http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
# http://curl.haxx.se/libcurl/c/curl_easy_perform.html
# http://curl.haxx.se/lxr/source/docs/examples/ftpget.c
# http://cool.haxx.se/cvs.cgi/*checkout*/curl/docs/examples/ftpget.c?r
+ev=1.8&content-type=text/plain
# http://cool.haxx.se/cvs.cgi/*checkout*/curl/docs/examples/ftpget.c?r
+ev=HEAD&content-type=text/plain
# http://search.cpan.org/src/SZBALINT/WWW-Curl-4.05/t/01basic.t
| [reply] [d/l] |
Re: WWW::Curl help
by Illuminatus (Curate) on Aug 22, 2008 at 13:30 UTC
|
Your post is woefully lacking in details. You say you want it to be 'fast', but what makes you think Curl has some performance advantage over other methods?
1) Are the 'numerous' files you need to tranfer on lots of different systems, or just one? If only one, then you will not gain much performance with concurrency.
2) Do you know the sizes of the files at the point when you want to do the tranfer? And the bandwidth to each system? If you have both, you could calculate an optimal N groupings of files. There are numerous CPAN ftp modules. You could either create multiple threads, or spawn multiple processes to handle this N groupings. | [reply] |
|
|
Hey there,
firstly thank you to everyone for replying. I went with libcurl for its support of sftp via libssh2 as well as other protocols i want to use. The assumptions for speed etc were made based on other postings here and on other pages of people that have used it as well as other CPAN modules. I did not have time to run a benchmark test though. The wikipedia callback pages explains callbacks rather well and they make sense so thank you to the first anonymous monk for directing me there.
I have another question about using libcurl with sftp, anyone have any experience with it, i don't seem to be able to pass a passphrase with success and wondering what attribute is the right attribute to set for the passphrase and how i should set it. It seems to want me to pass it as a pointer to the password, should i assume it wants me to pass a reference to $password ? Any ideas?
| [reply] |
|
|
I have another question about using libcurl with sftp, anyone have any experience with it, i don't seem to be able to pass a passphrase with success and wondering what attribute is the right attribute to set for the passphrase and how i should set it.
What does the manual say? Thats right bittis, stop wondering and read the fine manual :)
It seems to want me to pass it as a pointer to the password, should i assume it wants me to pass a reference to $password ? Any ideas?
CURLOPT_URL (and all others) also wants a pointer to a zero terminated string (char* imapointer) , and you don't pass a reference there, so no, don't assume that.
| [reply] |
|
|
|
|
Re: WWW::Curl help
by Perlbotics (Archbishop) on Aug 22, 2008 at 18:52 UTC
|
Does anyone understand what callback functions do?
It is sometimes called
inversion of control, meaning that you provide some functions that are called back
by others in case a certain event occurs, e.g. data available, timeout, exception, mouse-button pressed, and the like.
| [reply] |