Add optional host argument to ServerSocket
authorKevin Clark <kclark@apache.org>
Wed, 18 Jun 2008 01:15:45 +0000 (01:15 +0000)
committerKevin Clark <kclark@apache.org>
Wed, 18 Jun 2008 01:15:45 +0000 (01:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@668997 13f79535-47bb-0310-9956-ffa450edef68

lib/rb/lib/thrift/transport/socket.rb
lib/rb/spec/socket_spec.rb

index 818d329..77abdc3 100644 (file)
@@ -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
index cfd7c7b..4d129b0 100644 (file)
@@ -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)