Also prevent errors when trying to close a @handle twice
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@669010
13f79535-47bb-0310-9956-
ffa450edef68
else
data = @handle.read(sz)
end
+ rescue Errno::EAGAIN => e
+ # let our parent know that the nonblock read failed
+ raise e
rescue StandardError => e
- @handle.close
+ @handle.close unless @handle.closed?
@handle = nil
raise TransportException.new(TransportException::NOT_OPEN, e.message)
end
data
end
+ def read_nonblock(sz)
+ read(sz, true)
+ end
+
def close
- @handle.close unless @handle.nil?
+ @handle.close unless @handle.nil? or @handle.closed?
@handle = nil
end
+
+ def to_io
+ @handle
+ end
end
deprecate_class! :TSocket => Socket
end
def close
- @handle.close unless @handle.nil?
+ @handle.close unless @handle.nil? or @handle.closed?
@handle = nil
end
end
before(:each) do
@socket = Socket.new
- @handle = mock("Handle")
+ @handle = mock("Handle", :closed? => false)
@handle.stub!(:close)
end
end
it "should close the handle when closed" do
- handle = mock("TCPServer")
+ handle = mock("TCPServer", :closed? => false)
TCPServer.should_receive(:new).with(nil, 1234).and_return(handle)
@socket.listen
handle.should_receive(:close)