lib/packet/packet_master.rb
# method should use worker_key if provided in options hash.
method should use worker_key if provided in options hash.
method should use worker_key if provided in options hash .
def fork_and_load(worker_klass,worker_options = { })
      t_worker_name = worker_klass.worker_name
      worker_pimp = worker_klass.worker_proxy.to_s
      master_read_end,worker_write_end = UNIXSocket.pair(Socket::SOCK_STREAM)
      worker_read_end,master_write_end = UNIXSocket.pair(Socket::SOCK_STREAM)
      option_dump = Marshal.dump(worker_options)
      option_dump_length = option_dump.length
      master_write_end.write(option_dump)
      worker_name_key = gen_worker_key(t_worker_name,worker_options[:worker_key])
      if(!(pid = fork))
        [master_write_end,master_read_end].each { |x| x.close }
        [worker_read_end,worker_write_end].each { |x| enable_nonblock(x) }
        begin
          if(ARGV[0] == 'start' && Object.const_defined?(:SERVER_LOGGER))
            redirect_io(SERVER_LOGGER)
          end
        rescue
          puts $!.backtrace
        end
        exec form_cmd_line(worker_read_end.fileno,worker_write_end.fileno,t_worker_name,option_dump_length)
      end
      Process.detach(pid)
      [master_read_end,master_write_end].each { |x| enable_nonblock(x) }
      if worker_pimp && !worker_pimp.empty?
        require worker_pimp
        pimp_klass = Object.const_get(packet_classify(worker_pimp))
        @live_workers[worker_name_key,master_read_end.fileno] = pimp_klass.new(master_write_end,pid,self)
      else
        t_pimp = Packet::MetaPimp.new(master_write_end,pid,self)
        t_pimp.worker_key = worker_name_key
        t_pimp.worker_name = t_worker_name
        t_pimp.invokable_worker_methods = worker_klass.instance_methods
        @live_workers[worker_name_key,master_read_end.fileno] = t_pimp
      end
      worker_read_end.close
      worker_write_end.close
      read_ios << master_read_end
    end
def fork_and_load ( worker_klass , worker_options = { } ) t_worker_name = worker_klass . worker_name worker_pimp = worker_klass . worker_proxy . to_s master_read_end , worker_write_end = UNIXSocket . pair ( Socket :: SOCK_STREAM ) worker_read_end , master_write_end = UNIXSocket . pair ( Socket :: SOCK_STREAM ) option_dump = Marshal . dump ( worker_options ) option_dump_length = option_dump . length master_write_end . write ( option_dump ) worker_name_key = gen_worker_key ( t_worker_name , worker_options [ :worker_key ] ) if ( ! ( pid = fork ) ) [ master_write_end , master_read_end ] . each { | x | x . close } [ worker_read_end , worker_write_end ] . each { | x | enable_nonblock ( x ) } begin if ( ARGV [ 0 ] == 'start' && Object . const_defined? ( :SERVER_LOGGER ) ) redirect_io ( SERVER_LOGGER ) end rescue puts $! . backtrace end exec form_cmd_line ( worker_read_end . fileno , worker_write_end . fileno , t_worker_name , option_dump_length ) end Process . detach ( pid ) [ master_read_end , master_write_end ] . each { | x | enable_nonblock ( x ) } if worker_pimp && ! worker_pimp . empty? require worker_pimp pimp_klass = Object . const_get ( packet_classify ( worker_pimp ) ) @live_workers [ worker_name_key , master_read_end . fileno ] = pimp_klass . new ( master_write_end , pid , self ) else t_pimp = Packet :: MetaPimp . new ( master_write_end , pid , self ) t_pimp . worker_key = worker_name_key t_pimp . worker_name = t_worker_name t_pimp . invokable_worker_methods = worker_klass . instance_methods @live_workers [ worker_name_key , master_read_end . fileno ] = t_pimp end worker_read_end . close worker_write_end . close read_ios << master_read_end end
method should use worker_key if provided in options hash.
method should use worker_key if provided in options hash .
# socket from which master process is going to read # socket to which master process is going to write
worker_klass
<not_specific>
worker_options
<not_specific>