Author: kclark
Date: Thu Jun 26 11:35:15 2008
New Revision: 671979

URL: http://svn.apache.org/viewvc?rev=671979&view=rev
Log:
rb: Add some additional error handling to Thrift::Socket [THRIFT-53]

Author: Kevin Ballard <[EMAIL PROTECTED]>

Modified:
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb
    incubator/thrift/trunk/lib/rb/spec/socket_spec_shared.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=671979&r1=671978&r2=671979&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb Thu Jun 26 
11:35:15 2008
@@ -29,10 +29,11 @@
     end
 
     def open?
-      [EMAIL PROTECTED]
+      [EMAIL PROTECTED] and [EMAIL PROTECTED]
     end
 
     def write(str)
+      raise IOError, "closed stream" unless open?
       begin
         @handle.write(str)
       rescue StandardError
@@ -43,6 +44,7 @@
     end
 
     def read(sz, partial=false)
+      raise IOError, "closed stream" unless open?
       begin
         if partial
           data = @handle.readpartial(sz)

Modified: incubator/thrift/trunk/lib/rb/spec/socket_spec_shared.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/socket_spec_shared.rb?rev=671979&r1=671978&r2=671979&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/socket_spec_shared.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/socket_spec_shared.rb Thu Jun 26 
11:35:15 2008
@@ -49,4 +49,12 @@
     lambda { @socket.write("fail") }.should raise_error
     @socket.should_not be_open
   end
+
+  it "should raise an error when the stream is closed" do
+    @socket.open
+    @handle.stub!(:closed?).and_return(true)
+    @socket.should_not be_open
+    lambda { @socket.write("fail") }.should raise_error(IOError, "closed 
stream")
+    lambda { @socket.read(10) }.should raise_error(IOError, "closed stream")
+  end
 end


Reply via email to