Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

test_curl works with the simple.c Perl 6 example

  • Loading branch information...
commit 66b72d93ef882313633fb05056ce37ccb358c897 1 parent 17074b9
@azawawi authored
Showing with 29 additions and 2 deletions.
  1. +29 −2 test_curl.p6
View
31 test_curl.p6
@@ -5,6 +5,33 @@ use NativeCall;
constant LIB = 'libcurl.so';
-sub curl_version() returns Str is native(LIB) { ... };
+sub curl_easy_init() returns OpaquePointer is native(LIB) { ... };
+sub curl_easy_cleanup(OpaquePointer) is native(LIB) { ... };
+sub curl_easy_setopt(OpaquePointer, int, Str) is native(LIB) { ... };
+sub curl_easy_perform(OpaquePointer) returns int is native(LIB) { ... };
+sub curl_easy_strerror(int) returns Str is native(LIB) { ... };
-say "Your libcurl version is " ~ curl_version;
+constant CURLOPT_URL = 10002;
+constant CURLE_OK = 0;
+
+my $curl;
+my $res;
+
+$curl = curl_easy_init;
+if $curl {
+ curl_easy_setopt($curl, CURLOPT_URL, "http://example.com");
+
+ # Perform the request, res will get the return code
+ $res = curl_easy_perform($curl);
+
+ # Check for errors
+ if $res != CURLE_OK {
+ say "Error: curl_easy_perform() failed: {curl_easy_strerror($res)}\n";
+ } else {
+ say "Got a response!";
+ }
+ say "libcurl initialized!";
+
+ # always cleanup
+ curl_easy_cleanup($curl);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.