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 818d329..77abdc3 100644
--- a/lib/rb/lib/thrift/transport/socket.rb
+++ b/lib/rb/lib/thrift/transport/socket.rb
@@ -63,15 +63,22 @@
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 cfd7c7b..4d129b0 100644
--- a/lib/rb/spec/socket_spec.rb
+++ b/lib/rb/spec/socket_spec.rb
@@ -89,6 +89,12 @@
@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)