Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.61 KB | None | 0 0
  1. class LogRouter
  2.  
  3.   def self.start(options, &blk)
  4.     server_options = options['server']
  5.     EM.epoll
  6.     EM.run do
  7.       trap("TERM") { stop }
  8.       trap("INT") { stop }
  9.  
  10.       EventMachine::start_server(server_options[:host], server_options[:port],
  11.                                  EventMachine::RequestRouter::Connection, options) do |c|
  12.         c.on_data do |data|
  13.           data
  14.         end
  15.  
  16.         c.unbind do
  17.           debug [:c_unbind]
  18.         end
  19.       end
  20.     end
  21.   end
  22.  
  23.   def self.stop
  24.     EventMachine.stop
  25.   end
  26.  
  27.   def self.debug(*data)
  28.     require 'pp'
  29.     pp data
  30.     puts
  31.   end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement