Class: Push::Daemon::ApnsSupport::ConnectionApns
- Inherits:
-
Object
- Object
- Push::Daemon::ApnsSupport::ConnectionApns
- Defined in:
- lib/push/daemon/apns_support/connection_apns.rb
Constant Summary collapse
- IDLE_PERIOD =
30.minutes
Instance Attribute Summary collapse
-
#last_write ⇒ Object
Returns the value of attribute last_write.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
-
#initialize(provider, i = nil) ⇒ ConnectionApns
constructor
A new instance of ConnectionApns.
- #read(num_bytes) ⇒ Object
- #reconnect ⇒ Object
- #select(timeout) ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(provider, i = nil) ⇒ ConnectionApns
Returns a new instance of ConnectionApns.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/push/daemon/apns_support/connection_apns.rb', line 11 def initialize(provider, i=nil) @provider = provider if i # Apns push connection @name = "#{@provider.configuration[:name]}: ConnectionApns #{i}" @host = "gateway.#{provider.configuration[:sandbox] ? 'sandbox.' : ''}push.apple.com" @port = 2195 else @name = "#{@provider.configuration[:name]}: FeedbackReceiver" @host = "feedback.#{provider.configuration[:sandbox] ? 'sandbox.' : ''}push.apple.com" @port = 2196 end written end |
Instance Attribute Details
#last_write ⇒ Object
Returns the value of attribute last_write.
8 9 10 |
# File 'lib/push/daemon/apns_support/connection_apns.rb', line 8 def last_write @last_write end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/push/daemon/apns_support/connection_apns.rb', line 7 def name @name end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
7 8 9 |
# File 'lib/push/daemon/apns_support/connection_apns.rb', line 7 def provider @provider end |
Instance Method Details
#close ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/push/daemon/apns_support/connection_apns.rb', line 31 def close begin @ssl_socket.close if @ssl_socket @tcp_socket.close if @tcp_socket rescue IOError end end |
#connect ⇒ Object
26 27 28 29 |
# File 'lib/push/daemon/apns_support/connection_apns.rb', line 26 def connect @ssl_context = setup_ssl_context @tcp_socket, @ssl_socket = connect_socket end |
#read(num_bytes) ⇒ Object
39 40 41 |
# File 'lib/push/daemon/apns_support/connection_apns.rb', line 39 def read(num_bytes) @ssl_socket.read(num_bytes) end |
#reconnect ⇒ Object
71 72 73 74 |
# File 'lib/push/daemon/apns_support/connection_apns.rb', line 71 def reconnect close @tcp_socket, @ssl_socket = connect_socket end |
#select(timeout) ⇒ Object
43 44 45 |
# File 'lib/push/daemon/apns_support/connection_apns.rb', line 43 def select(timeout) IO.select([@ssl_socket], nil, nil, timeout) end |
#write(data) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/push/daemon/apns_support/connection_apns.rb', line 47 def write(data) reconnect_idle if idle_period_exceeded? retry_count = 0 begin write_data(data) rescue Errno::EPIPE, Errno::ETIMEDOUT, Errno::ECONNRESET, OpenSSL::SSL::SSLError => e retry_count += 1; if retry_count == 1 Push::Daemon.logger.error("[#{@name}] Lost connection to #{@host}:#{@port} (#{e.class.name}), reconnecting...") end if retry_count <= 3 reconnect sleep 1 retry else raise ConnectionError, "#{@name} tried #{retry_count-1} times to reconnect but failed (#{e.class.name})." end end end |