rb: NonblockingServer: Use a select() loop in the acceptor thread

Using a select() loop with a timeout allows the acceptor thread to be shut down
cleanly under JRuby.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@669042 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/spec/socket_spec.rb b/lib/rb/spec/socket_spec.rb
index ed2f56a..3fede96 100644
--- a/lib/rb/spec/socket_spec.rb
+++ b/lib/rb/spec/socket_spec.rb
@@ -69,5 +69,19 @@
     it "should return nil when accepting if there is no handle" do
       @socket.accept.should be_nil
     end
+
+    it "should return true for closed? when appropriate" do
+      handle = mock("TCPServer", :closed? => false)
+      TCPServer.stub!(:new).and_return(handle)
+      @socket.listen
+      @socket.should_not be_closed
+      handle.stub!(:close)
+      @socket.close
+      @socket.should be_closed
+      @socket.listen
+      @socket.should_not be_closed
+      handle.stub!(:closed?).and_return(true)
+      @socket.should be_closed
+    end
   end
 end
diff --git a/lib/rb/spec/unixsocket_spec.rb b/lib/rb/spec/unixsocket_spec.rb
index abc166a..ff5c96c 100644
--- a/lib/rb/spec/unixsocket_spec.rb
+++ b/lib/rb/spec/unixsocket_spec.rb
@@ -66,5 +66,20 @@
     it "should return nil when accepting if there is no handle" do
       @socket.accept.should be_nil
     end
+
+    it "should return true for closed? when appropriate" do
+      handle = mock("UNIXServer", :closed? => false)
+      UNIXServer.stub!(:new).and_return(handle)
+      File.stub!(:delete)
+      @socket.listen
+      @socket.should_not be_closed
+      handle.stub!(:close)
+      @socket.close
+      @socket.should be_closed
+      @socket.listen
+      @socket.should_not be_closed
+      handle.stub!(:closed?).and_return(true)
+      @socket.should be_closed
+    end
   end
 end