You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by kc...@apache.org on 2008/06/18 03:15:36 UTC
svn commit: r668996 - in /incubator/thrift/trunk/lib/rb:
lib/thrift/transport/socket.rb spec/socket_spec.rb
Author: kclark
Date: Tue Jun 17 18:15:36 2008
New Revision: 668996
URL: http://svn.apache.org/viewvc?rev=668996&view=rev
Log:
Teach Socket how to read_nonblock
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=668996&r1=668995&r2=668996&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:36 2008
@@ -39,13 +39,17 @@
end
end
- def read(sz)
+ def read(sz, nonblock=false)
begin
- data = @handle.recv(sz)
- rescue StandardError
- raise TransportException.new(TransportException::NOT_OPEN)
+ if nonblock
+ data = @handle.read_nonblock(sz)
+ else
+ data = @handle.read(sz)
+ end
+ rescue StandardError => e
+ raise TransportException.new(TransportException::NOT_OPEN, e.message)
end
- if (data.length == 0)
+ if (data.nil? or data.length == 0)
raise TransportException.new(TransportException::UNKNOWN, "Socket: Could not read #{sz} bytes from #{@host}:#{@port}")
end
data
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=668996&r1=668995&r2=668996&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:36 2008
@@ -49,21 +49,21 @@
it "should raise an error when it cannot read from the handle" do
TCPSocket.should_receive(:new).and_return(@handle)
@socket.open
- @handle.should_receive(:recv).with(17).and_raise(StandardError)
+ @handle.should_receive(:read).with(17).and_raise(StandardError)
lambda { @socket.read(17) }.should raise_error(TransportException) { |e| e.type.should == TransportException::NOT_OPEN }
end
it "should raise an error when it reads no data from the handle" do
TCPSocket.should_receive(:new).and_return(@handle)
@socket.open
- @handle.should_receive(:recv).with(17).and_return("")
+ @handle.should_receive(:read).with(17).and_return("")
lambda { @socket.read(17) }.should raise_error(TransportException, "Socket: Could not read 17 bytes from localhost:9090")
end
it "should return the data read when reading from the handle works" do
TCPSocket.should_receive(:new).and_return(@handle)
@socket.open
- @handle.should_receive(:recv).with(17).and_return("test data")
+ @handle.should_receive(:read).with(17).and_return("test data")
@socket.read(17).should == "test data"
end