Method: Packet::Core::CommonMethods#decorate_handler

Defined in:
lib/packet/packet_core.rb

#decorate_handler(t_socket, actually_connected, sock_addr, t_module, &block) ⇒ Object



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/packet/packet_core.rb', line 327

def decorate_handler(t_socket,actually_connected,sock_addr,t_module,&block)
  handler_instance = initialize_handler(t_module)
  after_connection_callbacks = connection_callbacks ? connection_callbacks[:after_connection] : nil
  after_connection_callbacks && after_connection_callbacks.each { |t_callback| self.send(t_callback,handler_instance,t_socket)}
  handler_instance.worker = self
  handler_instance.connection = t_socket
  handler_instance.reactor = self
  handler_instance.invoke_init unless handler_instance.initialized
  unless actually_connected
    handler_instance.unbind
    remove_connection(t_socket)
    return
  end
  handler_instance.signature = binding_str
  # FIXME: An Struct is more fashionable, but will have some performance hit, can use a simple hash here
  # klass = Struct.new(:socket,:instance,:signature,:sock_addr)
  connection_data = { :socket => t_socket,:instance => handler_instance,:signature => binding_str,:sock_addr => sock_addr }
  connections[t_socket.fileno] = connection_data
  # connections[t_socket.fileno] = klass.new(t_socket,handler_instance,handler_instance.signature,sock_addr)

  block.call(handler_instance) if block
  handler_instance.connection_completed #if handler_instance.respond_to?(:connection_completed)
  handler_instance
end