em-udns 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/em-udns.c +101 -51
- data/lib/em-udns/version.rb +1 -1
- data/test/test-em-udns.rb +6 -2
- metadata +3 -3
data/ext/em-udns.c
CHANGED
@@ -20,6 +20,31 @@ static VALUE eUdnsTempFail;
|
|
20
20
|
static VALUE eUdnsNoMem;
|
21
21
|
static VALUE eUdnsBadQuery;
|
22
22
|
|
23
|
+
static ID id_timer;
|
24
|
+
static ID id_queries;
|
25
|
+
static ID id_domain;
|
26
|
+
static ID id_priority;
|
27
|
+
static ID id_weight;
|
28
|
+
static ID id_port;
|
29
|
+
static ID id_order;
|
30
|
+
static ID id_preference;
|
31
|
+
static ID id_flags;
|
32
|
+
static ID id_service;
|
33
|
+
static ID id_regexp;
|
34
|
+
static ID id_replacement;
|
35
|
+
|
36
|
+
static VALUE symbol_dns_error_tempfail;
|
37
|
+
static VALUE symbol_dns_error_protocol;
|
38
|
+
static VALUE symbol_dns_error_nxdomain;
|
39
|
+
static VALUE symbol_dns_error_nodata;
|
40
|
+
static VALUE symbol_dns_error_unknown;
|
41
|
+
static VALUE symbol_failed;
|
42
|
+
static VALUE symbol_succeeded;
|
43
|
+
|
44
|
+
static ID method_cancel;
|
45
|
+
static ID method_set_timer;
|
46
|
+
static ID method_set_deferred_status;
|
47
|
+
|
23
48
|
|
24
49
|
void Resolver_free(struct dns_ctx *dns_context)
|
25
50
|
{
|
@@ -56,14 +81,14 @@ void timer_cb(struct dns_ctx *dns_context, int timeout, void *data)
|
|
56
81
|
VALUE timer;
|
57
82
|
|
58
83
|
resolver = (VALUE)data;
|
59
|
-
timer = rb_ivar_get(resolver,
|
84
|
+
timer = rb_ivar_get(resolver, id_timer);
|
60
85
|
|
61
86
|
/* Cancel the EM::Timer. */
|
62
87
|
if (TYPE(timer) != T_NIL)
|
63
|
-
rb_funcall(timer,
|
88
|
+
rb_funcall(timer, method_cancel, 0);
|
64
89
|
|
65
90
|
if (timeout >= 0)
|
66
|
-
rb_funcall(resolver,
|
91
|
+
rb_funcall(resolver, method_set_timer, 1, INT2FIX(timeout));
|
67
92
|
}
|
68
93
|
|
69
94
|
|
@@ -118,7 +143,7 @@ VALUE Resolver_cancel(VALUE self, VALUE query)
|
|
118
143
|
VALUE queries;
|
119
144
|
VALUE value;
|
120
145
|
|
121
|
-
queries = rb_ivar_get(self,
|
146
|
+
queries = rb_ivar_get(self, id_queries);
|
122
147
|
if (TYPE(rb_hash_aref(queries, query)) == T_TRUE) {
|
123
148
|
rb_hash_aset(queries, query, Qfalse);
|
124
149
|
return Qtrue;
|
@@ -149,7 +174,7 @@ static void* check_query(struct dns_ctx *dns_context, void *rr, void *data)
|
|
149
174
|
query = ((struct resolver_query*)data)->query;
|
150
175
|
xfree(data);
|
151
176
|
|
152
|
-
query_value_in_hash = rb_hash_delete(rb_ivar_get(resolver,
|
177
|
+
query_value_in_hash = rb_hash_delete(rb_ivar_get(resolver, id_queries), query);
|
153
178
|
/* Got response belongs to a query already removed (shouldn't occur). Ignore. */
|
154
179
|
if (query_value_in_hash == Qnil) {
|
155
180
|
if (rr) free(rr);
|
@@ -165,22 +190,22 @@ static void* check_query(struct dns_ctx *dns_context, void *rr, void *data)
|
|
165
190
|
if (rr) free(rr);
|
166
191
|
switch(status) {
|
167
192
|
case DNS_E_TEMPFAIL:
|
168
|
-
error =
|
193
|
+
error = symbol_dns_error_tempfail;
|
169
194
|
break;
|
170
195
|
case DNS_E_PROTOCOL:
|
171
|
-
error =
|
196
|
+
error = symbol_dns_error_protocol;
|
172
197
|
break;
|
173
198
|
case DNS_E_NXDOMAIN:
|
174
|
-
error =
|
199
|
+
error = symbol_dns_error_nxdomain;
|
175
200
|
break;
|
176
201
|
case DNS_E_NODATA:
|
177
|
-
error =
|
202
|
+
error = symbol_dns_error_nodata;
|
178
203
|
break;
|
179
204
|
default:
|
180
|
-
error =
|
205
|
+
error = symbol_dns_error_unknown;
|
181
206
|
break;
|
182
207
|
}
|
183
|
-
rb_funcall(query,
|
208
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_failed, error);
|
184
209
|
return NULL;
|
185
210
|
}
|
186
211
|
|
@@ -202,7 +227,7 @@ static void dns_result_A_cb(struct dns_ctx *dns_context, struct dns_rr_a4 *rr, v
|
|
202
227
|
rb_ary_push(array, rb_str_new2((char *)dns_ntop(AF_INET, &(rr->dnsa4_addr[i].s_addr), ip, INET_ADDRSTRLEN)));
|
203
228
|
free(rr);
|
204
229
|
|
205
|
-
rb_funcall(query,
|
230
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_succeeded, array);
|
206
231
|
}
|
207
232
|
|
208
233
|
|
@@ -220,7 +245,7 @@ static void dns_result_AAAA_cb(struct dns_ctx *dns_context, struct dns_rr_a6 *rr
|
|
220
245
|
rb_ary_push(array, rb_str_new2((char *)dns_ntop(AF_INET6, &(rr->dnsa6_addr[i].s6_addr), ip, INET6_ADDRSTRLEN)));
|
221
246
|
free(rr);
|
222
247
|
|
223
|
-
rb_funcall(query,
|
248
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_succeeded, array);
|
224
249
|
}
|
225
250
|
|
226
251
|
|
@@ -237,7 +262,7 @@ static void dns_result_PTR_cb(struct dns_ctx *dns_context, struct dns_rr_ptr *rr
|
|
237
262
|
rb_ary_push(array, rb_str_new2(rr->dnsptr_ptr[i]));
|
238
263
|
free(rr);
|
239
264
|
|
240
|
-
rb_funcall(query,
|
265
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_succeeded, array);
|
241
266
|
}
|
242
267
|
|
243
268
|
|
@@ -253,13 +278,13 @@ static void dns_result_MX_cb(struct dns_ctx *dns_context, struct dns_rr_mx *rr,
|
|
253
278
|
array = rb_ary_new2(rr->dnsmx_nrr);
|
254
279
|
for(i = 0; i < rr->dnsmx_nrr; i++) {
|
255
280
|
rr_mx = rb_obj_alloc(cRR_MX);
|
256
|
-
rb_ivar_set(rr_mx,
|
257
|
-
rb_ivar_set(rr_mx,
|
281
|
+
rb_ivar_set(rr_mx, id_domain, rb_str_new2(rr->dnsmx_mx[i].name));
|
282
|
+
rb_ivar_set(rr_mx, id_priority, INT2FIX(rr->dnsmx_mx[i].priority));
|
258
283
|
rb_ary_push(array, rr_mx);
|
259
284
|
}
|
260
285
|
free(rr);
|
261
286
|
|
262
|
-
rb_funcall(query,
|
287
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_succeeded, array);
|
263
288
|
}
|
264
289
|
|
265
290
|
|
@@ -276,7 +301,7 @@ static void dns_result_TXT_cb(struct dns_ctx *dns_context, struct dns_rr_txt *rr
|
|
276
301
|
rb_ary_push(array, rb_str_new(rr->dnstxt_txt[i].txt, rr->dnstxt_txt[i].len));
|
277
302
|
free(rr);
|
278
303
|
|
279
|
-
rb_funcall(query,
|
304
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_succeeded, array);
|
280
305
|
}
|
281
306
|
|
282
307
|
|
@@ -292,15 +317,15 @@ static void dns_result_SRV_cb(struct dns_ctx *dns_context, struct dns_rr_srv *rr
|
|
292
317
|
array = rb_ary_new2(rr->dnssrv_nrr);
|
293
318
|
for(i = 0; i < rr->dnssrv_nrr; i++) {
|
294
319
|
rr_srv = rb_obj_alloc(cRR_SRV);
|
295
|
-
rb_ivar_set(rr_srv,
|
296
|
-
rb_ivar_set(rr_srv,
|
297
|
-
rb_ivar_set(rr_srv,
|
298
|
-
rb_ivar_set(rr_srv,
|
320
|
+
rb_ivar_set(rr_srv, id_domain, rb_str_new2(rr->dnssrv_srv[i].name));
|
321
|
+
rb_ivar_set(rr_srv, id_priority, INT2FIX(rr->dnssrv_srv[i].priority));
|
322
|
+
rb_ivar_set(rr_srv, id_weight, INT2FIX(rr->dnssrv_srv[i].weight));
|
323
|
+
rb_ivar_set(rr_srv, id_port, INT2FIX(rr->dnssrv_srv[i].port));
|
299
324
|
rb_ary_push(array, rr_srv);
|
300
325
|
}
|
301
326
|
free(rr);
|
302
327
|
|
303
|
-
rb_funcall(query,
|
328
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_succeeded, array);
|
304
329
|
}
|
305
330
|
|
306
331
|
|
@@ -316,23 +341,23 @@ static void dns_result_NAPTR_cb(struct dns_ctx *dns_context, struct dns_rr_naptr
|
|
316
341
|
array = rb_ary_new2(rr->dnsnaptr_nrr);
|
317
342
|
for(i = 0; i < rr->dnsnaptr_nrr; i++) {
|
318
343
|
rr_naptr = rb_obj_alloc(cRR_NAPTR);
|
319
|
-
rb_ivar_set(rr_naptr,
|
320
|
-
rb_ivar_set(rr_naptr,
|
321
|
-
rb_ivar_set(rr_naptr,
|
322
|
-
rb_ivar_set(rr_naptr,
|
344
|
+
rb_ivar_set(rr_naptr, id_order, INT2FIX(rr->dnsnaptr_naptr[i].order));
|
345
|
+
rb_ivar_set(rr_naptr, id_preference, INT2FIX(rr->dnsnaptr_naptr[i].preference));
|
346
|
+
rb_ivar_set(rr_naptr, id_flags, rb_str_new2(rr->dnsnaptr_naptr[i].flags));
|
347
|
+
rb_ivar_set(rr_naptr, id_service, rb_str_new2(rr->dnsnaptr_naptr[i].service));
|
323
348
|
if (strlen(rr->dnsnaptr_naptr[i].regexp) > 0)
|
324
|
-
rb_ivar_set(rr_naptr,
|
349
|
+
rb_ivar_set(rr_naptr, id_regexp, rb_str_new2(rr->dnsnaptr_naptr[i].regexp));
|
325
350
|
else
|
326
|
-
rb_ivar_set(rr_naptr,
|
351
|
+
rb_ivar_set(rr_naptr, id_regexp, Qnil);
|
327
352
|
if (strlen(rr->dnsnaptr_naptr[i].replacement) > 0)
|
328
|
-
rb_ivar_set(rr_naptr,
|
353
|
+
rb_ivar_set(rr_naptr, id_replacement, rb_str_new2(rr->dnsnaptr_naptr[i].replacement));
|
329
354
|
else
|
330
|
-
rb_ivar_set(rr_naptr,
|
355
|
+
rb_ivar_set(rr_naptr, id_replacement, Qnil);
|
331
356
|
rb_ary_push(array, rr_naptr);
|
332
357
|
}
|
333
358
|
free(rr);
|
334
359
|
|
335
|
-
rb_funcall(query,
|
360
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_succeeded, array);
|
336
361
|
}
|
337
362
|
|
338
363
|
|
@@ -375,7 +400,7 @@ VALUE Resolver_submit_A(VALUE self, VALUE rb_domain)
|
|
375
400
|
raise_dns_error(dns_context);
|
376
401
|
}
|
377
402
|
|
378
|
-
rb_hash_aset(rb_ivar_get(self,
|
403
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
379
404
|
return query;
|
380
405
|
}
|
381
406
|
|
@@ -400,7 +425,7 @@ VALUE Resolver_submit_AAAA(VALUE self, VALUE rb_domain)
|
|
400
425
|
raise_dns_error(dns_context);
|
401
426
|
}
|
402
427
|
|
403
|
-
rb_hash_aset(rb_ivar_get(self,
|
428
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
404
429
|
return query;
|
405
430
|
}
|
406
431
|
|
@@ -449,7 +474,7 @@ VALUE Resolver_submit_PTR(VALUE self, VALUE rb_ip)
|
|
449
474
|
break;
|
450
475
|
}
|
451
476
|
|
452
|
-
rb_hash_aset(rb_ivar_get(self,
|
477
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
453
478
|
return query;
|
454
479
|
}
|
455
480
|
|
@@ -474,7 +499,7 @@ VALUE Resolver_submit_MX(VALUE self, VALUE rb_domain)
|
|
474
499
|
raise_dns_error(dns_context);
|
475
500
|
}
|
476
501
|
|
477
|
-
rb_hash_aset(rb_ivar_get(self,
|
502
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
478
503
|
return query;
|
479
504
|
}
|
480
505
|
|
@@ -499,7 +524,7 @@ VALUE Resolver_submit_TXT(VALUE self, VALUE rb_domain)
|
|
499
524
|
raise_dns_error(dns_context);
|
500
525
|
}
|
501
526
|
|
502
|
-
rb_hash_aset(rb_ivar_get(self,
|
527
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
503
528
|
return query;
|
504
529
|
}
|
505
530
|
|
@@ -537,7 +562,7 @@ VALUE Resolver_submit_SRV(int argc, VALUE *argv, VALUE self)
|
|
537
562
|
raise_dns_error(dns_context);
|
538
563
|
}
|
539
564
|
|
540
|
-
rb_hash_aset(rb_ivar_get(self,
|
565
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
541
566
|
return query;
|
542
567
|
}
|
543
568
|
|
@@ -562,26 +587,26 @@ VALUE Resolver_submit_NAPTR(VALUE self, VALUE rb_domain)
|
|
562
587
|
raise_dns_error(dns_context);
|
563
588
|
}
|
564
589
|
|
565
|
-
rb_hash_aset(rb_ivar_get(self,
|
590
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
566
591
|
return query;
|
567
592
|
}
|
568
593
|
|
569
594
|
|
570
595
|
/* Attribute readers. */
|
571
|
-
VALUE RR_MX_domain(VALUE self) { return rb_ivar_get(self,
|
572
|
-
VALUE RR_MX_priority(VALUE self) { return rb_ivar_get(self,
|
596
|
+
VALUE RR_MX_domain(VALUE self) { return rb_ivar_get(self, id_domain); }
|
597
|
+
VALUE RR_MX_priority(VALUE self) { return rb_ivar_get(self, id_priority); }
|
573
598
|
|
574
|
-
VALUE RR_SRV_priority(VALUE self) { return rb_ivar_get(self,
|
575
|
-
VALUE RR_SRV_weight(VALUE self) { return rb_ivar_get(self,
|
576
|
-
VALUE RR_SRV_port(VALUE self) { return rb_ivar_get(self,
|
577
|
-
VALUE RR_SRV_domain(VALUE self) { return rb_ivar_get(self,
|
599
|
+
VALUE RR_SRV_priority(VALUE self) { return rb_ivar_get(self, id_priority); }
|
600
|
+
VALUE RR_SRV_weight(VALUE self) { return rb_ivar_get(self, id_weight); }
|
601
|
+
VALUE RR_SRV_port(VALUE self) { return rb_ivar_get(self, id_port); }
|
602
|
+
VALUE RR_SRV_domain(VALUE self) { return rb_ivar_get(self, id_domain); }
|
578
603
|
|
579
|
-
VALUE RR_NAPTR_order(VALUE self) { return rb_ivar_get(self,
|
580
|
-
VALUE RR_NAPTR_preference(VALUE self) { return rb_ivar_get(self,
|
581
|
-
VALUE RR_NAPTR_flags(VALUE self) { return rb_ivar_get(self,
|
582
|
-
VALUE RR_NAPTR_service(VALUE self) { return rb_ivar_get(self,
|
583
|
-
VALUE RR_NAPTR_regexp(VALUE self) { return rb_ivar_get(self,
|
584
|
-
VALUE RR_NAPTR_replacement(VALUE self) { return rb_ivar_get(self,
|
604
|
+
VALUE RR_NAPTR_order(VALUE self) { return rb_ivar_get(self, id_order); }
|
605
|
+
VALUE RR_NAPTR_preference(VALUE self) { return rb_ivar_get(self, id_preference); }
|
606
|
+
VALUE RR_NAPTR_flags(VALUE self) { return rb_ivar_get(self, id_flags); }
|
607
|
+
VALUE RR_NAPTR_service(VALUE self) { return rb_ivar_get(self, id_service); }
|
608
|
+
VALUE RR_NAPTR_regexp(VALUE self) { return rb_ivar_get(self, id_regexp); }
|
609
|
+
VALUE RR_NAPTR_replacement(VALUE self) { return rb_ivar_get(self, id_replacement); }
|
585
610
|
|
586
611
|
|
587
612
|
void Init_em_udns_ext()
|
@@ -631,4 +656,29 @@ void Init_em_udns_ext()
|
|
631
656
|
rb_define_method(cRR_NAPTR, "service", RR_NAPTR_service, 0);
|
632
657
|
rb_define_method(cRR_NAPTR, "regexp", RR_NAPTR_regexp, 0);
|
633
658
|
rb_define_method(cRR_NAPTR, "replacement", RR_NAPTR_replacement, 0);
|
659
|
+
|
660
|
+
id_timer = rb_intern("@timer");
|
661
|
+
id_queries = rb_intern("@queries");
|
662
|
+
id_domain = rb_intern("@domain");
|
663
|
+
id_priority = rb_intern("@priority");
|
664
|
+
id_weight = rb_intern("@weight");
|
665
|
+
id_port = rb_intern("@port");
|
666
|
+
id_order = rb_intern("@order");
|
667
|
+
id_preference = rb_intern("@preference");
|
668
|
+
id_flags = rb_intern("@flags");
|
669
|
+
id_service = rb_intern("@service");
|
670
|
+
id_regexp = rb_intern("@regexp");
|
671
|
+
id_replacement = rb_intern("@replacement");
|
672
|
+
|
673
|
+
symbol_dns_error_tempfail = ID2SYM(rb_intern("dns_error_tempfail"));
|
674
|
+
symbol_dns_error_protocol = ID2SYM(rb_intern("dns_error_protocol"));
|
675
|
+
symbol_dns_error_nxdomain = ID2SYM(rb_intern("dns_error_nxdomain"));
|
676
|
+
symbol_dns_error_nodata = ID2SYM(rb_intern("dns_error_nodata"));
|
677
|
+
symbol_dns_error_unknown = ID2SYM(rb_intern("dns_error_unknown"));
|
678
|
+
symbol_failed = ID2SYM(rb_intern("failed"));
|
679
|
+
symbol_succeeded = ID2SYM(rb_intern("succeeded"));
|
680
|
+
|
681
|
+
method_cancel = rb_intern("cancel");
|
682
|
+
method_set_timer = rb_intern("set_timer");
|
683
|
+
method_set_deferred_status = rb_intern("set_deferred_status");
|
634
684
|
}
|
data/lib/em-udns/version.rb
CHANGED
data/test/test-em-udns.rb
CHANGED
@@ -56,7 +56,7 @@ EM.set_max_timers 100000
|
|
56
56
|
EM.run do
|
57
57
|
|
58
58
|
# Set the nameserver rather than using /etc/resolv.conf.
|
59
|
-
|
59
|
+
EM::Udns.nameservers = "127.0.0.1"
|
60
60
|
|
61
61
|
resolver = EM::Udns::Resolver.new
|
62
62
|
EM::Udns.run resolver
|
@@ -94,7 +94,11 @@ EM.run do
|
|
94
94
|
|
95
95
|
query.callback do |result|
|
96
96
|
recv += 1
|
97
|
-
puts "#{Time.now} INFO: callback: result =>
|
97
|
+
puts "#{Time.now} INFO: callback: result =>"
|
98
|
+
result.each do |rr|
|
99
|
+
puts "- #{rr.inspect}"
|
100
|
+
end
|
101
|
+
puts "(sent: #{sent} / recv: #{recv})"
|
98
102
|
if recv == times
|
99
103
|
print_info(times, time_start)
|
100
104
|
exit
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 7
|
9
|
+
version: 0.1.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "I\xC3\xB1aki Baz Castillo"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-04-
|
17
|
+
date: 2011-04-22 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|