def Iowa.run()
mylog = Logger['iowa_log']
if @@config['socket'].has_key? 'port'
socket_host = @@config['socket']['hostname']
socket_port = @@config['socket']['port']
begin
TCPServer.do_not_reverse_lookup = true
if socket_host.to_s == ''
server = TCPserver.new(socket_port)
mylog.info "Listening at localhost:#{socket_port}."
else
server = TCPserver.new(socket_host,socket_port)
mylog.info "Listening at #{socket_host}:#{socket_port}."
end
rescue Exception => exception
mylog.fatal "Failure while attempting to establish a TCP socket at #{socket_host}:#{socket_port} : #{exception}"
raise
end
else
begin
server = UNIXServer.new(@@config['socket']['path'])
File.chmod(0666, @@config['socket']['path'])
mylog.info "Listening on #{@@config['socket']['path']}."
rescue Exception => exception
mylog.fatal "Failure while attemting to establish a Unix socket at #{@@config['socket']['path']} : #{exception}"
raise
end
end
app.initialLoad()
begin
mylog.info 'Entering the main event loop...'
loop do
socket = server.accept
Thread.start {handleConnection socket}
end
rescue Exception => exception
mylog.fatal "Catastrophic failure in main event loop: #{exception} :: " + exception.backtrace.join(".....").to_s
ensure
server.close
File.delete(@@config['socket']['path']) if @@config['socket'].has_key? 'path'
end
end