curb 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/curb.h +3 -3
- data/ext/curb_multi.c +18 -12
- data/lib/curl/multi.rb +8 -1
- data/tests/tc_curl_multi.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51f01ce3c875c6eb02061c959c0724844fd0076d3644e28aa130b87c3f7da631
|
4
|
+
data.tar.gz: 0ca3a17b17bcdfc721608f119757e908d2c57c40aaf8e9a66d119a1deec3184d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 207ac7282c2d95de745edfadef35e809d7dee0edf03eec266c536e0c080dd072df87809dbdd0a3137382a4c7a1b5c420bb32de3bd2820126c6ad6e29085d986f
|
7
|
+
data.tar.gz: e1ad940900fb2a107c52b8f28991e0cc50d409dc91a1d075d03145020a527a806578da341ed8cbf2162cb8383c64f3137ec68329911b04ce4713acb9bb7baf1b
|
data/ext/curb.h
CHANGED
@@ -28,11 +28,11 @@
|
|
28
28
|
#include "curb_macros.h"
|
29
29
|
|
30
30
|
// These should be managed from the Rake 'release' task.
|
31
|
-
#define CURB_VERSION "1.0.
|
32
|
-
#define CURB_VER_NUM
|
31
|
+
#define CURB_VERSION "1.0.3"
|
32
|
+
#define CURB_VER_NUM 1003
|
33
33
|
#define CURB_VER_MAJ 1
|
34
34
|
#define CURB_VER_MIN 0
|
35
|
-
#define CURB_VER_MIC
|
35
|
+
#define CURB_VER_MIC 3
|
36
36
|
#define CURB_VER_PATCH 0
|
37
37
|
|
38
38
|
|
data/ext/curb_multi.c
CHANGED
@@ -43,6 +43,11 @@ static void rb_curl_multi_remove(ruby_curl_multi *rbcm, VALUE easy);
|
|
43
43
|
static void rb_curl_multi_read_info(VALUE self, CURLM *mptr);
|
44
44
|
static void rb_curl_multi_run(VALUE self, CURLM *multi_handle, int *still_running);
|
45
45
|
|
46
|
+
static VALUE callback_exception(VALUE did_raise, VALUE exception) {
|
47
|
+
rb_hash_aset(did_raise, rb_easy_hkey("error"), exception);
|
48
|
+
return exception;
|
49
|
+
}
|
50
|
+
|
46
51
|
void curl_multi_free(ruby_curl_multi *rbcm) {
|
47
52
|
curl_multi_cleanup(rbcm->handle);
|
48
53
|
free(rbcm);
|
@@ -292,13 +297,14 @@ static void rb_curl_mutli_handle_complete(VALUE self, CURL *easy_handle, int res
|
|
292
297
|
}
|
293
298
|
|
294
299
|
int status;
|
300
|
+
VALUE did_raise = rb_hash_new();
|
295
301
|
|
296
302
|
if (!rb_easy_nil("complete_proc")) {
|
297
303
|
callargs = rb_ary_new3(2, rb_easy_get("complete_proc"), easy);
|
298
304
|
rbce->callback_active = 1;
|
299
|
-
|
305
|
+
rb_rescue(call_status_handler1, callargs, callback_exception, did_raise);
|
300
306
|
rbce->callback_active = 0;
|
301
|
-
if (
|
307
|
+
if (rb_hash_aref(did_raise, "error") != Qnil) {
|
302
308
|
CURB_RB_CALLBACK_RAISE("complete")
|
303
309
|
}
|
304
310
|
}
|
@@ -316,9 +322,9 @@ static void rb_curl_mutli_handle_complete(VALUE self, CURL *easy_handle, int res
|
|
316
322
|
if (!rb_easy_nil("failure_proc")) {
|
317
323
|
callargs = rb_ary_new3(3, rb_easy_get("failure_proc"), easy, rb_curl_easy_error(result));
|
318
324
|
rbce->callback_active = 1;
|
319
|
-
|
325
|
+
rb_rescue(call_status_handler2, callargs, callback_exception, did_raise);
|
320
326
|
rbce->callback_active = 0;
|
321
|
-
if (
|
327
|
+
if (rb_hash_aref(did_raise, "error") != Qnil) {
|
322
328
|
CURB_RB_CALLBACK_RAISE("failure")
|
323
329
|
}
|
324
330
|
}
|
@@ -327,17 +333,17 @@ static void rb_curl_mutli_handle_complete(VALUE self, CURL *easy_handle, int res
|
|
327
333
|
/* NOTE: we allow response_code == 0, in the case of non http requests e.g. reading from disk */
|
328
334
|
callargs = rb_ary_new3(2, rb_easy_get("success_proc"), easy);
|
329
335
|
rbce->callback_active = 1;
|
330
|
-
|
336
|
+
rb_rescue(call_status_handler1, callargs, callback_exception, did_raise);
|
331
337
|
rbce->callback_active = 0;
|
332
|
-
if (
|
338
|
+
if (rb_hash_aref(did_raise, "error") != Qnil) {
|
333
339
|
CURB_RB_CALLBACK_RAISE("success")
|
334
340
|
}
|
335
341
|
} else if (!rb_easy_nil("redirect_proc") && ((response_code >= 300 && response_code < 400) || redirect_count > 0) ) {
|
336
342
|
rbce->callback_active = 1;
|
337
343
|
callargs = rb_ary_new3(3, rb_easy_get("redirect_proc"), easy, rb_curl_easy_error(result));
|
338
344
|
rbce->callback_active = 0;
|
339
|
-
|
340
|
-
if (
|
345
|
+
rb_rescue(call_status_handler2, callargs, callback_exception, did_raise);
|
346
|
+
if (rb_hash_aref(did_raise, "error") != Qnil) {
|
341
347
|
CURB_RB_CALLBACK_RAISE("redirect")
|
342
348
|
}
|
343
349
|
} else if (!rb_easy_nil("missing_proc") &&
|
@@ -345,17 +351,17 @@ static void rb_curl_mutli_handle_complete(VALUE self, CURL *easy_handle, int res
|
|
345
351
|
rbce->callback_active = 1;
|
346
352
|
callargs = rb_ary_new3(3, rb_easy_get("missing_proc"), easy, rb_curl_easy_error(result));
|
347
353
|
rbce->callback_active = 0;
|
348
|
-
|
349
|
-
if (
|
354
|
+
rb_rescue(call_status_handler2, callargs, callback_exception, did_raise);
|
355
|
+
if (rb_hash_aref(did_raise, "error") != Qnil) {
|
350
356
|
CURB_RB_CALLBACK_RAISE("missing")
|
351
357
|
}
|
352
358
|
} else if (!rb_easy_nil("failure_proc") &&
|
353
359
|
(response_code >= 500 && response_code <= 999)) {
|
354
360
|
callargs = rb_ary_new3(3, rb_easy_get("failure_proc"), easy, rb_curl_easy_error(result));
|
355
361
|
rbce->callback_active = 1;
|
356
|
-
|
362
|
+
rb_rescue(call_status_handler2, callargs, callback_exception, did_raise);
|
357
363
|
rbce->callback_active = 0;
|
358
|
-
if (
|
364
|
+
if (rb_hash_aref(did_raise, "error") != Qnil) {
|
359
365
|
CURB_RB_CALLBACK_RAISE("failure")
|
360
366
|
}
|
361
367
|
}
|
data/lib/curl/multi.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Curl
|
3
3
|
class Multi
|
4
|
+
class DownloadError < RuntimeError
|
5
|
+
attr_accessor :errors
|
6
|
+
end
|
4
7
|
class << self
|
5
8
|
# call-seq:
|
6
9
|
# Curl::Multi.get(['url1','url2','url3','url4','url5'], :follow_location => true) do|easy|
|
@@ -241,7 +244,11 @@ module Curl
|
|
241
244
|
errors << e
|
242
245
|
end
|
243
246
|
}
|
244
|
-
|
247
|
+
if errors.any?
|
248
|
+
de = Curl::Multi::DownloadError.new
|
249
|
+
de.errors = errors
|
250
|
+
raise de
|
251
|
+
end
|
245
252
|
end
|
246
253
|
end
|
247
254
|
|
data/tests/tc_curl_multi.rb
CHANGED
@@ -161,6 +161,15 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
161
161
|
|
162
162
|
end
|
163
163
|
|
164
|
+
def test_multi_easy_get
|
165
|
+
n = 1
|
166
|
+
urls = []
|
167
|
+
n.times { urls << $TEST_URL }
|
168
|
+
Curl::Multi.get(urls, {timeout: 5}) {|easy|
|
169
|
+
puts easy.last_effective_url
|
170
|
+
}
|
171
|
+
end
|
172
|
+
|
164
173
|
# NOTE: if this test runs slowly on Mac OSX, it is probably due to the use of a port install curl+ssl+ares install
|
165
174
|
# on my MacBook, this causes curl_easy_init to take nearly 0.01 seconds / * 100 below is 1 second too many!
|
166
175
|
def test_n_requests
|