pauldix-typhoeus 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,8 +4,8 @@ VALUE mTyphoeus;
4
4
 
5
5
  void Init_native()
6
6
  {
7
- mTyphoeus = rb_const_get(rb_cObject, rb_intern("Typhoeus"));
8
-
9
- init_typhoeus_easy();
10
- init_typhoeus_multi();
11
- }
7
+ mTyphoeus = rb_const_get(rb_cObject, rb_intern("Typhoeus"));
8
+
9
+ init_typhoeus_easy();
10
+ init_typhoeus_multi();
11
+ }
@@ -6,6 +6,9 @@
6
6
  #include <curl/easy.h>
7
7
  #include <curl/multi.h>
8
8
 
9
+ void Init_native();
9
10
  extern VALUE mTyphoeus;
11
+ extern void init_typhoeus_easy();
12
+ extern void init_typhoeus_multi();
10
13
 
11
- #endif
14
+ #endif
@@ -1,206 +1,207 @@
1
1
  #include <typhoeus_easy.h>
2
-
2
+
3
3
  static VALUE idAppend;
4
4
  VALUE cTyphoeusEasy;
5
5
 
6
6
  static void dealloc(CurlEasy *curl_easy) {
7
- if (curl_easy->request_chunk != NULL) {
8
- free(curl_easy->request_chunk);
9
- }
10
-
11
- if (curl_easy->headers != NULL) {
12
- curl_slist_free_all(curl_easy->headers);
13
- }
14
-
15
- curl_easy_cleanup(curl_easy->curl);
16
-
17
- free(curl_easy);
7
+ if (curl_easy->request_chunk != NULL) {
8
+ free(curl_easy->request_chunk);
9
+ }
10
+
11
+ if (curl_easy->headers != NULL) {
12
+ curl_slist_free_all(curl_easy->headers);
13
+ }
14
+
15
+ curl_easy_cleanup(curl_easy->curl);
16
+
17
+ free(curl_easy);
18
18
  }
19
19
 
20
20
  static VALUE easy_setopt_string(VALUE self, VALUE opt_name, VALUE parameter) {
21
- CurlEasy *curl_easy;
22
- Data_Get_Struct(self, CurlEasy, curl_easy);
21
+ CurlEasy *curl_easy;
22
+ Data_Get_Struct(self, CurlEasy, curl_easy);
23
23
 
24
- long opt = NUM2LONG(opt_name);
25
- curl_easy_setopt(curl_easy->curl, opt, StringValuePtr(parameter));
26
- return opt_name;
24
+ long opt = NUM2LONG(opt_name);
25
+ curl_easy_setopt(curl_easy->curl, opt, StringValuePtr(parameter));
26
+ return opt_name;
27
27
  }
28
28
 
29
29
  static VALUE easy_setopt_long(VALUE self, VALUE opt_name, VALUE parameter) {
30
- CurlEasy *curl_easy;
31
- Data_Get_Struct(self, CurlEasy, curl_easy);
30
+ CurlEasy *curl_easy;
31
+ Data_Get_Struct(self, CurlEasy, curl_easy);
32
32
 
33
- long opt = NUM2LONG(opt_name);
34
- curl_easy_setopt(curl_easy->curl, opt, NUM2LONG(parameter));
35
- return opt_name;
33
+ long opt = NUM2LONG(opt_name);
34
+ curl_easy_setopt(curl_easy->curl, opt, NUM2LONG(parameter));
35
+ return opt_name;
36
36
  }
37
37
 
38
38
  static VALUE easy_getinfo_string(VALUE self, VALUE info) {
39
- char *info_string;
40
- CurlEasy *curl_easy;
41
- Data_Get_Struct(self, CurlEasy, curl_easy);
39
+ char *info_string;
40
+ CurlEasy *curl_easy;
41
+ Data_Get_Struct(self, CurlEasy, curl_easy);
42
42
 
43
- long opt = NUM2LONG(info);
44
- curl_easy_getinfo(curl_easy->curl, opt, &info_string);
45
-
46
- return rb_str_new2(info_string);
43
+ long opt = NUM2LONG(info);
44
+ curl_easy_getinfo(curl_easy->curl, opt, &info_string);
45
+
46
+ return rb_str_new2(info_string);
47
47
  }
48
48
 
49
49
  static VALUE easy_getinfo_long(VALUE self, VALUE info) {
50
- long info_long;
51
- CurlEasy *curl_easy;
52
- Data_Get_Struct(self, CurlEasy, curl_easy);
50
+ long info_long;
51
+ CurlEasy *curl_easy;
52
+ Data_Get_Struct(self, CurlEasy, curl_easy);
53
+
54
+ long opt = NUM2LONG(info);
55
+ curl_easy_getinfo(curl_easy->curl, opt, &info_long);
53
56
 
54
- long opt = NUM2LONG(info);
55
- curl_easy_getinfo(curl_easy->curl, opt, &info_long);
56
-
57
- return LONG2NUM(info_long);
57
+ return LONG2NUM(info_long);
58
58
  }
59
59
 
60
60
  static VALUE easy_getinfo_double(VALUE self, VALUE info) {
61
- double info_double = 0;
62
- CurlEasy *curl_easy;
63
- Data_Get_Struct(self, CurlEasy, curl_easy);
61
+ double info_double = 0;
62
+ CurlEasy *curl_easy;
63
+ Data_Get_Struct(self, CurlEasy, curl_easy);
64
64
 
65
- long opt = NUM2LONG(info);
66
- curl_easy_getinfo(curl_easy->curl, opt, &info_double);
65
+ long opt = NUM2LONG(info);
66
+ curl_easy_getinfo(curl_easy->curl, opt, &info_double);
67
67
 
68
- return rb_float_new(info_double);
68
+ return rb_float_new(info_double);
69
69
  }
70
70
 
71
71
  static VALUE easy_perform(VALUE self) {
72
- CurlEasy *curl_easy;
73
- Data_Get_Struct(self, CurlEasy, curl_easy);
74
- curl_easy_perform(curl_easy->curl);
72
+ CurlEasy *curl_easy;
73
+ Data_Get_Struct(self, CurlEasy, curl_easy);
74
+ curl_easy_perform(curl_easy->curl);
75
75
 
76
- return Qnil;
76
+ return Qnil;
77
77
  }
78
78
 
79
79
  static size_t write_data_handler(char *stream, size_t size, size_t nmemb, VALUE val) {
80
- rb_funcall(val, idAppend, 1, rb_str_new(stream, size * nmemb));
81
- return size * nmemb;
80
+ long stream_size = (long)(size * nmemb);
81
+ rb_funcall(val, idAppend, 1, rb_str_new(stream, stream_size));
82
+ return size * nmemb;
82
83
  }
83
84
 
84
85
  static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *data) {
85
- int realsize = size * nmemb;
86
- RequestChunk *mem = (RequestChunk *)data;
86
+ size_t realsize = size * nmemb;
87
+ RequestChunk *mem = (RequestChunk *)data;
88
+
89
+ if (realsize > mem->size - mem->read) {
90
+ realsize = mem->size - mem->read;
91
+ }
87
92
 
88
- if (realsize > mem->size - mem->read) {
89
- realsize = mem->size - mem->read;
90
- }
91
-
92
- if (realsize != 0) {
93
- memcpy(ptr, &(mem->memory[mem->read]), realsize);
94
- mem->read += realsize;
95
- }
96
-
97
- return realsize;
93
+ if (realsize != 0) {
94
+ memcpy(ptr, &(mem->memory[mem->read]), realsize);
95
+ mem->read += realsize;
96
+ }
97
+
98
+ return realsize;
98
99
  }
99
100
 
100
101
  static void set_response_handlers(VALUE easy, CURL *curl) {
101
- rb_iv_set(easy, "@response_body", rb_str_new2(""));
102
- rb_iv_set(easy, "@response_header", rb_str_new2(""));
103
-
102
+ rb_iv_set(easy, "@response_body", rb_str_new2(""));
103
+ rb_iv_set(easy, "@response_header", rb_str_new2(""));
104
+
104
105
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, (curl_write_callback)&write_data_handler);
105
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, rb_iv_get(easy, "@response_body"));
106
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, rb_iv_get(easy, "@response_body"));
106
107
  curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, (curl_write_callback)&write_data_handler);
107
108
  curl_easy_setopt(curl, CURLOPT_HEADERDATA, rb_iv_get(easy, "@response_header"));
108
109
  }
109
110
 
110
111
  static VALUE easy_reset(VALUE self) {
111
- CurlEasy *curl_easy;
112
- Data_Get_Struct(self, CurlEasy, curl_easy);
112
+ CurlEasy *curl_easy;
113
+ Data_Get_Struct(self, CurlEasy, curl_easy);
114
+
115
+ if (curl_easy->request_chunk != NULL) {
116
+ free(curl_easy->request_chunk);
117
+ curl_easy->request_chunk = NULL;
118
+ }
113
119
 
114
- if (curl_easy->request_chunk != NULL) {
115
- free(curl_easy->request_chunk);
116
- curl_easy->request_chunk = NULL;
117
- }
118
-
119
- if (curl_easy->headers != NULL) {
120
- curl_slist_free_all(curl_easy->headers);
121
- curl_easy->headers = NULL;
122
- }
120
+ if (curl_easy->headers != NULL) {
121
+ curl_slist_free_all(curl_easy->headers);
122
+ curl_easy->headers = NULL;
123
+ }
123
124
 
124
- curl_easy_reset(curl_easy->curl);
125
+ curl_easy_reset(curl_easy->curl);
125
126
 
126
- set_response_handlers(self, curl_easy->curl);
127
-
128
- return Qnil;
127
+ set_response_handlers(self, curl_easy->curl);
128
+
129
+ return Qnil;
129
130
  }
130
131
 
131
132
  static VALUE easy_add_header(VALUE self, VALUE header) {
132
- CurlEasy *curl_easy;
133
- Data_Get_Struct(self, CurlEasy, curl_easy);
134
-
135
- curl_easy->headers = curl_slist_append(curl_easy->headers, RSTRING_PTR(header));
136
- return header;
133
+ CurlEasy *curl_easy;
134
+ Data_Get_Struct(self, CurlEasy, curl_easy);
135
+
136
+ curl_easy->headers = curl_slist_append(curl_easy->headers, RSTRING_PTR(header));
137
+ return header;
137
138
  }
138
139
 
139
140
  static VALUE easy_set_headers(VALUE self) {
140
- CurlEasy *curl_easy;
141
- Data_Get_Struct(self, CurlEasy, curl_easy);
141
+ CurlEasy *curl_easy;
142
+ Data_Get_Struct(self, CurlEasy, curl_easy);
143
+
144
+ curl_easy_setopt(curl_easy->curl, CURLOPT_HTTPHEADER, curl_easy->headers);
142
145
 
143
- curl_easy_setopt(curl_easy->curl, CURLOPT_HTTPHEADER, curl_easy->headers);
144
-
145
- return Qnil;
146
+ return Qnil;
146
147
  }
147
148
 
148
149
  static VALUE easy_set_request_body(VALUE self, VALUE data, VALUE content_length_header) {
149
- CurlEasy *curl_easy;
150
- Data_Get_Struct(self, CurlEasy, curl_easy);
150
+ CurlEasy *curl_easy;
151
+ Data_Get_Struct(self, CurlEasy, curl_easy);
151
152
 
152
- curl_easy->request_chunk = ALLOC(RequestChunk);
153
- curl_easy->request_chunk->size = RSTRING_LEN(data);
154
- curl_easy->request_chunk->memory = StringValuePtr(data);
155
- curl_easy->request_chunk->read = 0;
153
+ curl_easy->request_chunk = ALLOC(RequestChunk);
154
+ curl_easy->request_chunk->size = RSTRING_LEN(data);
155
+ curl_easy->request_chunk->memory = StringValuePtr(data);
156
+ curl_easy->request_chunk->read = 0;
156
157
 
157
158
  curl_easy_setopt(curl_easy->curl, CURLOPT_READFUNCTION, (curl_read_callback)read_callback);
158
159
  curl_easy_setopt(curl_easy->curl, CURLOPT_READDATA, curl_easy->request_chunk);
159
- curl_easy_setopt(curl_easy->curl, CURLOPT_INFILESIZE, RSTRING_LEN(data));
160
+ curl_easy_setopt(curl_easy->curl, CURLOPT_INFILESIZE, RSTRING_LEN(data));
160
161
 
161
- return Qnil;
162
+ return Qnil;
162
163
  }
163
164
 
164
165
  static VALUE easy_escape(VALUE self, VALUE data, VALUE length) {
165
- CurlEasy *curl_easy;
166
- Data_Get_Struct(self, CurlEasy, curl_easy);
166
+ CurlEasy *curl_easy;
167
+ Data_Get_Struct(self, CurlEasy, curl_easy);
167
168
 
168
- return rb_str_new2(curl_easy_escape(curl_easy->curl, StringValuePtr(data), NUM2INT(length)));
169
+ return rb_str_new2(curl_easy_escape(curl_easy->curl, StringValuePtr(data), NUM2INT(length)));
169
170
  }
170
171
 
171
172
  static VALUE version(VALUE self) {
172
- return rb_str_new2(curl_version());
173
+ return rb_str_new2(curl_version());
173
174
  }
174
175
 
175
176
  static VALUE new(int argc, VALUE *argv, VALUE klass) {
176
- CURL *curl = curl_easy_init();
177
- CurlEasy *curl_easy = ALLOC(CurlEasy);
178
- curl_easy->curl = curl;
179
- curl_easy->headers = NULL;
180
- curl_easy->request_chunk = NULL;
181
- VALUE easy = Data_Wrap_Struct(cTyphoeusEasy, 0, dealloc, curl_easy);
177
+ CURL *curl = curl_easy_init();
178
+ CurlEasy *curl_easy = ALLOC(CurlEasy);
179
+ curl_easy->curl = curl;
180
+ curl_easy->headers = NULL;
181
+ curl_easy->request_chunk = NULL;
182
+ VALUE easy = Data_Wrap_Struct(cTyphoeusEasy, 0, dealloc, curl_easy);
182
183
 
183
- set_response_handlers(easy, curl);
184
+ set_response_handlers(easy, curl);
184
185
 
185
- rb_obj_call_init(easy, argc, argv);
186
+ rb_obj_call_init(easy, argc, argv);
186
187
 
187
- return easy;
188
+ return easy;
188
189
  }
189
190
 
190
191
  void init_typhoeus_easy() {
191
- VALUE klass = cTyphoeusEasy = rb_define_class_under(mTyphoeus, "Easy", rb_cObject);
192
- idAppend = rb_intern("<<");
193
- rb_define_singleton_method(klass, "new", new, -1);
194
- rb_define_private_method(klass, "easy_setopt_string", easy_setopt_string, 2);
195
- rb_define_private_method(klass, "easy_setopt_long", easy_setopt_long, 2);
196
- rb_define_private_method(klass, "easy_getinfo_string", easy_getinfo_string, 1);
197
- rb_define_private_method(klass, "easy_getinfo_long", easy_getinfo_long, 1);
198
- rb_define_private_method(klass, "easy_getinfo_double", easy_getinfo_double, 1);
199
- rb_define_private_method(klass, "easy_perform", easy_perform, 0);
200
- rb_define_private_method(klass, "easy_reset", easy_reset, 0);
201
- rb_define_private_method(klass, "easy_set_request_body", easy_set_request_body, 1);
202
- rb_define_private_method(klass, "easy_set_headers", easy_set_headers, 0);
203
- rb_define_private_method(klass, "easy_add_header", easy_add_header, 1);
204
- rb_define_private_method(klass, "easy_escape", easy_escape, 2);
205
- rb_define_private_method(klass, "version", version, 0);
192
+ VALUE klass = cTyphoeusEasy = rb_define_class_under(mTyphoeus, "Easy", rb_cObject);
193
+ idAppend = rb_intern("<<");
194
+ rb_define_singleton_method(klass, "new", new, -1);
195
+ rb_define_private_method(klass, "easy_setopt_string", easy_setopt_string, 2);
196
+ rb_define_private_method(klass, "easy_setopt_long", easy_setopt_long, 2);
197
+ rb_define_private_method(klass, "easy_getinfo_string", easy_getinfo_string, 1);
198
+ rb_define_private_method(klass, "easy_getinfo_long", easy_getinfo_long, 1);
199
+ rb_define_private_method(klass, "easy_getinfo_double", easy_getinfo_double, 1);
200
+ rb_define_private_method(klass, "easy_perform", easy_perform, 0);
201
+ rb_define_private_method(klass, "easy_reset", easy_reset, 0);
202
+ rb_define_private_method(klass, "easy_set_request_body", easy_set_request_body, 1);
203
+ rb_define_private_method(klass, "easy_set_headers", easy_set_headers, 0);
204
+ rb_define_private_method(klass, "easy_add_header", easy_add_header, 1);
205
+ rb_define_private_method(klass, "easy_escape", easy_escape, 2);
206
+ rb_define_private_method(klass, "version", version, 0);
206
207
  }
@@ -5,15 +5,15 @@
5
5
 
6
6
  void init_typhoeus_easy();
7
7
  typedef struct {
8
- const char *memory;
9
- int size;
10
- int read;
8
+ const char *memory;
9
+ int size;
10
+ int read;
11
11
  } RequestChunk;
12
12
 
13
13
  typedef struct {
14
- RequestChunk *request_chunk;
15
- CURL *curl;
16
- struct curl_slist *headers;
14
+ RequestChunk *request_chunk;
15
+ CURL *curl;
16
+ struct curl_slist *headers;
17
17
  } CurlEasy;
18
18
 
19
- #endif
19
+ #endif
@@ -3,23 +3,23 @@
3
3
  static void multi_read_info(VALUE self, CURLM *multi_handle);
4
4
 
5
5
  static void dealloc(CurlMulti *curl_multi) {
6
- curl_multi_cleanup(curl_multi->multi);
7
- free(curl_multi);
6
+ curl_multi_cleanup(curl_multi->multi);
7
+ free(curl_multi);
8
8
  }
9
9
 
10
10
  static VALUE multi_add_handle(VALUE self, VALUE easy) {
11
- CurlEasy *curl_easy;
12
- Data_Get_Struct(easy, CurlEasy, curl_easy);
13
- CurlMulti *curl_multi;
14
- Data_Get_Struct(self, CurlMulti, curl_multi);
11
+ CurlEasy *curl_easy;
12
+ Data_Get_Struct(easy, CurlEasy, curl_easy);
13
+ CurlMulti *curl_multi;
14
+ Data_Get_Struct(self, CurlMulti, curl_multi);
15
15
  CURLMcode mcode;
16
16
 
17
17
  mcode = curl_multi_add_handle(curl_multi->multi, curl_easy->curl);
18
18
  if (mcode != CURLM_CALL_MULTI_PERFORM && mcode != CURLM_OK) {
19
- rb_raise(mcode, "An error occured adding the handle");
19
+ rb_raise((VALUE)mcode, "An error occured adding the handle");
20
20
  }
21
21
 
22
- curl_easy_setopt(curl_easy->curl, CURLOPT_PRIVATE, easy);
22
+ curl_easy_setopt(curl_easy->curl, CURLOPT_PRIVATE, easy);
23
23
  curl_multi->active++;
24
24
 
25
25
  if (mcode == CURLM_CALL_MULTI_PERFORM) {
@@ -27,23 +27,23 @@ static VALUE multi_add_handle(VALUE self, VALUE easy) {
27
27
  }
28
28
  //
29
29
  // if (curl_multi->running) {
30
- // printf("call read_info on add<br/>");
30
+ // printf("call read_info on add<br/>");
31
31
  // multi_read_info(self, curl_multi->multi);
32
32
  // }
33
-
34
- return easy;
33
+
34
+ return easy;
35
35
  }
36
36
 
37
37
  static VALUE multi_remove_handle(VALUE self, VALUE easy) {
38
- CurlEasy *curl_easy;
39
- Data_Get_Struct(easy, CurlEasy, curl_easy);
40
- CurlMulti *curl_multi;
41
- Data_Get_Struct(self, CurlMulti, curl_multi);
42
-
43
- curl_multi->active--;
44
- curl_multi_remove_handle(curl_multi->multi, curl_easy->curl);
45
-
46
- return easy;
38
+ CurlEasy *curl_easy;
39
+ Data_Get_Struct(easy, CurlEasy, curl_easy);
40
+ CurlMulti *curl_multi;
41
+ Data_Get_Struct(self, CurlMulti, curl_multi);
42
+
43
+ curl_multi->active--;
44
+ curl_multi_remove_handle(curl_multi->multi, curl_easy->curl);
45
+
46
+ return easy;
47
47
  }
48
48
 
49
49
  static void multi_read_info(VALUE self, CURLM *multi_handle) {
@@ -51,7 +51,7 @@ static void multi_read_info(VALUE self, CURLM *multi_handle) {
51
51
  CURLMsg *msg;
52
52
  CURLcode ecode;
53
53
  CURL *easy_handle;
54
- VALUE easy;
54
+ VALUE easy;
55
55
 
56
56
  /* check for finished easy handles and remove from the multi handle */
57
57
  while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
@@ -70,29 +70,29 @@ static void multi_read_info(VALUE self, CURLM *multi_handle) {
70
70
 
71
71
  long response_code = -1;
72
72
  curl_easy_getinfo(easy_handle, CURLINFO_RESPONSE_CODE, &response_code);
73
-
74
- // TODO: find out what the real problem is here and fix it.
75
- // this next bit is a horrible hack. For some reason my tests against a local server on my laptop
76
- // fail intermittently and return this result number. However, it will succeed if you try it a few
77
- // more times. Also noteworthy is that this doens't happen when hitting an external server. WTF?!
78
- if (result == 7) {
79
- VALUE max_retries = rb_funcall(easy, rb_intern("max_retries?"), 0);
80
- if (max_retries != Qtrue) {
81
- multi_remove_handle(self, easy);
82
- multi_add_handle(self, easy);
83
- CurlMulti *curl_multi;
84
- Data_Get_Struct(self, CurlMulti, curl_multi);
85
- curl_multi_perform(curl_multi->multi, &(curl_multi->running));
86
-
87
- rb_funcall(easy, rb_intern("increment_retries"), 0);
88
-
89
- continue;
90
- }
91
- }
92
- multi_remove_handle(self, easy);
73
+
74
+ // TODO: find out what the real problem is here and fix it.
75
+ // this next bit is a horrible hack. For some reason my tests against a local server on my laptop
76
+ // fail intermittently and return this result number. However, it will succeed if you try it a few
77
+ // more times. Also noteworthy is that this doens't happen when hitting an external server. WTF?!
78
+ if (result == 7) {
79
+ VALUE max_retries = rb_funcall(easy, rb_intern("max_retries?"), 0);
80
+ if (max_retries != Qtrue) {
81
+ multi_remove_handle(self, easy);
82
+ multi_add_handle(self, easy);
83
+ CurlMulti *curl_multi;
84
+ Data_Get_Struct(self, CurlMulti, curl_multi);
85
+ curl_multi_perform(curl_multi->multi, &(curl_multi->running));
86
+
87
+ rb_funcall(easy, rb_intern("increment_retries"), 0);
88
+
89
+ continue;
90
+ }
91
+ }
92
+ multi_remove_handle(self, easy);
93
93
 
94
94
  if (result != 0) {
95
- rb_funcall(easy, rb_intern("failure"), 0);
95
+ rb_funcall(easy, rb_intern("failure"), 0);
96
96
  }
97
97
  else if ((response_code >= 200 && response_code < 300) || response_code == 0) {
98
98
  rb_funcall(easy, rb_intern("success"), 0);
@@ -113,7 +113,7 @@ static void rb_curl_multi_run(VALUE self, CURLM *multi_handle, int *still_runnin
113
113
  } while (mcode == CURLM_CALL_MULTI_PERFORM);
114
114
 
115
115
  if (mcode != CURLM_OK) {
116
- rb_raise(mcode, "an error occured while running perform");
116
+ rb_raise((VALUE)mcode, "an error occured while running perform");
117
117
  }
118
118
 
119
119
  multi_read_info( self, multi_handle );
@@ -121,7 +121,7 @@ static void rb_curl_multi_run(VALUE self, CURLM *multi_handle, int *still_runnin
121
121
 
122
122
  static VALUE multi_perform(VALUE self) {
123
123
  CURLMcode mcode;
124
- CurlMulti *curl_multi;
124
+ CurlMulti *curl_multi;
125
125
  int maxfd, rc;
126
126
  fd_set fdread, fdwrite, fdexcep;
127
127
 
@@ -131,7 +131,7 @@ static VALUE multi_perform(VALUE self) {
131
131
  Data_Get_Struct(self, CurlMulti, curl_multi);
132
132
 
133
133
  rb_curl_multi_run( self, curl_multi->multi, &(curl_multi->running) );
134
- while(curl_multi->running) {
134
+ while(curl_multi->running) {
135
135
  FD_ZERO(&fdread);
136
136
  FD_ZERO(&fdwrite);
137
137
  FD_ZERO(&fdexcep);
@@ -139,9 +139,9 @@ static VALUE multi_perform(VALUE self) {
139
139
  /* get the curl suggested time out */
140
140
  mcode = curl_multi_timeout(curl_multi->multi, &timeout);
141
141
  if (mcode != CURLM_OK) {
142
- rb_raise(mcode, "an error occured getting the timeout");
143
- }
144
-
142
+ rb_raise((VALUE)mcode, "an error occured getting the timeout");
143
+ }
144
+
145
145
  if (timeout == 0) { /* no delay */
146
146
  rb_curl_multi_run( self, curl_multi->multi, &(curl_multi->running) );
147
147
  continue;
@@ -151,12 +151,12 @@ static VALUE multi_perform(VALUE self) {
151
151
  }
152
152
 
153
153
  tv.tv_sec = timeout / 1000;
154
- tv.tv_usec = (timeout * 1000) % 1000000;
154
+ tv.tv_usec = (timeout * 1000) % 1000000;
155
155
 
156
156
  /* load the fd sets from the multi handle */
157
157
  mcode = curl_multi_fdset(curl_multi->multi, &fdread, &fdwrite, &fdexcep, &maxfd);
158
158
  if (mcode != CURLM_OK) {
159
- rb_raise(mcode, "an error occured getting the fdset");
159
+ rb_raise((VALUE)mcode, "an error occured getting the fdset");
160
160
  }
161
161
 
162
162
  rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &tv);
@@ -171,43 +171,43 @@ static VALUE multi_perform(VALUE self) {
171
171
  }
172
172
 
173
173
  static VALUE active_handle_count(VALUE self) {
174
- CurlMulti *curl_multi;
175
- Data_Get_Struct(self, CurlMulti, curl_multi);
174
+ CurlMulti *curl_multi;
175
+ Data_Get_Struct(self, CurlMulti, curl_multi);
176
176
 
177
- return INT2NUM(curl_multi->active);
177
+ return INT2NUM(curl_multi->active);
178
178
  }
179
179
 
180
180
  static VALUE multi_cleanup(VALUE self) {
181
- CurlMulti *curl_multi;
182
- Data_Get_Struct(self, CurlMulti, curl_multi);
183
-
184
- curl_multi_cleanup(curl_multi->multi);
185
- curl_multi->active = 0;
186
- curl_multi->running = 0;
187
-
188
- return Qnil;
181
+ CurlMulti *curl_multi;
182
+ Data_Get_Struct(self, CurlMulti, curl_multi);
183
+
184
+ curl_multi_cleanup(curl_multi->multi);
185
+ curl_multi->active = 0;
186
+ curl_multi->running = 0;
187
+
188
+ return Qnil;
189
189
  }
190
190
 
191
191
  static VALUE new(int argc, VALUE *argv, VALUE klass) {
192
- CurlMulti *curl_multi = ALLOC(CurlMulti);
193
- curl_multi->multi = curl_multi_init();
194
- curl_multi->active = 0;
195
- curl_multi->running = 0;
192
+ CurlMulti *curl_multi = ALLOC(CurlMulti);
193
+ curl_multi->multi = curl_multi_init();
194
+ curl_multi->active = 0;
195
+ curl_multi->running = 0;
196
196
 
197
- VALUE multi = Data_Wrap_Struct(cTyphoeusMulti, 0, dealloc, curl_multi);
197
+ VALUE multi = Data_Wrap_Struct(cTyphoeusMulti, 0, dealloc, curl_multi);
198
198
 
199
- rb_obj_call_init(multi, argc, argv);
199
+ rb_obj_call_init(multi, argc, argv);
200
200
 
201
- return multi;
201
+ return multi;
202
202
  }
203
203
 
204
204
  void init_typhoeus_multi() {
205
- VALUE klass = cTyphoeusMulti = rb_define_class_under(mTyphoeus, "Multi", rb_cObject);
206
-
207
- rb_define_singleton_method(klass, "new", new, -1);
208
- rb_define_private_method(klass, "multi_add_handle", multi_add_handle, 1);
209
- rb_define_private_method(klass, "multi_remove_handle", multi_remove_handle, 1);
210
- rb_define_private_method(klass, "multi_perform", multi_perform, 0);
211
- rb_define_private_method(klass, "multi_cleanup", multi_cleanup, 0);
212
- rb_define_private_method(klass, "active_handle_count", active_handle_count, 0);
213
- }
205
+ VALUE klass = cTyphoeusMulti = rb_define_class_under(mTyphoeus, "Multi", rb_cObject);
206
+
207
+ rb_define_singleton_method(klass, "new", new, -1);
208
+ rb_define_private_method(klass, "multi_add_handle", multi_add_handle, 1);
209
+ rb_define_private_method(klass, "multi_remove_handle", multi_remove_handle, 1);
210
+ rb_define_private_method(klass, "multi_perform", multi_perform, 0);
211
+ rb_define_private_method(klass, "multi_cleanup", multi_cleanup, 0);
212
+ rb_define_private_method(klass, "active_handle_count", active_handle_count, 0);
213
+ }
@@ -6,11 +6,11 @@
6
6
 
7
7
  VALUE cTyphoeusMulti;
8
8
  typedef struct {
9
- int running;
10
- int active;
11
- CURLM *multi;
9
+ int running;
10
+ int active;
11
+ CURLM *multi;
12
12
  } CurlMulti;
13
13
 
14
14
  void init_typhoeus_multi();
15
15
 
16
- #endif
16
+ #endif
@@ -14,7 +14,7 @@ require 'typhoeus/request'
14
14
  require 'typhoeus/hydra'
15
15
 
16
16
  module Typhoeus
17
- VERSION = "0.1.0"
17
+ VERSION = "0.1.1"
18
18
 
19
19
  def self.easy_object_pool
20
20
  @easy_objects ||= []
@@ -49,6 +49,10 @@ module Typhoeus
49
49
  @on_complete = block
50
50
  end
51
51
 
52
+ def on_complete=(proc)
53
+ @on_complete = proc
54
+ end
55
+
52
56
  def mock(method, url)
53
57
  @mocks << HydraMock.new(url, method)
54
58
  @mocks.last
@@ -50,10 +50,18 @@ module Typhoeus
50
50
  @on_complete = block
51
51
  end
52
52
 
53
+ def on_complete=(proc)
54
+ @on_complete = proc
55
+ end
56
+
53
57
  def after_complete(&block)
54
58
  @after_complete = block
55
59
  end
56
60
 
61
+ def after_complete=(proc)
62
+ @after_complete = proc
63
+ end
64
+
57
65
  def call_handlers
58
66
  if @on_complete
59
67
  @handled_response = @on_complete.call(response)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pauldix-typhoeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix
@@ -62,7 +62,6 @@ files:
62
62
  - spec/servers/method_server.rb
63
63
  has_rdoc: true
64
64
  homepage: http://github.com/pauldix/typhoeus
65
- licenses:
66
65
  post_install_message:
67
66
  rdoc_options: []
68
67
 
@@ -84,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
83
  requirements: []
85
84
 
86
85
  rubyforge_project:
87
- rubygems_version: 1.3.5
86
+ rubygems_version: 1.2.0
88
87
  signing_key:
89
88
  specification_version: 2
90
89
  summary: A library for interacting with web services (and building SOAs) at blinding speed.