Module: EventMachine::APN::Server
- Defined in:
- lib/em-apn/server.rb
Instance Method Summary collapse
- #post_init ⇒ Object
- #process(headers, payload) ⇒ Object
- #receive_data(data) ⇒ Object
- #ssl_handshake_completed ⇒ Object
- #unbind ⇒ Object
Instance Method Details
#post_init ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/em-apn/server.rb', line 6 def post_init EM::APN.logger.info("Received a new connection") @data = "" start_tls( :cert_chain_file => ENV["APN_CERT"], :private_key_file => ENV["APN_KEY"], :verify_peer => false ) end |
#process(headers, payload) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/em-apn/server.rb', line 38 def process(headers, payload) = "APN RECV #{headers[4]} #{payload}" EM::APN.logger.info() args = Yajl::Parser.parse(payload) # If the alert is 'DISCONNECT', then we fake a bad payload by replying # with an error and disconnecting. if args["aps"]["alert"] == "DISCONNECT" EM::APN.logger.info("Disconnecting") send_data([8, 1, 0].pack("ccN")) close_connection_after_writing end end |
#receive_data(data) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/em-apn/server.rb', line 21 def receive_data(data) @data << data # Try to extract the payload header headers = @data.unpack("cNNnH64n") return if headers.last.nil? # Try to grab the payload payload_size = headers.last payload = @data[45, payload_size] return if payload.length != payload_size @data = @data[45 + payload_size, -1] || "" process(headers, payload) end |
#ssl_handshake_completed ⇒ Object
17 18 19 |
# File 'lib/em-apn/server.rb', line 17 def ssl_handshake_completed EM::APN.logger.info("SSL handshake completed") end |
#unbind ⇒ Object
53 54 55 |
# File 'lib/em-apn/server.rb', line 53 def unbind EM::APN.logger.info("Connection closed") end |