aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/sender.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-06-16 11:10:07 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-06-16 11:10:07 +0100
commitaddb611276f434c261391832616b8e576e9fd84b (patch)
treee51f96ff9a0753c628db2a65dbf87fe3f8d8ce21 /lib/mauve/sender.rb
parent8da31cd2258c9516c91189595bdb467a93f5aebd (diff)
* More IPv6 tidying.
* Fixed typo in Processor
Diffstat (limited to 'lib/mauve/sender.rb')
-rw-r--r--lib/mauve/sender.rb39
1 files changed, 25 insertions, 14 deletions
diff --git a/lib/mauve/sender.rb b/lib/mauve/sender.rb
index 6abe44d..0a481d5 100644
--- a/lib/mauve/sender.rb
+++ b/lib/mauve/sender.rb
@@ -70,21 +70,20 @@ module Mauve
list.each do |d,p|
r = []
+ #
+ # Try IPv6 first.
+ #
+ dns.getresources(d, AAAA).map do |a|
+ r << [a.address.to_s, p]
+ end
#
- # Try IPv4 first.
+ # Try IPv4 too.
#
dns.getresources(d, A).each do |a|
r << [a.address.to_s, p]
end
- #
- # Try IPv6 too.
- #
- dns.getresources(d, AAAA).map do |a|
- r << [a.address.to_s, p]
- end
-
results += r unless r.empty?
end
end
@@ -102,7 +101,10 @@ module Mauve
end
end
-
+
+ #
+ # Returns the number of packets sent.
+ #
def send(update, verbose=0)
#
@@ -131,15 +133,24 @@ module Mauve
print "Sending #{update.inspect.chomp} to #{@destinations.join(", ")}\n"
end
+ #
+ # Keep a count of the number of alerts sent.
+ #
+ sent = 0
+
@destinations.each do |ip, port|
begin
- UDPSocket.open(ip.family) do |sock|
- sock.send(data, 0, ip.to_s, port)
- end
- rescue StandardError => ex
- warn "Got #{ex.to_s} whilst trying to send to #{ip} #{port}"
+ UDPSocket.open(ip.family).send(data, 0, ip.to_s, port)
+ sent += 1
+ rescue Errno::ENETUNREACH => ex
+ # Catch and ignore unreachable network errors.
+ warn "Got #{ex.to_s} whilst trying to send to #{ip} #{port}" if verbose > 0
end
end
+
+ raise "Failed to send any packets to any destinations!" unless sent > 0
+
+ sent
end
end
end