From: Kevin Clark Date: Wed, 18 Jun 2008 01:15:45 +0000 (+0000) Subject: Add optional host argument to ServerSocket X-Git-Tag: 0.2.0~554 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=c67587006f525dc158c3ed044883fabb7c70846e;p=common%2Fthrift.git Add optional host argument to ServerSocket git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@668997 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/rb/lib/thrift/transport/socket.rb b/lib/rb/lib/thrift/transport/socket.rb index 818d329a..77abdc3c 100644 --- a/lib/rb/lib/thrift/transport/socket.rb +++ b/lib/rb/lib/thrift/transport/socket.rb @@ -63,15 +63,22 @@ module Thrift deprecate_class! :TSocket => Socket class ServerSocket < ServerTransport - def initialize(port) - @port = port + # call-seq: initialize(host = nil, port) + def initialize(host_or_port, port = nil) + if port + @host = host_or_port + @port = port + else + @host = nil + @port = host_or_port + end @handle = nil end attr_reader :handle def listen - @handle = TCPServer.new(nil, @port) + @handle = TCPServer.new(@host, @port) end def accept diff --git a/lib/rb/spec/socket_spec.rb b/lib/rb/spec/socket_spec.rb index cfd7c7bf..4d129b04 100644 --- a/lib/rb/spec/socket_spec.rb +++ b/lib/rb/spec/socket_spec.rb @@ -89,6 +89,12 @@ class ThriftSocketSpec < Spec::ExampleGroup @socket.handle.should be_an_instance_of(TCPServer) end + it "should accept an optional host argument" do + @socket = ServerSocket.new('localhost', 1234) + TCPServer.should_receive(:new).with('localhost', 1234) + @socket.listen + end + it "should create a Thrift::Socket to wrap accepted sockets" do handle = mock("TCPServer") TCPServer.should_receive(:new).with(nil, 1234).and_return(handle)