taf2-curb 0.4.5.0 → 0.4.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/doc.rb CHANGED
@@ -34,7 +34,7 @@ begin
34
34
  end
35
35
  end
36
36
 
37
- system("rdoc --title='Curb - libcurl bindings for ruby' --main=README #{pp_srcdir}/*.c README LICENSE ext/curb.rb")
37
+ system("rdoc --title='Curb - libcurl bindings for ruby' --main=README #{pp_srcdir}/*.c README LICENSE lib/curb.rb")
38
38
  ensure
39
39
  rm_rf(tmpdir)
40
40
  end
data/ext/curb.h CHANGED
@@ -20,11 +20,11 @@
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.5.0"
24
- #define CURB_VER_NUM 450
23
+ #define CURB_VERSION "0.4.6.0"
24
+ #define CURB_VER_NUM 460
25
25
  #define CURB_VER_MAJ 0
26
26
  #define CURB_VER_MIN 4
27
- #define CURB_VER_MIC 5
27
+ #define CURB_VER_MIC 6
28
28
  #define CURB_VER_PATCH 0
29
29
 
30
30
 
data/ext/curb_multi.c CHANGED
@@ -93,6 +93,51 @@ static VALUE ruby_curl_multi_new(VALUE klass) {
93
93
  return new_curlm;
94
94
  }
95
95
 
96
+ // Hash#foreach callback for ruby_curl_multi_requests
97
+ static int ruby_curl_multi_requests_callback(VALUE key, VALUE value, VALUE result_array) {
98
+ rb_ary_push(result_array, value);
99
+
100
+ return ST_CONTINUE;
101
+ }
102
+
103
+ /*
104
+ * call-seq:
105
+ * multi.requests => [#<Curl::Easy...>, ...]
106
+ *
107
+ * Returns an array containing all the active requests on this Curl::Multi object.
108
+ */
109
+ static VALUE ruby_curl_multi_requests(VALUE self) {
110
+ ruby_curl_multi *rbcm;
111
+
112
+ Data_Get_Struct(self, ruby_curl_multi, rbcm);
113
+
114
+ VALUE result_array = rb_ary_new();
115
+
116
+ // iterate over the requests hash, and stuff references into the array.
117
+ rb_hash_foreach( rbcm->requests, ruby_curl_multi_requests_callback, result_array );
118
+
119
+ return result_array;
120
+ }
121
+
122
+ /*
123
+ * call-seq:
124
+ * multi.idle? => true or false
125
+ *
126
+ * Returns whether or not this Curl::Multi handle is processing any requests. E.g. this returns
127
+ * true when multi.requests.length == 0.
128
+ */
129
+ static VALUE ruby_curl_multi_idle(VALUE self) {
130
+ ruby_curl_multi *rbcm;
131
+
132
+ Data_Get_Struct(self, ruby_curl_multi, rbcm);
133
+
134
+ if ( FIX2INT( rb_funcall(rbcm->requests, rb_intern("length"), 0) ) == 0 ) {
135
+ return Qtrue;
136
+ } else {
137
+ return Qfalse;
138
+ }
139
+ }
140
+
96
141
  /*
97
142
  * call-seq:
98
143
  * multi = Curl::Multi.new
@@ -185,7 +230,7 @@ static VALUE ruby_curl_multi_add(VALUE self, VALUE easy) {
185
230
  * # sometime later
186
231
  * multi.remove(easy)
187
232
  *
188
- * Remove an easy handle from a multi stack
233
+ * Remove an easy handle from a multi stack.
189
234
  *
190
235
  * Will raise an exception if the easy handle is not found
191
236
  */
@@ -226,6 +271,30 @@ static void rb_curl_multi_remove(ruby_curl_multi *rbcm, VALUE easy) {
226
271
  }
227
272
  }
228
273
 
274
+ // Hash#foreach callback for ruby_curl_multi_cancel
275
+ static int ruby_curl_multi_cancel_callback(VALUE key, VALUE value, ruby_curl_multi *rbcm) {
276
+ rb_curl_multi_remove(rbcm, value);
277
+
278
+ return ST_CONTINUE;
279
+ }
280
+
281
+ /*
282
+ * call-seq:
283
+ * multi.cancel!
284
+ *
285
+ * Cancels all requests currently being made on this Curl::Multi handle.
286
+ */
287
+ static VALUE ruby_curl_multi_cancel(VALUE self) {
288
+ ruby_curl_multi *rbcm;
289
+
290
+ Data_Get_Struct(self, ruby_curl_multi, rbcm);
291
+
292
+ rb_hash_foreach( rbcm->requests, ruby_curl_multi_cancel_callback, (VALUE)rbcm );
293
+
294
+ // for chaining
295
+ return self;
296
+ }
297
+
229
298
  static void rb_curl_multi_read_info(VALUE self, CURLM *multi_handle) {
230
299
  int msgs_left, result;
231
300
  CURLMsg *msg;
@@ -379,11 +448,16 @@ void init_curb_multi() {
379
448
 
380
449
  /* Class methods */
381
450
  rb_define_singleton_method(cCurlMulti, "new", ruby_curl_multi_new, 0);
382
-
451
+
452
+ /* "Attributes" */
453
+ rb_define_method(cCurlMulti, "requests", ruby_curl_multi_requests, 0);
454
+ rb_define_method(cCurlMulti, "idle?", ruby_curl_multi_idle, 0);
455
+
383
456
  /* Instnace methods */
384
457
  rb_define_method(cCurlMulti, "max_connects=", ruby_curl_multi_max_connects, 1);
385
458
  rb_define_method(cCurlMulti, "pipeline=", ruby_curl_multi_pipeline, 1);
386
459
  rb_define_method(cCurlMulti, "add", ruby_curl_multi_add, 1);
387
460
  rb_define_method(cCurlMulti, "remove", ruby_curl_multi_remove, 1);
461
+ rb_define_method(cCurlMulti, "cancel!", ruby_curl_multi_cancel, 0);
388
462
  rb_define_method(cCurlMulti, "perform", ruby_curl_multi_perform, 0);
389
463
  }
data/ext/curb_upload.c CHANGED
@@ -6,6 +6,10 @@
6
6
  extern VALUE mCurl;
7
7
  VALUE cCurlUpload;
8
8
 
9
+ #ifdef RDOC_NEVER_DEFINED
10
+ mCurl = rb_define_module("Curl");
11
+ #endif
12
+
9
13
  static void curl_upload_mark(ruby_curl_upload *rbcu) {
10
14
  if (rbcu->stream) rb_gc_mark(rbcu->stream);
11
15
  }
@@ -13,6 +17,10 @@ static void curl_upload_free(ruby_curl_upload *rbcu) {
13
17
  free(rbcu);
14
18
  }
15
19
 
20
+ /*
21
+ * call-seq:
22
+ * internal class for sending large file uploads
23
+ */
16
24
  VALUE ruby_curl_upload_new(VALUE klass) {
17
25
  VALUE upload;
18
26
  ruby_curl_upload *rbcu = ALLOC(ruby_curl_upload);
@@ -22,23 +30,39 @@ VALUE ruby_curl_upload_new(VALUE klass) {
22
30
  return upload;
23
31
  }
24
32
 
33
+ /*
34
+ * call-seq:
35
+ * internal class for sending large file uploads
36
+ */
25
37
  VALUE ruby_curl_upload_stream_set(VALUE self, VALUE stream) {
26
38
  ruby_curl_upload *rbcu;
27
39
  Data_Get_Struct(self, ruby_curl_upload, rbcu);
28
40
  rbcu->stream = stream;
29
41
  return stream;
30
42
  }
43
+ /*
44
+ * call-seq:
45
+ * internal class for sending large file uploads
46
+ */
31
47
  VALUE ruby_curl_upload_stream_get(VALUE self) {
32
48
  ruby_curl_upload *rbcu;
33
49
  Data_Get_Struct(self, ruby_curl_upload, rbcu);
34
50
  return rbcu->stream;
35
51
  }
52
+ /*
53
+ * call-seq:
54
+ * internal class for sending large file uploads
55
+ */
36
56
  VALUE ruby_curl_upload_offset_set(VALUE self, VALUE offset) {
37
57
  ruby_curl_upload *rbcu;
38
58
  Data_Get_Struct(self, ruby_curl_upload, rbcu);
39
59
  rbcu->offset = FIX2INT(offset);
40
60
  return offset;
41
61
  }
62
+ /*
63
+ * call-seq:
64
+ * internal class for sending large file uploads
65
+ */
42
66
  VALUE ruby_curl_upload_offset_get(VALUE self) {
43
67
  ruby_curl_upload *rbcu;
44
68
  Data_Get_Struct(self, ruby_curl_upload, rbcu);
@@ -100,6 +100,50 @@ class TestCurbCurlMulti < Test::Unit::TestCase
100
100
  m = nil
101
101
 
102
102
  end
103
+
104
+ def test_idle_check
105
+ m = Curl::Multi.new
106
+ e = Curl::Easy.new($TEST_URL)
107
+
108
+ assert(m.idle?, 'A new Curl::Multi handle should be idle')
109
+
110
+ m.add(e)
111
+
112
+ assert((not m.idle?), 'A Curl::Multi handle with a request should not be idle')
113
+
114
+ m.perform
115
+
116
+ assert(m.idle?, 'A Curl::Multi handle should be idle after performing its requests')
117
+ end
118
+
119
+ def test_requests
120
+ m = Curl::Multi.new
121
+
122
+ assert_equal([], m.requests, 'A new Curl::Multi handle should have no requests')
123
+
124
+ 10.times do
125
+ m.add(Curl::Easy.new($TEST_URL))
126
+ end
127
+
128
+ assert_equal(10, m.requests.length, 'multi.requests should contain all the active requests')
129
+
130
+ m.perform
131
+
132
+ assert_equal([], m.requests, 'A new Curl::Multi handle should have no requests after a perform')
133
+ end
134
+
135
+ def test_cancel
136
+ m = Curl::Multi.new
137
+ m.cancel! # shouldn't raise anything
138
+
139
+ 10.times do
140
+ m.add(Curl::Easy.new($TEST_URL))
141
+ end
142
+
143
+ m.cancel!
144
+
145
+ assert_equal([], m.requests, 'A new Curl::Multi handle should have no requests after being canceled')
146
+ end
103
147
 
104
148
  def test_with_success
105
149
  c1 = Curl::Easy.new($TEST_URL)
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.5.0
4
+ version: 0.4.6.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-18 00:00:00 -07:00
13
+ date: 2009-07-19 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16