Author: kclark
Date: Tue Jun 17 18:15:45 2008
New Revision: 668997

URL: http://svn.apache.org/viewvc?rev=668997&view=rev
Log:
Add optional host argument to ServerSocket

Modified:
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb
    incubator/thrift/trunk/lib/rb/spec/socket_spec.rb

Modified: incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb?rev=668997&r1=668996&r2=668997&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb Tue Jun 17 
18:15:45 2008
@@ -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

Modified: incubator/thrift/trunk/lib/rb/spec/socket_spec.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/socket_spec.rb?rev=668997&r1=668996&r2=668997&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/socket_spec.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/socket_spec.rb Tue Jun 17 18:15:45 2008
@@ -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)


Reply via email to