Class: Apns::Persistent::Connection
- Inherits:
-
Object
- Object
- Apns::Persistent::Connection
- Extended by:
- Forwardable
- Defined in:
- lib/apns/persistent/connection.rb
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(uri, certificate, passphrase) ⇒ Connection
constructor
A new instance of Connection.
- #open ⇒ Object
- #opened? ⇒ Boolean
- #readable? ⇒ Boolean
- #reopen ⇒ Object
Constructor Details
#initialize(uri, certificate, passphrase) ⇒ Connection
Returns a new instance of Connection.
12 13 14 15 16 |
# File 'lib/apns/persistent/connection.rb', line 12 def initialize(uri, certificate, passphrase) @uri = URI(uri) @certificate = certificate @passphrase = passphrase end |
Instance Method Details
#close ⇒ Object
28 29 30 31 32 33 |
# File 'lib/apns/persistent/connection.rb', line 28 def close @ssl.close @socket.close @ssl = nil @socket = nil end |
#closed? ⇒ Boolean
44 45 46 |
# File 'lib/apns/persistent/connection.rb', line 44 def closed? !opened? end |
#open ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/apns/persistent/connection.rb', line 18 def open @socket = TCPSocket.new(@uri.host, @uri.port) context = OpenSSL::SSL::SSLContext.new context.key = OpenSSL::PKey::RSA.new(@certificate, @passphrase) context.cert = OpenSSL::X509::Certificate.new(@certificate) @ssl = OpenSSL::SSL::SSLSocket.new(@socket, context) @ssl.sync @ssl.connect end |
#opened? ⇒ Boolean
40 41 42 |
# File 'lib/apns/persistent/connection.rb', line 40 def opened? !(@ssl.nil? || @socket.nil?) end |
#readable? ⇒ Boolean
48 49 50 51 |
# File 'lib/apns/persistent/connection.rb', line 48 def readable? r, w = IO.select([@ssl], [], [@ssl], 1) (r && r[0]) end |
#reopen ⇒ Object
35 36 37 38 |
# File 'lib/apns/persistent/connection.rb', line 35 def reopen close open end |