lib/racoon/firehose.rb in racoon-1.0.0 vs lib/racoon/firehose.rb in racoon-1.0.1

- old
+ new

@@ -8,17 +8,18 @@ require 'zmqmachine' require 'yaml' module Racoon class Firehose - attr_accessor :connections, :feedback_callback + attr_accessor :connections, :feedback_callback, :error_callback def initialize(reactor, address = ZM::Address.new('*', 11555, :tcp), &feedback_callback) @connections = {} @reactor = reactor @address = address @feedback_callback = feedback_callback + @error_callback = nil end def on_attach(socket) socket.bind(@address) end @@ -30,11 +31,11 @@ end end private - def apns(project, bytes, retries=2, &error_callback) + def apns(project, bytes, retries=2) uri = "gateway.#{project[:sandbox] ? 'sandbox.' : ''}push.apple.com" hash = Digest::SHA1.hexdigest("#{project[:name]}-#{project[:certificate]}") begin @connections[hash] ||= { :connection => Racoon::APNS::Connection.new(project[:certificate], uri), @@ -42,10 +43,10 @@ :sandbox => project[:sandbox] } connection = @connections[hash][:connection] connection.connect! unless connection.connected? connection.write(bytes) - connection.read.each(&error_callback) unless error_callback.nil? + connection.read.each(&@error_callback) if @error_callback rescue Errno::EPIPE, OpenSSL::SSL::SSLError, Errno::ECONNRESET connection.disconnect! retry if (retries -= 1) > 0 end end