Module: APND::Daemon::Protocol
- Included in:
- ServerConnection
- Defined in:
- lib/apnd/daemon/protocol.rb
Overview
Daemon::Protocol handles incoming APNs
Instance Method Summary collapse
-
#post_init ⇒ Object
Called when a client connection is opened.
-
#receive_data(data) ⇒ Object
Add incoming notification(s) to @buffer.
-
#unbind ⇒ Object
Called when a client connection is closed.
Instance Method Details
#post_init ⇒ Object
Called when a client connection is opened
12 13 14 15 |
# File 'lib/apnd/daemon/protocol.rb', line 12 def post_init @address = ::Socket.unpack_sockaddr_in(self.get_peername) APND.ohai "#{@address.last}:#{@address.first} opened connection" end |
#receive_data(data) ⇒ Object
Add incoming notification(s) to @buffer
38 39 40 41 |
# File 'lib/apnd/daemon/protocol.rb', line 38 def receive_data(data) APND.ohai "#{@address.last}:#{@address.first} buffering data" (@buffer ||= "") << data end |
#unbind ⇒ Object
Called when a client connection is closed
Checks @buffer for any pending notifications to be queued
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/apnd/daemon/protocol.rb', line 23 def unbind @buffer.chomp.split("\n").each do |line| if notification = APND::Notification.valid?(line) APND.ohai "#{@address.last}:#{@address.first} added new Notification to queue" queue.push(notification) else APND.ohai "#{@address.last}:#{@address.first} submitted invalid Notification" end end APND.ohai "#{@address.last}:#{@address.first} closed connection" end |