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.
- data/ext/typhoeus/native.c +5 -5
- data/ext/typhoeus/native.h +4 -1
- data/ext/typhoeus/typhoeus_easy.c +126 -125
- data/ext/typhoeus/typhoeus_easy.h +7 -7
- data/ext/typhoeus/typhoeus_multi.c +77 -77
- data/ext/typhoeus/typhoeus_multi.h +4 -4
- data/lib/typhoeus.rb +1 -1
- data/lib/typhoeus/hydra.rb +4 -0
- data/lib/typhoeus/request.rb +8 -0
- metadata +2 -3
data/ext/typhoeus/native.c
CHANGED
@@ -4,8 +4,8 @@ VALUE mTyphoeus;
|
|
4
4
|
|
5
5
|
void Init_native()
|
6
6
|
{
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
7
|
+
mTyphoeus = rb_const_get(rb_cObject, rb_intern("Typhoeus"));
|
8
|
+
|
9
|
+
init_typhoeus_easy();
|
10
|
+
init_typhoeus_multi();
|
11
|
+
}
|
data/ext/typhoeus/native.h
CHANGED
@@ -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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
22
|
-
|
21
|
+
CurlEasy *curl_easy;
|
22
|
+
Data_Get_Struct(self, CurlEasy, curl_easy);
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
31
|
-
|
30
|
+
CurlEasy *curl_easy;
|
31
|
+
Data_Get_Struct(self, CurlEasy, curl_easy);
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
39
|
+
char *info_string;
|
40
|
+
CurlEasy *curl_easy;
|
41
|
+
Data_Get_Struct(self, CurlEasy, curl_easy);
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
61
|
+
double info_double = 0;
|
62
|
+
CurlEasy *curl_easy;
|
63
|
+
Data_Get_Struct(self, CurlEasy, curl_easy);
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
long opt = NUM2LONG(info);
|
66
|
+
curl_easy_getinfo(curl_easy->curl, opt, &info_double);
|
67
67
|
|
68
|
-
|
68
|
+
return rb_float_new(info_double);
|
69
69
|
}
|
70
70
|
|
71
71
|
static VALUE easy_perform(VALUE self) {
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
CurlEasy *curl_easy;
|
73
|
+
Data_Get_Struct(self, CurlEasy, curl_easy);
|
74
|
+
curl_easy_perform(curl_easy->curl);
|
75
75
|
|
76
|
-
|
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
|
-
|
81
|
-
|
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
|
-
|
86
|
-
|
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
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
102
|
-
|
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
|
-
|
112
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
125
|
+
curl_easy_reset(curl_easy->curl);
|
125
126
|
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
141
|
-
|
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
|
-
|
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
|
-
|
150
|
-
|
150
|
+
CurlEasy *curl_easy;
|
151
|
+
Data_Get_Struct(self, CurlEasy, curl_easy);
|
151
152
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
-
|
160
|
+
curl_easy_setopt(curl_easy->curl, CURLOPT_INFILESIZE, RSTRING_LEN(data));
|
160
161
|
|
161
|
-
|
162
|
+
return Qnil;
|
162
163
|
}
|
163
164
|
|
164
165
|
static VALUE easy_escape(VALUE self, VALUE data, VALUE length) {
|
165
|
-
|
166
|
-
|
166
|
+
CurlEasy *curl_easy;
|
167
|
+
Data_Get_Struct(self, CurlEasy, curl_easy);
|
167
168
|
|
168
|
-
|
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
|
-
|
173
|
+
return rb_str_new2(curl_version());
|
173
174
|
}
|
174
175
|
|
175
176
|
static VALUE new(int argc, VALUE *argv, VALUE klass) {
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
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
|
-
|
184
|
+
set_response_handlers(easy, curl);
|
184
185
|
|
185
|
-
|
186
|
+
rb_obj_call_init(easy, argc, argv);
|
186
187
|
|
187
|
-
|
188
|
+
return easy;
|
188
189
|
}
|
189
190
|
|
190
191
|
void init_typhoeus_easy() {
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
8
|
+
const char *memory;
|
9
|
+
int size;
|
10
|
+
int read;
|
11
11
|
} RequestChunk;
|
12
12
|
|
13
13
|
typedef struct {
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
7
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
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
|
-
//
|
30
|
+
// printf("call read_info on add<br/>");
|
31
31
|
// multi_read_info(self, curl_multi->multi);
|
32
32
|
// }
|
33
|
-
|
34
|
-
|
33
|
+
|
34
|
+
return easy;
|
35
35
|
}
|
36
36
|
|
37
37
|
static VALUE multi_remove_handle(VALUE self, VALUE easy) {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
175
|
-
|
174
|
+
CurlMulti *curl_multi;
|
175
|
+
Data_Get_Struct(self, CurlMulti, curl_multi);
|
176
176
|
|
177
|
-
|
177
|
+
return INT2NUM(curl_multi->active);
|
178
178
|
}
|
179
179
|
|
180
180
|
static VALUE multi_cleanup(VALUE self) {
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
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
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
-
|
197
|
+
VALUE multi = Data_Wrap_Struct(cTyphoeusMulti, 0, dealloc, curl_multi);
|
198
198
|
|
199
|
-
|
199
|
+
rb_obj_call_init(multi, argc, argv);
|
200
200
|
|
201
|
-
|
201
|
+
return multi;
|
202
202
|
}
|
203
203
|
|
204
204
|
void init_typhoeus_multi() {
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
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
|
+
}
|
data/lib/typhoeus.rb
CHANGED
data/lib/typhoeus/hydra.rb
CHANGED
data/lib/typhoeus/request.rb
CHANGED
@@ -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.
|
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.
|
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.
|