12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/apnserver/server.rb', line 12
def start!
EventMachine::run do
puts "#{Time.now} Starting APN Server on #{bind_address}:#{port}"
EM.start_server(bind_address, port, ApnServer::ServerConnection) do |s|
s.queue = @queue
end
EventMachine::PeriodicTimer.new(1) do
unless @queue.empty?
size = @queue.size
size.times do
@queue.pop do |notification|
begin
@client.connect! unless @client.connected?
@client.write(notification)
rescue Errno::EPIPE
puts "Caught Errno::EPIPE adding notification back to queue"
@queue.push(notification)
rescue OpenSSL::SSL::SSLError
puts "Caught OpenSSL Error, closing connecting and adding notification back to queue"
@client.disconnect!
@queue.push(notification)
rescue RuntimeError => e
puts "Unable to handle: #{e}"
end
end
end
end
end
end
end
|