Kouhei Sutou
null+****@clear*****
Tue Jan 7 16:00:39 JST 2014
Kouhei Sutou 2014-01-07 16:00:39 +0900 (Tue, 07 Jan 2014) New Revision: 794afc9269da4ef9249048ecff6bda0aa3de5112 https://github.com/ranguba/gqtp/commit/794afc9269da4ef9249048ecff6bda0aa3de5112 Message: Use "host" instead of "address" Because "host" is more general word rather than "address". GQTP can accept "host name" or "IP address". "host" includes both but "address" includes only "IP address". This is a backward incompatible change. :address option key still usable but it will be removed in the feature. 3rd party connection module doesn't work. Modified files: README.md bin/gqtp-proxy lib/gqtp/client.rb lib/gqtp/connection/coolio.rb lib/gqtp/connection/synchronous.rb lib/gqtp/connection/thread.rb lib/gqtp/error.rb lib/gqtp/proxy.rb lib/gqtp/server.rb test/test-client.rb Modified: README.md (+4 -4) =================================================================== --- README.md 2014-01-07 15:37:17 +0900 (79fa83e) +++ README.md 2014-01-07 16:00:39 +0900 (6ef8c42) @@ -22,7 +22,7 @@ for high concurrency use. ### Client - client = GQTP::Client.new(:address => "192.168.0.1", :port => 10043) + client = GQTP::Client.new(:host => "192.168.0.1", :port => 10043) request = client.send("status") do |header, body| p body # => "{\"alloc_count\":163,...}" end @@ -30,7 +30,7 @@ for high concurrency use. ### Server - server = GQTP::Server.new(:address => "192.168.0.1", :port => 10043) + server = GQTP::Server.new(:host => "192.168.0.1", :port => 10043) server.on_request do |request, client| body = "{\"alloc_count\":163,...}" header = GQTP::Header.new @@ -45,9 +45,9 @@ for high concurrency use. ### Proxy - proxy = GQTP::Proxy.new(:listen_address => "127.0.0.1", + proxy = GQTP::Proxy.new(:listen_host => "127.0.0.1", :listen_port => 10043, - :upstream_address => "192.168.0.1", + :upstream_host => "192.168.0.1", :upstream_port => 10043) proxy.run.wait Modified: bin/gqtp-proxy (+14 -14) =================================================================== --- bin/gqtp-proxy 2014-01-07 15:37:17 +0900 (02a49cf) +++ bin/gqtp-proxy 2014-01-07 16:00:39 +0900 (7ae2a1b) @@ -22,27 +22,27 @@ require "ostruct" require "gqtp" options = OpenStruct.new -options.listen_address = "0.0.0.0" +options.listen_host = "0.0.0.0" options.listen_port = 10043 -options.upstream_address = nil +options.upstream_host = nil options.upstream_port = 10043 options.backend = :thread parser = OptionParser.new -parser.on("--listen-address=ADDRESS", - "IP address or host name to listen", - "(#{options.listen_address})") do |address| - options.listen_address = address +parser.on("--listen-host=HOST", + "IP host or host name to listen", + "(#{options.listen_host})") do |host| + options.listen_host = host end parser.on("--listen-port=PORT", Integer, "Port number to listen", "(#{options.listen_port})") do |port| options.listen_port = port end -parser.on("--upstream-address=ADDRESS", - "IP address or host name of upstream", - "(#{options.upstream_address})") do |address| - options.upstream_address = address +parser.on("--upstream-host=HOST", + "IP host or host name of upstream", + "(#{options.upstream_host})") do |host| + options.upstream_host = host end parser.on("--upstream-port=PORT", Integer, "Port number of upstream", @@ -64,14 +64,14 @@ rescue OptionParser::ParseError exit(false) end -if options.upstream_address.nil? - puts("--upstream-address is required.") +if options.upstream_host.nil? + puts("--upstream-host is required.") exit(false) end -proxy = GQTP::Proxy.new(:listen_address => options.listen_address, +proxy = GQTP::Proxy.new(:listen_host => options.listen_host, :listen_port => options.listen_port, - :upstream_address => options.upstream_address, + :upstream_host => options.upstream_host, :upstream_port => options.upstream_port, :connection => options.backend) proxy.run.wait Modified: lib/gqtp/client.rb (+2 -2) =================================================================== --- lib/gqtp/client.rb 2014-01-07 15:37:17 +0900 (05d8560) +++ lib/gqtp/client.rb 2014-01-07 16:00:39 +0900 (0fa66e3) @@ -21,10 +21,10 @@ require "gqtp/sequential-request" module GQTP class Client - attr_accessor :address, :port + attr_accessor :host, :port def initialize(options={}) @options = options.dup - @options[:address] ||= "127.0.0.1" + @options[:host] ||= @options[:address] || "127.0.0.1" @options[:port] ||= 10043 @connection = create_connection end Modified: lib/gqtp/connection/coolio.rb (+6 -6) =================================================================== --- lib/gqtp/connection/coolio.rb 2014-01-07 15:37:17 +0900 (d66941e) +++ lib/gqtp/connection/coolio.rb 2014-01-07 16:00:39 +0900 (0b45962) @@ -83,13 +83,13 @@ module GQTP end class Client - attr_accessor :address, :port + attr_accessor :host, :port def initialize(options={}) @options = options - @address = options[:address] || "127.0.0.1" + @host = options[:host] || "127.0.0.1" @port = options[:port] || 10043 @loop = options[:loop] || ::Coolio::Loop.default - @socket = Socket.connect(@address, @port) + @socket = Socket.connect(@host, @port) @socket.attach(@loop) end @@ -107,16 +107,16 @@ module GQTP end class Server - attr_accessor :address, :port + attr_accessor :host, :port def initialize(options={}) @options = options - @address = options[:address] || "0.0.0.0" + @host = options[:host] || "0.0.0.0" @port = options[:port] || 10043 @loop = options[:loop] || ::Coolio::Loop.default end def run - @server = ::Coolio::TCPServer.new(@address, @port, Socket) do |client| + @server = ::Coolio::TCPServer.new(@host, @port, Socket) do |client| yield(client) end @server.attach(@loop) Modified: lib/gqtp/connection/synchronous.rb (+7 -7) =================================================================== --- lib/gqtp/connection/synchronous.rb 2014-01-07 15:37:17 +0900 (9f4d7f4) +++ lib/gqtp/connection/synchronous.rb 2014-01-07 16:00:39 +0900 (bb59b30) @@ -58,15 +58,15 @@ module GQTP end class Client - attr_accessor :address, :port + attr_accessor :host, :port def initialize(options={}) @options = options - @address = options[:address] || "127.0.0.1" + @host = options[:host] || "127.0.0.1" @port = options[:port] || 10043 begin - @socket = TCPSocket.open(@address, @port) + @socket = TCPSocket.open(@host, @port) rescue SystemCallError - raise ConnectionError.new(@address, @port, $!) + raise ConnectionError.new(@host, @port, $!) end @io = IO.new(@socket) end @@ -85,16 +85,16 @@ module GQTP end class Server - attr_accessor :address, :port + attr_accessor :host, :port def initialize(options={}) @options = options - @address = options[:address] || "0.0.0.0" + @host = options[:host] || "0.0.0.0" @port = options[:port] || 10043 @backlog = options[:backlog] || 128 end def run - @server = TCPServer.new(@address, @port) + @server = TCPServer.new(@host, @port) @server.listen(@backlog) loop do client =****@serve***** Modified: lib/gqtp/connection/thread.rb (+7 -7) =================================================================== --- lib/gqtp/connection/thread.rb 2014-01-07 15:37:17 +0900 (49ec208) +++ lib/gqtp/connection/thread.rb 2014-01-07 16:00:39 +0900 (5a728a1) @@ -69,15 +69,15 @@ module GQTP end class Client - attr_accessor :address, :port + attr_accessor :host, :port def initialize(options={}) @options = options - @address = options[:address] || "127.0.0.1" + @host = options[:host] || "127.0.0.1" @port = options[:port] || 10043 begin - @socket = TCPSocket.open(@address, @port) + @socket = TCPSocket.open(@host, @port) rescue SystemCallError - raise ConnectionError.new(@address, @port, $!) + raise ConnectionError.new(@host, @port, $!) end @io = IO.new(@socket) end @@ -96,16 +96,16 @@ module GQTP end class Server - attr_accessor :address, :port + attr_accessor :host, :port def initialize(options={}) @options = options - @address = options[:address] || "0.0.0.0" + @host = options[:host] || "0.0.0.0" @port = options[:port] || 10043 @backlog = options[:backlog] || 128 end def run - @server = TCPServer.new(@address, @port) + @server = TCPServer.new(@host, @port) @server.listen(@backlog) thread = ::Thread.new do loop do Modified: lib/gqtp/error.rb (+4 -4) =================================================================== --- lib/gqtp/error.rb 2014-01-07 15:37:17 +0900 (4dd8296) +++ lib/gqtp/error.rb 2014-01-07 16:00:39 +0900 (55c8a09) @@ -21,14 +21,14 @@ module GQTP end class ConnectionError < Error - attr_reader :address + attr_reader :host attr_reader :port attr_reader :detail - def initialize(address, port, detail) - @address = address + def initialize(host, port, detail) + @host = host @port = port @detail = detail - super("Failed to connect to <#{@address}:#{@port}>: " + + super("Failed to connect to <#{@host}:#{@port}>: " + "#{@detail.message} (#{@detail.class})") end end Modified: lib/gqtp/proxy.rb (+8 -6) =================================================================== --- lib/gqtp/proxy.rb 2014-01-07 15:37:17 +0900 (f24059b) +++ lib/gqtp/proxy.rb 2014-01-07 16:00:39 +0900 (7296954) @@ -20,16 +20,18 @@ require "gqtp/server" module GQTP class Proxy - attr_accessor :listen_address, :listen_port - attr_accessor :upstream_address, :upstream_port + attr_accessor :listen_host, :listen_port + attr_accessor :upstream_host, :upstream_port def initialize(options={}) @options = options.dup - @listen_address = @options[:listen_address] || "0.0.0.0" + @listen_host = @options[:listen_host] || @options[:listen_address] + @listen_host ||= "0.0.0.0" @listen_port = @options[:listen_port] || 10043 - @upstream_address = @options[:upstream_address] || "127.0.0.1" + @upstream_host = @options[:upstream_host] || @options[:upstream_address] + @upstream_host ||= "127.0.0.1" @upstream_port = @options[:upstream_port] || 10043 @connection = @options[:connection] || :thread - @server = Server.new(:address => @listen_address, + @server = Server.new(:host => @listen_host, :port => @listen_port, :connection => @connection) end @@ -67,7 +69,7 @@ module GQTP require "gqtp/connection/#{@connection}" module_name =****@conne*****_s.capitalize connection_module = GQTP::Connection::const_get(module_name) - connection_module::Client.new(:address => @upstream_address, + connection_module::Client.new(:host => @upstream_host, :port => @upstream_port) end end Modified: lib/gqtp/server.rb (+2 -2) =================================================================== --- lib/gqtp/server.rb 2014-01-07 15:37:17 +0900 (2f81193) +++ lib/gqtp/server.rb 2014-01-07 16:00:39 +0900 (2da9c52) @@ -20,10 +20,10 @@ require "gqtp/header" module GQTP class Server - attr_accessor :address, :port + attr_accessor :host, :port def initialize(options={}) @options = options.dup - @options[:address] ||= "0.0.0.0" + @options[:host] ||= @options[:address] || "0.0.0.0" @options[:port] ||= 10043 @on_request = nil @on_connect = nil Modified: test/test-client.rb (+6 -6) =================================================================== --- test/test-client.rb 2014-01-07 15:37:17 +0900 (4083417) +++ test/test-client.rb 2014-01-07 16:00:39 +0900 (eea06e8) @@ -40,8 +40,8 @@ class ClientTest < Test::Unit::TestCase class RequestTest < self def setup - @address = "127.0.0.1" - @server = TCPServer.new(@address, 0) + @host = "127.0.0.1" + @server = TCPServer.new(@host, 0) @port =****@serve*****[1] @request_body = nil @@ -74,7 +74,7 @@ class ClientTest < Test::Unit::TestCase class SendTest < self def test_sync @response_body = "[false]" - client = GQTP::Client.new(:address => @address, :port => @port) + client = GQTP::Client.new(:host => @host, :port => @port) client.send("status") header, body = client.read assert_equal(["status", @response_body.bytesize, @response_body], @@ -83,7 +83,7 @@ class ClientTest < Test::Unit::TestCase def test_async @response_body = "[false]" - client = GQTP::Client.new(:address => @address, :port => @port) + client = GQTP::Client.new(:host => @host, :port => @port) request = client.send("status") do |header, body| assert_equal(["status", @response_body.bytesize, @response_body], [@request_body, header.size, body]) @@ -95,13 +95,13 @@ class ClientTest < Test::Unit::TestCase class CloseTest < self def test_sync @response_body = "[]" - client = GQTP::Client.new(:address => @address, :port => @port) + client = GQTP::Client.new(:host => @host, :port => @port) assert_true(client.close) end def test_async @response_body = "[]" - client = GQTP::Client.new(:address => @address, :port => @port) + client = GQTP::Client.new(:host => @host, :port => @port) closed = false close_request = client.close do closed = true -------------- next part -------------- HTML����������������������������... Descargar