Class: Rpush::Daemon::Dispatcher::ApnsTcp

Inherits:
Tcp
  • Object
show all
Includes:
Loggable, Reflectable
Defined in:
lib/rpush/daemon/dispatcher/apns_tcp.rb

Constant Summary collapse

SELECT_TIMEOUT =
10
ERROR_TUPLE_BYTES =
6
APNS_ERRORS =
{
  1 => 'Processing error',
  2 => 'Missing device token',
  3 => 'Missing topic',
  4 => 'Missing payload',
  5 => 'Missing token size',
  6 => 'Missing topic size',
  7 => 'Missing payload size',
  8 => 'Invalid token',
  10 => 'APNs closed connection (possible maintenance)',
  255 => 'None (unknown error)'
}

Instance Method Summary collapse

Methods included from Reflectable

#reflect

Methods included from Loggable

#log_debug, #log_error, #log_info, #log_warn

Constructor Details

#initialize(*args) ⇒ ApnsTcp


23
24
25
26
27
28
# File 'lib/rpush/daemon/dispatcher/apns_tcp.rb', line 23

def initialize(*args)
  super
  @dispatch_mutex = Mutex.new
  @stop_error_receiver = false
  @connection.on_connect { start_error_receiver }
end

Instance Method Details

#cleanupObject


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rpush/daemon/dispatcher/apns_tcp.rb', line 37

def cleanup
  if Rpush.config.push
    # In push mode only a single batch is sent, followed my immediate shutdown.
    # Allow the error receiver time to handle any errors.
    @reconnect_disabled = true
    sleep 1
  end

  @stop_error_receiver = true
  super
  @error_receiver_thread.join if @error_receiver_thread
rescue StandardError => e
  log_error(e)
  reflect(:error, e)
ensure
  @error_receiver_thread = nil
end

#dispatch(payload) ⇒ Object


30
31
32
33
34
35
# File 'lib/rpush/daemon/dispatcher/apns_tcp.rb', line 30

def dispatch(payload)
  @dispatch_mutex.synchronize do
    @delivery_class.new(@app, @connection, payload.batch).perform
    record_batch(payload.batch)
  end
end