/web
Created
October 13, 2008 13:37
Revisions
-
schmidt revised this gist
Jun 1, 2010 . 1 changed file with 38 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,38 @@ #!/usr/bin/env ruby require 'webrick' require 'socket' require 'timeout' # code from http://stackoverflow.com/questions/517219/ruby-see-if-a-port-is-open/517638#517638 def port_in_use?(port) begin Timeout::timeout(1) do begin s = TCPSocket.new('0.0.0.0', port) s.close return true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH return false end end rescue Timeout::Error end return false end def port_above(port) while port_in_use?(port) port += 1 end port end s = WEBrick::HTTPServer.new(:Port => port_above(3000), :DocumentRoot => Dir::pwd) trap("INT") { s.shutdown } s.start -
schmidt created this gist
Oct 13, 2008 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ #!/usr/bin/env ruby require 'webrick' port = 3000 begin s = WEBrick::HTTPServer.new( :Port => port, :DocumentRoot => Dir::pwd ) port += 1 end while s.listeners.size < 2 trap("INT") { s.shutdown } s.start