EM.epoll
EM.run do
trap("TERM") { stop(config['pid']) }
trap("INT") { stop(config['pid']) }
Router.config(config)
Router.log.info "Starting VCAP Router (#{Router.version})"
Router.log.info "Listening on: #{inet}:#{port}" if inet && port
Router.inet = inet || VCAP.local_ip(config['local_route'])
Router.port = port
# If the sock paramater is set, this will override the inet/port
# for unix domain sockets
if fn = config['sock']
File.unlink(fn) if File.exists?(fn)
Router.log.info "Listening on unix domain socket: '#{fn}'"
end
# Hack for running on BVTs on Macs which default to 256 FDs per process
if RUBY_PLATFORM =~ /darwin/
begin
Process.setrlimit(Process::RLIMIT_NOFILE, 4096)
rescue => e
Router.log.info "Failed to modify the socket limit: #{e}"
end
end
EM.set_descriptor_table_size(32768) # Requires Root privileges
Router.log.info "Socket Limit:#{EM.set_descriptor_table_size}"
create_pid_file(config['pid'])
NATS.on_error do |e|
if e.kind_of? NATS::ConnectError
Router.log.error("EXITING! NATS connection failed: #{e}")
exit!
else
Router.log.error("NATS problem, #{e}")
end
end
EM.error_handler do |e|
Router.log.error "Eventmachine problem, #{e}"
Router.log.error("#{e.backtrace.join("\n")}")
end
begin
# TCP/IP Socket
Router.server = EM.start_server(inet, port, ClientConnection, false) if inet && port
Router.local_server = EM.start_server(fn, nil, ClientConnection, true) if fn
rescue => e
Router.log.fatal "Problem starting server, #{e}"
exit
end
求教 1,EM.epoll 是什么意思?网上看了似懂非懂的
2, trap("TERM") { stop(config['pid']) } trap("INT") { stop(config['pid']) } 这是什么意思,谢谢