Kouhei Sutou
null+****@clear*****
Tue Jan 7 15:37:17 JST 2014
Kouhei Sutou 2014-01-07 15:37:17 +0900 (Tue, 07 Jan 2014) New Revision: 730af931064953d90370fbf1bd07aeeeed7f8391 https://github.com/ranguba/gqtp/commit/730af931064953d90370fbf1bd07aeeeed7f8391 Message: Wrap error on connection to ConnectionError Modified files: lib/gqtp/connection/synchronous.rb lib/gqtp/connection/thread.rb lib/gqtp/error.rb test/test-client.rb Modified: lib/gqtp/connection/synchronous.rb (+5 -1) =================================================================== --- lib/gqtp/connection/synchronous.rb 2014-01-07 15:28:23 +0900 (551a4c7) +++ lib/gqtp/connection/synchronous.rb 2014-01-07 15:37:17 +0900 (9f4d7f4) @@ -63,7 +63,11 @@ module GQTP @options = options @address = options[:address] || "127.0.0.1" @port = options[:port] || 10043 - @socket = TCPSocket.open(@address, @port) + begin + @socket = TCPSocket.open(@address, @port) + rescue SystemCallError + raise ConnectionError.new(@address, @port, $!) + end @io = IO.new(@socket) end Modified: lib/gqtp/connection/thread.rb (+5 -1) =================================================================== --- lib/gqtp/connection/thread.rb 2014-01-07 15:28:23 +0900 (eb42e75) +++ lib/gqtp/connection/thread.rb 2014-01-07 15:37:17 +0900 (49ec208) @@ -74,7 +74,11 @@ module GQTP @options = options @address = options[:address] || "127.0.0.1" @port = options[:port] || 10043 - @socket = TCPSocket.open(@address, @port) + begin + @socket = TCPSocket.open(@address, @port) + rescue SystemCallError + raise ConnectionError.new(@address, @port, $!) + end @io = IO.new(@socket) end Modified: lib/gqtp/error.rb (+13 -2) =================================================================== --- lib/gqtp/error.rb 2014-01-07 15:28:23 +0900 (9661093) +++ lib/gqtp/error.rb 2014-01-07 15:37:17 +0900 (4dd8296) @@ -16,9 +16,20 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -require "gqtp/header" - module GQTP class Error < StandardError end + + class ConnectionError < Error + attr_reader :address + attr_reader :port + attr_reader :detail + def initialize(address, port, detail) + @address = address + @port = port + @detail = detail + super("Failed to connect to <#{@address}:#{@port}>: " + + "#{@detail.message} (#{@detail.class})") + end + end end Modified: test/test-client.rb (+9 -0) =================================================================== --- test/test-client.rb 2014-01-07 15:28:23 +0900 (e217bb2) +++ test/test-client.rb 2014-01-07 15:37:17 +0900 (4083417) @@ -27,6 +27,15 @@ class ClientTest < Test::Unit::TestCase GQTP::Client.new(:connection => "unknown") end end + + def test_no_server + server = TCPServer.new("127.0.0.1", 0) + free_port = server.addr[1] + server.close + assert_raise(GQTP::ConnectionError) do + GQTP::Client.new(:port => free_port) + end + end end class RequestTest < self -------------- next part -------------- HTML����������������������������...下载