taf2-curb 0.4.6.0 → 0.4.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/ext/curb.h CHANGED
@@ -20,20 +20,21 @@
20
20
  #include "curb_macros.h"
21
21
 
22
22
  // These should be managed from the Rake 'release' task.
23
- #define CURB_VERSION "0.4.6.0"
24
- #define CURB_VER_NUM 460
23
+ #define CURB_VERSION "0.4.8.0"
24
+ #define CURB_VER_NUM 480
25
25
  #define CURB_VER_MAJ 0
26
26
  #define CURB_VER_MIN 4
27
- #define CURB_VER_MIC 6
27
+ #define CURB_VER_MIC 8
28
28
  #define CURB_VER_PATCH 0
29
29
 
30
30
 
31
31
  // Maybe not yet defined in Ruby
32
32
  #ifndef RSTRING_LEN
33
- #define RSTRING_LEN(x) RSTRING(x)->len
33
+ #define RSTRING_LEN(x) RSTRING(x)->len
34
34
  #endif
35
+
35
36
  #ifndef RSTRING_PTR
36
- #define RSTRING_PTR(x) RSTRING(x)->ptr
37
+ #define RSTRING_PTR(x) RSTRING(x)->ptr
37
38
  #endif
38
39
 
39
40
  #ifdef HAVE_RUBY19_HASH
data/ext/curb_easy.c CHANGED
@@ -8,6 +8,7 @@
8
8
  #include "curb_errors.h"
9
9
  #include "curb_postfield.h"
10
10
  #include "curb_upload.h"
11
+ #include "curb_multi.h"
11
12
 
12
13
  #include <errno.h>
13
14
  #include <string.h>
@@ -1716,147 +1717,16 @@ VALUE ruby_curl_easy_cleanup( VALUE self, ruby_curl_easy *rbce, VALUE bodybuf, V
1716
1717
  */
1717
1718
  static VALUE handle_perform(VALUE self, ruby_curl_easy *rbce) {
1718
1719
 
1719
- CURLcode result = -1;
1720
- struct curl_slist *headers = NULL;
1721
- VALUE bodybuf = Qnil, headerbuf = Qnil;
1722
- // char errors[CURL_ERROR_SIZE*2];
1720
+ VALUE multi = ruby_curl_multi_new(cCurlMulti);
1721
+ ruby_curl_multi_add(multi, self);
1722
+ VALUE ret = ruby_curl_multi_perform(multi);
1723
1723
 
1724
- ruby_curl_easy_setup(rbce, &bodybuf, &headerbuf, &headers);
1725
- // curl_easy_setopt(rbce->curl, CURLOPT_ERRORBUFFER, errors);
1726
- // curl_easy_setopt(rbce->curl, CURLOPT_VERBOSE, 1);
1727
-
1728
- if( rb_thread_alone() ) {
1729
- result = curl_easy_perform(rbce->curl);
1724
+ /* check for errors in the easy response and raise exceptions if anything went wrong and their is no on_failure handler */
1725
+ if( rbce->last_result != 0 && rbce->failure_proc == Qnil ) {
1726
+ raise_curl_easy_error_exception(rbce->last_result);
1730
1727
  }
1731
- else {
1732
- int msgs;
1733
- int still_running = 1;
1734
- CURLMcode mcode = -1;
1735
- CURLM *multi_handle = curl_multi_init();
1736
- long timeout;
1737
- struct timeval tv = {0, 0};
1738
- int rc; /* select() return code */
1739
- int maxfd;
1740
-
1741
- /* NOTE:
1742
- * We create an Curl multi handle here and use rb_thread_select allowing other ruby threads to
1743
- * perform actions... ideally we'd have just 1 shared multi handle per all curl easy handles globally
1744
- */
1745
- mcode = curl_multi_add_handle(multi_handle, rbce->curl);
1746
- if (mcode != CURLM_CALL_MULTI_PERFORM && mcode != CURLM_OK) {
1747
- raise_curl_multi_error_exception(mcode);
1748
- }
1749
-
1750
- while(CURLM_CALL_MULTI_PERFORM == (mcode=curl_multi_perform(multi_handle, &still_running)) ) ;
1751
-
1752
- if (mcode != CURLM_CALL_MULTI_PERFORM && mcode != CURLM_OK) {
1753
- raise_curl_multi_error_exception(mcode);
1754
- }
1755
-
1756
-
1757
- while(still_running) {
1758
-
1759
- fd_set fdread;
1760
- fd_set fdwrite;
1761
- fd_set fdexcep;
1762
-
1763
- FD_ZERO(&fdread);
1764
- FD_ZERO(&fdwrite);
1765
- FD_ZERO(&fdexcep);
1766
-
1767
- //time_t timer = time(NULL);
1768
- /* get file descriptors from the transfers */
1769
- mcode = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
1770
- if (mcode != CURLM_CALL_MULTI_PERFORM && mcode != CURLM_OK) {
1771
- raise_curl_multi_error_exception(mcode);
1772
- }
1773
-
1774
- #ifdef HAVE_CURL_MULTI_TIMEOUT
1775
- /* get the curl suggested time out */
1776
- mcode = curl_multi_timeout(multi_handle, &timeout);
1777
- if (mcode != CURLM_OK) {
1778
- raise_curl_multi_error_exception(mcode);
1779
- }
1780
- #else
1781
- /* libcurl doesn't have a timeout method defined... make a wild guess */
1782
- timeout = 1; /* wait a second */
1783
- #endif
1784
-
1785
- if (timeout == 0) { /* no delay */
1786
- while(CURLM_CALL_MULTI_PERFORM == (mcode=curl_multi_perform(multi_handle, &still_running)) );
1787
- continue;
1788
- }
1789
- else if (timeout == -1) {
1790
- timeout = 1; /* wait a second */
1791
- }
1792
-
1793
- /* set a suitable timeout to play around with - ruby seems to be greedy about this and won't necessarily yield so the timeout is small.. */
1794
- tv.tv_sec = timeout / 1000;
1795
- tv.tv_usec = (timeout * 1000) % 1000000;
1796
- rc = rb_thread_select(maxfd+1, &fdread, &fdwrite, &fdexcep, &tv);
1797
- if (rc < 0) {
1798
- rb_raise(rb_eRuntimeError, "select(): %s", strerror(errno));
1799
- }
1800
1728
 
1801
- if( rc >= 0 ) {
1802
- switch(rc) {
1803
- case 0:
1804
- //printf("timeout(%.6f) :", difftime(time(NULL), timer) );
1805
- default:
1806
- //printf("readable/writable: %d\n", rc);
1807
- /* timeout or readable/writable sockets */
1808
- while(CURLM_CALL_MULTI_PERFORM == (mcode=curl_multi_perform(multi_handle, &still_running)) );
1809
- break;
1810
- }
1811
- }
1812
- else {
1813
- // error
1814
- }
1815
-
1816
- if (mcode != CURLM_CALL_MULTI_PERFORM && mcode != CURLM_OK) {
1817
- raise_curl_multi_error_exception(mcode);
1818
- }
1819
-
1820
- }
1821
-
1822
- /* check for errors */
1823
- CURLMsg *msg = curl_multi_info_read(multi_handle, &msgs);
1824
- if (msg && msg->msg == CURLMSG_DONE) {
1825
- result = msg->data.result;
1826
- }
1827
-
1828
- curl_multi_remove_handle(multi_handle, rbce->curl);
1829
- curl_multi_cleanup(multi_handle);
1830
- }
1831
-
1832
- ruby_curl_easy_cleanup(self, rbce, bodybuf, headerbuf, headers);
1833
-
1834
- if (rbce->complete_proc != Qnil) {
1835
- rb_funcall( rbce->complete_proc, idCall, 1, self );
1836
- }
1837
-
1838
- /* check the request status and determine if on_success or on_failure should be called */
1839
- long response_code = -1;
1840
- curl_easy_getinfo(rbce->curl, CURLINFO_RESPONSE_CODE, &response_code);
1841
- if (result != 0) {
1842
- // printf("error: %s\n", errors);
1843
- if (rbce->failure_proc != Qnil) {
1844
- rb_funcall( rbce->failure_proc, idCall, 2, rbce->self, rb_curl_easy_error(result) );
1845
- } else {
1846
- raise_curl_easy_error_exception(result);
1847
- }
1848
- }
1849
- else if (rbce->success_proc != Qnil &&
1850
- /* NOTE: we allow response_code == 0, in the case the file is being read from disk */
1851
- ((response_code >= 200 && response_code < 300) || response_code == 0)) {
1852
- rb_funcall( rbce->success_proc, idCall, 1, self );
1853
- }
1854
- else if (rbce->failure_proc != Qnil &&
1855
- (response_code >= 300 && response_code <= 999)) {
1856
- rb_funcall( rbce->failure_proc, idCall, 2, rbce->self, rb_curl_easy_error(result) );
1857
- }
1858
-
1859
- return Qtrue;
1729
+ return ret;
1860
1730
  }
1861
1731
 
1862
1732
  /*
data/ext/curb_easy.h CHANGED
@@ -89,6 +89,8 @@ typedef struct {
89
89
  VALUE self; /* pointer to self, used by multi interface */
90
90
  VALUE upload; /* pointer to an active upload otherwise Qnil */
91
91
 
92
+ int last_result; /* last result code from multi loop */
93
+
92
94
  } ruby_curl_easy;
93
95
 
94
96
  extern VALUE cCurlEasy;
data/ext/curb_multi.c CHANGED
@@ -6,9 +6,11 @@
6
6
 
7
7
  #include "curb_config.h"
8
8
  #ifdef HAVE_RUBY19_ST_H
9
- #include <ruby/st.h>
9
+ #include <ruby.h>
10
+ #include <ruby/st.h>
10
11
  #else
11
- #include <st.h>
12
+ #include <ruby.h>
13
+ #include <st.h>
12
14
  #endif
13
15
  #include "curb_easy.h"
14
16
  #include "curb_errors.h"
@@ -26,7 +28,6 @@ static VALUE idCall;
26
28
 
27
29
  VALUE cCurlMulti;
28
30
 
29
- static VALUE ruby_curl_multi_remove(VALUE , VALUE );
30
31
  static void rb_curl_multi_remove(ruby_curl_multi *rbcm, VALUE easy);
31
32
  static void rb_curl_multi_read_info(VALUE self, CURLM *mptr);
32
33
 
@@ -76,7 +77,7 @@ static void curl_multi_free(ruby_curl_multi *rbcm) {
76
77
  *
77
78
  * Create a new Curl::Multi instance
78
79
  */
79
- static VALUE ruby_curl_multi_new(VALUE klass) {
80
+ VALUE ruby_curl_multi_new(VALUE klass) {
80
81
  VALUE new_curlm;
81
82
 
82
83
  ruby_curl_multi *rbcm = ALLOC(ruby_curl_multi);
@@ -186,7 +187,7 @@ static VALUE ruby_curl_multi_pipeline(VALUE self, VALUE onoff) {
186
187
  *
187
188
  * Add an easy handle to the multi stack
188
189
  */
189
- static VALUE ruby_curl_multi_add(VALUE self, VALUE easy) {
190
+ VALUE ruby_curl_multi_add(VALUE self, VALUE easy) {
190
191
  CURLMcode mcode;
191
192
  ruby_curl_easy *rbce;
192
193
  ruby_curl_multi *rbcm;
@@ -234,7 +235,7 @@ static VALUE ruby_curl_multi_add(VALUE self, VALUE easy) {
234
235
  *
235
236
  * Will raise an exception if the easy handle is not found
236
237
  */
237
- static VALUE ruby_curl_multi_remove(VALUE self, VALUE easy) {
238
+ VALUE ruby_curl_multi_remove(VALUE self, VALUE easy) {
238
239
  ruby_curl_multi *rbcm;
239
240
 
240
241
  Data_Get_Struct(self, ruby_curl_multi, rbcm);
@@ -316,6 +317,7 @@ static void rb_curl_multi_read_info(VALUE self, CURLM *multi_handle) {
316
317
  if (ecode != 0) {
317
318
  raise_curl_easy_error_exception(ecode);
318
319
  }
320
+ rbce->last_result = result; // save the last easy result code
319
321
  ruby_curl_multi_remove( self, rbce->self );
320
322
 
321
323
  if (rbce->complete_proc != Qnil) {
@@ -377,7 +379,7 @@ static void rb_curl_multi_run(VALUE self, CURLM *multi_handle, int *still_runnin
377
379
  *
378
380
  * Run multi handles, looping selecting when data can be transfered
379
381
  */
380
- static VALUE ruby_curl_multi_perform(VALUE self) {
382
+ VALUE ruby_curl_multi_perform(VALUE self) {
381
383
  CURLMcode mcode;
382
384
  ruby_curl_multi *rbcm;
383
385
  int maxfd, rc;
@@ -437,7 +439,7 @@ static VALUE ruby_curl_multi_perform(VALUE self) {
437
439
 
438
440
  }
439
441
 
440
- return Qnil;
442
+ return Qtrue;
441
443
  }
442
444
 
443
445
  /* =================== INIT LIB =====================*/
data/ext/curb_multi.h CHANGED
@@ -20,6 +20,10 @@ typedef struct {
20
20
 
21
21
  extern VALUE cCurlMulti;
22
22
  void init_curb_multi();
23
+ VALUE ruby_curl_multi_new(VALUE klass);
24
+ VALUE ruby_curl_multi_perform(VALUE self);
25
+ VALUE ruby_curl_multi_add(VALUE self, VALUE easy);
26
+ VALUE ruby_curl_multi_remove(VALUE self, VALUE easy);
23
27
 
24
28
 
25
29
  #endif
data/tests/helper.rb CHANGED
@@ -21,7 +21,7 @@ require 'webrick'
21
21
  # or to test with multiple threads set it to false
22
22
  # this is important since, some code paths will change depending
23
23
  # on the presence of multiple threads
24
- TEST_SINGLE_THREADED=true
24
+ TEST_SINGLE_THREADED=false
25
25
 
26
26
  # keep webrick quiet
27
27
  class ::WEBrick::HTTPServer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taf2-curb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6.0
4
+ version: 0.4.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Bamford
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-07-19 00:00:00 -07:00
13
+ date: 2009-07-21 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -32,18 +32,18 @@ files:
32
32
  - lib/curb.rb
33
33
  - lib/curl.rb
34
34
  - ext/curb.c
35
- - ext/curb_easy.c
36
- - ext/curb_errors.c
37
- - ext/curb_multi.c
38
35
  - ext/curb_postfield.c
36
+ - ext/curb_multi.c
37
+ - ext/curb_errors.c
38
+ - ext/curb_easy.c
39
39
  - ext/curb_upload.c
40
- - ext/curb.h
41
40
  - ext/curb_easy.h
42
41
  - ext/curb_errors.h
42
+ - ext/curb_upload.h
43
43
  - ext/curb_macros.h
44
- - ext/curb_multi.h
44
+ - ext/curb.h
45
45
  - ext/curb_postfield.h
46
- - ext/curb_upload.h
46
+ - ext/curb_multi.h
47
47
  has_rdoc: true
48
48
  homepage: http://curb.rubyforge.org/
49
49
  post_install_message:
@@ -73,15 +73,15 @@ signing_key:
73
73
  specification_version: 2
74
74
  summary: Ruby libcurl bindings
75
75
  test_files:
76
- - tests/alltests.rb
76
+ - tests/tc_curl_multi.rb
77
+ - tests/tc_curl_postfield.rb
77
78
  - tests/bug_curb_easy_blocks_ruby_threads.rb
78
- - tests/bug_instance_post_differs_from_class_post.rb
79
- - tests/bug_multi_segfault.rb
79
+ - tests/unittests.rb
80
80
  - tests/bug_require_last_or_segfault.rb
81
- - tests/helper.rb
82
- - tests/require_last_or_segfault_script.rb
81
+ - tests/bug_instance_post_differs_from_class_post.rb
83
82
  - tests/tc_curl_download.rb
83
+ - tests/alltests.rb
84
+ - tests/helper.rb
84
85
  - tests/tc_curl_easy.rb
85
- - tests/tc_curl_multi.rb
86
- - tests/tc_curl_postfield.rb
87
- - tests/unittests.rb
86
+ - tests/bug_multi_segfault.rb
87
+ - tests/require_last_or_segfault_script.rb