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:19:04 UTC
svn commit: r669024 - in /incubator/thrift/trunk/lib/rb:
benchmark/fairness.rb lib/thrift/server/nonblockingserver.rb
lib/thrift/transport/socket.rb
Author: kclark
Date: Tue Jun 17 18:19:04 2008
New Revision: 669024
URL: http://svn.apache.org/viewvc?rev=669024&view=rev
Log:
rb: Switch from read_nonblock to readpartial to make jruby happy
Modified:
incubator/thrift/trunk/lib/rb/benchmark/fairness.rb
incubator/thrift/trunk/lib/rb/lib/thrift/server/nonblockingserver.rb
incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb
Modified: incubator/thrift/trunk/lib/rb/benchmark/fairness.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/benchmark/fairness.rb?rev=669024&r1=669023&r2=669024&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/benchmark/fairness.rb (original)
+++ incubator/thrift/trunk/lib/rb/benchmark/fairness.rb Tue Jun 17 18:19:04 2008
@@ -142,7 +142,7 @@
next if rd.nil?
rd.each do |fd|
begin
- @buffers[fd] << fd.read_nonblock(4096)
+ @buffers[fd] << fd.readpartial(4096)
rescue EOFError
@pool.delete fd
end
Modified: incubator/thrift/trunk/lib/rb/lib/thrift/server/nonblockingserver.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/server/nonblockingserver.rb?rev=669024&r1=669023&r2=669024&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/server/nonblockingserver.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/server/nonblockingserver.rb Tue Jun 17 18:19:04 2008
@@ -136,12 +136,7 @@
end
def read_connection(fd)
- buffer = ''
- begin
- buffer << fd.read_nonblock(4096) while true
- rescue Errno::EAGAIN, EOFError
- @buffers[fd] << buffer
- end
+ @buffers[fd] << fd.readpartial(1048576)
frame = slice_frame!(@buffers[fd])
if frame
@worker_queue.push [:frame, fd, frame]
@@ -167,13 +162,12 @@
def read_signals
# clear the signal pipe
- begin
- @signal_pipes[0].read_nonblock(1024) while true
- rescue Errno::EAGAIN
- end
+ # note that since read_nonblock is broken in jruby,
+ # we can only read up to a set number of signals at once
+ sigstr = @signal_pipes[0].readpartial(1024)
# now read the signals
begin
- loop do
+ sigstr.length.times do
signal, obj = @signal_queue.pop(true)
case signal
when :connection
@@ -185,6 +179,10 @@
end
rescue ThreadError
# out of signals
+ # note that in a perfect world this would never happen, since we're
+ # only reading the number of signals pushed on the pipe, but given the lack
+ # of locks, in theory we could clear the pipe/queue while a new signal is being
+ # placed on the pipe, at which point our next read_signals would hit this error
end
end
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=669024&r1=669023&r2=669024&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:19:04 2008
@@ -42,10 +42,10 @@
end
end
- def read(sz, nonblock=false)
+ def read(sz, partial=false)
begin
- if nonblock
- data = @handle.read_nonblock(sz)
+ if partial
+ data = @handle.readpartial(sz)
else
data = @handle.read(sz)
end
@@ -63,7 +63,7 @@
data
end
- def read_nonblock(sz)
+ def readpartial(sz)
read(sz, true)
end