em-udns 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/em-udns.c +66 -33
- data/lib/em-udns/resolver.rb +0 -2
- data/lib/em-udns/version.rb +1 -1
- data/test/test-em-udns.rb +5 -3
- metadata +4 -4
data/ext/em-udns.c
CHANGED
@@ -16,9 +16,6 @@ static VALUE cRR_SRV;
|
|
16
16
|
static VALUE cRR_NAPTR;
|
17
17
|
|
18
18
|
static VALUE eUdnsError;
|
19
|
-
static VALUE eUdnsTempFail;
|
20
|
-
static VALUE eUdnsNoMem;
|
21
|
-
static VALUE eUdnsBadQuery;
|
22
19
|
|
23
20
|
static ID id_timer;
|
24
21
|
static ID id_queries;
|
@@ -38,6 +35,9 @@ static VALUE symbol_dns_error_protocol;
|
|
38
35
|
static VALUE symbol_dns_error_nxdomain;
|
39
36
|
static VALUE symbol_dns_error_nodata;
|
40
37
|
static VALUE symbol_dns_error_unknown;
|
38
|
+
static VALUE symbol_dns_error_badquery;
|
39
|
+
static VALUE symbol_dns_error_nomem;
|
40
|
+
static VALUE symbol_dns_error_unknown;
|
41
41
|
static VALUE symbol_failed;
|
42
42
|
static VALUE symbol_succeeded;
|
43
43
|
|
@@ -361,20 +361,20 @@ static void dns_result_NAPTR_cb(struct dns_ctx *dns_context, struct dns_rr_naptr
|
|
361
361
|
}
|
362
362
|
|
363
363
|
|
364
|
-
|
364
|
+
VALUE get_dns_error(struct dns_ctx *dns_context)
|
365
365
|
{
|
366
366
|
switch(dns_status(dns_context)) {
|
367
367
|
case DNS_E_TEMPFAIL:
|
368
|
-
|
368
|
+
return symbol_dns_error_tempfail;
|
369
369
|
break;
|
370
370
|
case DNS_E_NOMEM:
|
371
|
-
|
371
|
+
return symbol_dns_error_nomem;
|
372
372
|
break;
|
373
373
|
case DNS_E_BADQUERY:
|
374
|
-
|
374
|
+
return symbol_dns_error_badquery;
|
375
375
|
break;
|
376
376
|
default:
|
377
|
-
|
377
|
+
return symbol_dns_error_unknown;
|
378
378
|
break;
|
379
379
|
}
|
380
380
|
}
|
@@ -385,7 +385,9 @@ VALUE Resolver_submit_A(VALUE self, VALUE rb_domain)
|
|
385
385
|
struct dns_ctx *dns_context;
|
386
386
|
char *domain;
|
387
387
|
VALUE query;
|
388
|
+
VALUE error;
|
388
389
|
struct resolver_query *data;
|
390
|
+
|
389
391
|
|
390
392
|
Data_Get_Struct(self, struct dns_ctx, dns_context);
|
391
393
|
domain = StringValueCStr(rb_domain);
|
@@ -396,11 +398,14 @@ VALUE Resolver_submit_A(VALUE self, VALUE rb_domain)
|
|
396
398
|
data->query = query;
|
397
399
|
|
398
400
|
if (!dns_submit_a4(dns_context, domain, 0, dns_result_A_cb, (void *)data)) {
|
401
|
+
error = get_dns_error(dns_context);
|
399
402
|
xfree(data);
|
400
|
-
|
403
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_failed, error);
|
401
404
|
}
|
402
|
-
|
403
|
-
|
405
|
+
else {
|
406
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
407
|
+
}
|
408
|
+
|
404
409
|
return query;
|
405
410
|
}
|
406
411
|
|
@@ -410,6 +415,7 @@ VALUE Resolver_submit_AAAA(VALUE self, VALUE rb_domain)
|
|
410
415
|
struct dns_ctx *dns_context;
|
411
416
|
char *domain;
|
412
417
|
VALUE query;
|
418
|
+
VALUE error;
|
413
419
|
struct resolver_query *data;
|
414
420
|
|
415
421
|
Data_Get_Struct(self, struct dns_ctx, dns_context);
|
@@ -421,11 +427,14 @@ VALUE Resolver_submit_AAAA(VALUE self, VALUE rb_domain)
|
|
421
427
|
data->query = query;
|
422
428
|
|
423
429
|
if (!dns_submit_a6(dns_context, domain, 0, dns_result_AAAA_cb, (void *)data)) {
|
430
|
+
error = get_dns_error(dns_context);
|
424
431
|
xfree(data);
|
425
|
-
|
432
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_failed, error);
|
426
433
|
}
|
427
|
-
|
428
|
-
|
434
|
+
else {
|
435
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
436
|
+
}
|
437
|
+
|
429
438
|
return query;
|
430
439
|
}
|
431
440
|
|
@@ -435,6 +444,7 @@ VALUE Resolver_submit_PTR(VALUE self, VALUE rb_ip)
|
|
435
444
|
struct dns_ctx *dns_context;
|
436
445
|
char *ip;
|
437
446
|
VALUE query;
|
447
|
+
VALUE error;
|
438
448
|
struct resolver_query *data;
|
439
449
|
struct in_addr addr;
|
440
450
|
struct in6_addr addr6;
|
@@ -451,8 +461,12 @@ VALUE Resolver_submit_PTR(VALUE self, VALUE rb_ip)
|
|
451
461
|
/* It's valid IPv4. */
|
452
462
|
case 1:
|
453
463
|
if (!dns_submit_a4ptr(dns_context, &addr, dns_result_PTR_cb, (void *)data)) {
|
464
|
+
error = get_dns_error(dns_context);
|
454
465
|
xfree(data);
|
455
|
-
|
466
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_failed, error);
|
467
|
+
}
|
468
|
+
else {
|
469
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
456
470
|
}
|
457
471
|
break;
|
458
472
|
/* Invalid IPv4, let's try with IPv6. */
|
@@ -461,20 +475,23 @@ VALUE Resolver_submit_PTR(VALUE self, VALUE rb_ip)
|
|
461
475
|
/* It's valid IPv6. */
|
462
476
|
case 1:
|
463
477
|
if (!dns_submit_a6ptr(dns_context, &addr6, dns_result_PTR_cb, (void *)data)) {
|
478
|
+
error = get_dns_error(dns_context);
|
464
479
|
xfree(data);
|
465
|
-
|
480
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_failed, error);
|
481
|
+
}
|
482
|
+
else {
|
483
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
466
484
|
}
|
467
485
|
break;
|
468
|
-
/* Also an invalid IPv6 so
|
486
|
+
/* Also an invalid IPv6 so the IP is invalid. */
|
469
487
|
case 0:
|
470
488
|
xfree(data);
|
471
|
-
|
489
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_failed, symbol_dns_error_badquery);
|
472
490
|
break;
|
473
491
|
}
|
474
492
|
break;
|
475
493
|
}
|
476
494
|
|
477
|
-
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
478
495
|
return query;
|
479
496
|
}
|
480
497
|
|
@@ -484,6 +501,7 @@ VALUE Resolver_submit_MX(VALUE self, VALUE rb_domain)
|
|
484
501
|
struct dns_ctx *dns_context;
|
485
502
|
char *domain;
|
486
503
|
VALUE query;
|
504
|
+
VALUE error;
|
487
505
|
struct resolver_query *data;
|
488
506
|
|
489
507
|
Data_Get_Struct(self, struct dns_ctx, dns_context);
|
@@ -495,11 +513,14 @@ VALUE Resolver_submit_MX(VALUE self, VALUE rb_domain)
|
|
495
513
|
data->query = query;
|
496
514
|
|
497
515
|
if (!dns_submit_mx(dns_context, domain, 0, dns_result_MX_cb, (void *)data)) {
|
516
|
+
error = get_dns_error(dns_context);
|
498
517
|
xfree(data);
|
499
|
-
|
518
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_failed, error);
|
500
519
|
}
|
501
|
-
|
502
|
-
|
520
|
+
else {
|
521
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
522
|
+
}
|
523
|
+
|
503
524
|
return query;
|
504
525
|
}
|
505
526
|
|
@@ -509,6 +530,7 @@ VALUE Resolver_submit_TXT(VALUE self, VALUE rb_domain)
|
|
509
530
|
struct dns_ctx *dns_context;
|
510
531
|
char *domain;
|
511
532
|
VALUE query;
|
533
|
+
VALUE error;
|
512
534
|
struct resolver_query *data;
|
513
535
|
|
514
536
|
Data_Get_Struct(self, struct dns_ctx, dns_context);
|
@@ -520,11 +542,14 @@ VALUE Resolver_submit_TXT(VALUE self, VALUE rb_domain)
|
|
520
542
|
data->query = query;
|
521
543
|
|
522
544
|
if (!dns_submit_txt(dns_context, domain, DNS_C_IN, 0, dns_result_TXT_cb, (void *)data)) {
|
545
|
+
error = get_dns_error(dns_context);
|
523
546
|
xfree(data);
|
524
|
-
|
547
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_failed, error);
|
525
548
|
}
|
526
|
-
|
527
|
-
|
549
|
+
else {
|
550
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
551
|
+
}
|
552
|
+
|
528
553
|
return query;
|
529
554
|
}
|
530
555
|
|
@@ -536,6 +561,7 @@ VALUE Resolver_submit_SRV(int argc, VALUE *argv, VALUE self)
|
|
536
561
|
char *service = NULL;
|
537
562
|
char *protocol = NULL;
|
538
563
|
VALUE query;
|
564
|
+
VALUE error;
|
539
565
|
struct resolver_query *data;
|
540
566
|
|
541
567
|
if (argc == 1 && TYPE(argv[0]) == T_STRING);
|
@@ -558,11 +584,14 @@ VALUE Resolver_submit_SRV(int argc, VALUE *argv, VALUE self)
|
|
558
584
|
data->query = query;
|
559
585
|
|
560
586
|
if (!dns_submit_srv(dns_context, domain, service, protocol, 0, dns_result_SRV_cb, (void *)data)) {
|
587
|
+
error = get_dns_error(dns_context);
|
561
588
|
xfree(data);
|
562
|
-
|
589
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_failed, error);
|
590
|
+
}
|
591
|
+
else {
|
592
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
563
593
|
}
|
564
594
|
|
565
|
-
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
566
595
|
return query;
|
567
596
|
}
|
568
597
|
|
@@ -572,6 +601,7 @@ VALUE Resolver_submit_NAPTR(VALUE self, VALUE rb_domain)
|
|
572
601
|
struct dns_ctx *dns_context;
|
573
602
|
char *domain;
|
574
603
|
VALUE query;
|
604
|
+
VALUE error;
|
575
605
|
struct resolver_query *data;
|
576
606
|
|
577
607
|
Data_Get_Struct(self, struct dns_ctx, dns_context);
|
@@ -583,11 +613,14 @@ VALUE Resolver_submit_NAPTR(VALUE self, VALUE rb_domain)
|
|
583
613
|
data->query = query;
|
584
614
|
|
585
615
|
if (!dns_submit_naptr(dns_context, domain, 0, dns_result_NAPTR_cb, (void *)data)) {
|
616
|
+
error = get_dns_error(dns_context);
|
586
617
|
xfree(data);
|
587
|
-
|
618
|
+
rb_funcall(query, method_set_deferred_status, 2, symbol_failed, error);
|
588
619
|
}
|
589
|
-
|
590
|
-
|
620
|
+
else {
|
621
|
+
rb_hash_aset(rb_ivar_get(self, id_queries), query, Qtrue);
|
622
|
+
}
|
623
|
+
|
591
624
|
return query;
|
592
625
|
}
|
593
626
|
|
@@ -616,9 +649,6 @@ void Init_em_udns_ext()
|
|
616
649
|
mUdns = rb_define_module_under(mEm, "Udns");
|
617
650
|
|
618
651
|
eUdnsError = rb_define_class_under(mUdns, "UdnsError", rb_eStandardError);
|
619
|
-
eUdnsTempFail = rb_define_class_under(mUdns, "UdnsTempFail", eUdnsError);
|
620
|
-
eUdnsNoMem = rb_define_class_under(mUdns, "UdnsNoMem", eUdnsError);
|
621
|
-
eUdnsBadQuery = rb_define_class_under(mUdns, "UdnsBadQuery", eUdnsError);
|
622
652
|
|
623
653
|
cResolver = rb_define_class_under(mUdns, "Resolver", rb_cObject);
|
624
654
|
rb_define_alloc_func(cResolver, Resolver_alloc);
|
@@ -675,6 +705,9 @@ void Init_em_udns_ext()
|
|
675
705
|
symbol_dns_error_nxdomain = ID2SYM(rb_intern("dns_error_nxdomain"));
|
676
706
|
symbol_dns_error_nodata = ID2SYM(rb_intern("dns_error_nodata"));
|
677
707
|
symbol_dns_error_unknown = ID2SYM(rb_intern("dns_error_unknown"));
|
708
|
+
symbol_dns_error_badquery = ID2SYM(rb_intern("dns_error_badquery"));
|
709
|
+
symbol_dns_error_nomem = ID2SYM(rb_intern("dns_error_nomem"));
|
710
|
+
symbol_dns_error_unknown = ID2SYM(rb_intern("dns_error_unknown"));
|
678
711
|
symbol_failed = ID2SYM(rb_intern("failed"));
|
679
712
|
symbol_succeeded = ID2SYM(rb_intern("succeeded"));
|
680
713
|
|
data/lib/em-udns/resolver.rb
CHANGED
data/lib/em-udns/version.rb
CHANGED
data/test/test-em-udns.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
+
$0 = "test-em-udns.rb"
|
4
|
+
|
3
5
|
require "rubygems"
|
4
6
|
require "em-udns"
|
5
7
|
|
@@ -56,7 +58,7 @@ EM.set_max_timers 100000
|
|
56
58
|
EM.run do
|
57
59
|
|
58
60
|
# Set the nameserver rather than using /etc/resolv.conf.
|
59
|
-
EM::Udns.nameservers = "127.0.0.1"
|
61
|
+
#EM::Udns.nameservers = "127.0.0.1"
|
60
62
|
|
61
63
|
resolver = EM::Udns::Resolver.new
|
62
64
|
EM::Udns.run resolver
|
@@ -98,7 +100,7 @@ EM.run do
|
|
98
100
|
result.each do |rr|
|
99
101
|
puts "- #{rr.inspect}"
|
100
102
|
end
|
101
|
-
puts "(sent: #{sent} / recv: #{recv})"
|
103
|
+
puts "(active queries: #{resolver.active} / sent: #{sent} / recv: #{recv})"
|
102
104
|
if recv == times
|
103
105
|
print_info(times, time_start)
|
104
106
|
exit
|
@@ -107,7 +109,7 @@ EM.run do
|
|
107
109
|
|
108
110
|
query.errback do |error|
|
109
111
|
recv += 1
|
110
|
-
puts "#{Time.now} INFO: errback: error => #{error.inspect} (sent: #{sent} / recv: #{recv})"
|
112
|
+
puts "#{Time.now} INFO: errback: error => #{error.inspect} (active queries: #{resolver.active} / sent: #{sent} / recv: #{recv})"
|
111
113
|
if recv == times
|
112
114
|
print_info(times, time_start)
|
113
115
|
exit
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
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-07-04 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|