Class: Pling::APN::Connection
- Inherits:
-
Object
- Object
- Pling::APN::Connection
- Includes:
- Configurable
- Defined in:
- lib/pling/apn/connection.rb
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #gets(*args, &block) ⇒ Object
-
#initialize(config) ⇒ Connection
constructor
A new instance of Connection.
- #open ⇒ Object
- #open? ⇒ Boolean
- #puts(*args, &block) ⇒ Object
- #read(*args, &block) ⇒ Object
- #reopen ⇒ Object
- #write(*args, &block) ⇒ Object
Constructor Details
#initialize(config) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 |
# File 'lib/pling/apn/connection.rb', line 8 def initialize(config) setup_configuration(config, :require => [:certificate]) open end |
Instance Method Details
#close ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/pling/apn/connection.rb', line 29 def close Pling.logger.info "#{self.class} -- Closing connection in #{Process.pid}" ssl_socket.close rescue true tcp_socket.close rescue true @ssl_socket = @tcp_socket = nil self end |
#closed? ⇒ Boolean
39 40 41 42 43 44 45 46 47 |
# File 'lib/pling/apn/connection.rb', line 39 def closed? return true if ssl_socket.closed? tcp_socket.read_nonblock(1) return false rescue Errno::EAGAIN return false rescue Exception => e return !e..match(/read would block/) end |
#gets(*args, &block) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/pling/apn/connection.rb', line 70 def gets(*args, &block) with_retries do raise IOError, "Connection closed" if closed? ssl_socket.gets(*args, &block) end end |
#open ⇒ Object
13 14 15 16 17 18 |
# File 'lib/pling/apn/connection.rb', line 13 def open Pling.logger.info "#{self.class} -- Opening connection in #{Process.pid}" ssl_socket.connect self end |
#open? ⇒ Boolean
25 26 27 |
# File 'lib/pling/apn/connection.rb', line 25 def open? not closed? end |
#puts(*args, &block) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/pling/apn/connection.rb', line 56 def puts(*args, &block) with_retries do raise IOError, "Connection closed" if closed? ssl_socket.puts(*args, &block) end end |
#read(*args, &block) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/pling/apn/connection.rb', line 63 def read(*args, &block) with_retries do raise IOError, "Connection closed" if closed? ssl_socket.read(*args, &block) end end |
#reopen ⇒ Object
20 21 22 23 |
# File 'lib/pling/apn/connection.rb', line 20 def reopen close open end |
#write(*args, &block) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/pling/apn/connection.rb', line 49 def write(*args, &block) with_retries do raise IOError, "Connection closed" if closed? ssl_socket.write(*args, &block) end end |