Sha256: 99ed49e054697c981af5ff97c1119ca0a9b69e38e0e99e010e3e9c6715e68d2c
Contents?: true
Size: 1.18 KB
Versions: 13
Compression:
Stored size: 1.18 KB
Contents
#!/usr/bin/env ruby # # An example application using our patched Thin and EventMachine. You # can obtain these from: # # https://github.com/stripe/thin.git, and # https://github.com/stripe/eventmachine.git require 'rubygems' require 'einhorn' require 'eventmachine-le' require 'thin' require 'thin/attach_socket' class App def initialize(id) @id = id end def call(env) return [200, {}, "[#{$$}] From server instance #{@id}: Got your request!\n"] end end def einhorn_main puts "Called with #{ARGV.inspect}" fd_count = Einhorn::Worker.einhorn_fd_count unless fd_count > 0 raise "Need to call with at least one bound socket. Try running 'einhorn -b 127.0.0.1:5000,r,n -b 127.0.0.1:5001,r,n #{$0}' and then running 'curl 127.0.0.1:5000' or 'curl 127.0.0.1:5001'" end Einhorn::Worker.graceful_shutdown do puts "#{$$} is now exiting..." exit(0) end Einhorn::Worker.ack! EventMachine.run do (0...fd_count).each do |i| sock = Einhorn::Worker.socket!(i) srv = Thin::Server.new(App.new(i), :backend => Thin::Backends::AttachSocket, :socket => IO.for_fd(sock)) srv.start end end end if $0 == __FILE__ einhorn_main end
Version data entries
13 entries across 13 versions & 1 rubygems