Class: ApnMachine::Server::ServerConnection

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/apnmachine/server/server_connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ServerConnection

Returns a new instance of ServerConnection.



6
7
8
9
10
# File 'lib/apnmachine/server/server_connection.rb', line 6

def initialize(*args)
  super
  @client = args.last
  @disconnected = false
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/apnmachine/server/server_connection.rb', line 4

def client
  @client
end

Instance Method Details

#connected?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/apnmachine/server/server_connection.rb', line 12

def connected?
  !@disconnected
end

#connection_completedObject



24
25
26
# File 'lib/apnmachine/server/server_connection.rb', line 24

def connection_completed
  Config.logger.info "Connection to Apple Servers completed" 
end

#post_initObject



16
17
18
19
20
21
22
# File 'lib/apnmachine/server/server_connection.rb', line 16

def post_init
  start_tls(
    :private_key_file => client.key,
    :cert_chain_file  => client.cert,
    :verify_peer      => false
  )
end

#receive_data(data) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/apnmachine/server/server_connection.rb', line 28

def receive_data(data)
  data_array = data.unpack("ccN")
  Config.logger.info "Error"
  error_response = ErrorResponse.new(*data_array)
  Config.logger.warn(error_response.to_s)
  if client.error_callback
    client.error_callback.call(error_response)
  end
end

#unbindObject



38
39
40
41
42
# File 'lib/apnmachine/server/server_connection.rb', line 38

def unbind
  @disconnected = true
  Config.logger.info "Connection closed"
  client.close_callback.call if client.close_callback
end