From: Kevin Clark Date: Wed, 18 Jun 2008 01:19:04 +0000 (+0000) Subject: rb: Switch from read_nonblock to readpartial to make jruby happy X-Git-Tag: 0.2.0~527 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=fb5c0eb2b3318dc5f0299a9d65c5a9761e0e359f;p=common%2Fthrift.git rb: Switch from read_nonblock to readpartial to make jruby happy git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@669024 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/rb/benchmark/fairness.rb b/lib/rb/benchmark/fairness.rb index a032013f..11a9f049 100644 --- a/lib/rb/benchmark/fairness.rb +++ b/lib/rb/benchmark/fairness.rb @@ -142,7 +142,7 @@ class BenchmarkManager 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 diff --git a/lib/rb/lib/thrift/server/nonblockingserver.rb b/lib/rb/lib/thrift/server/nonblockingserver.rb index 054c4d73..7868bab1 100644 --- a/lib/rb/lib/thrift/server/nonblockingserver.rb +++ b/lib/rb/lib/thrift/server/nonblockingserver.rb @@ -136,12 +136,7 @@ module Thrift 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 @@ module Thrift 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 @@ module Thrift 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 diff --git a/lib/rb/lib/thrift/transport/socket.rb b/lib/rb/lib/thrift/transport/socket.rb index 3d540e48..8d6f1ed2 100644 --- a/lib/rb/lib/thrift/transport/socket.rb +++ b/lib/rb/lib/thrift/transport/socket.rb @@ -42,10 +42,10 @@ module Thrift 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 @@ module Thrift data end - def read_nonblock(sz) + def readpartial(sz) read(sz, true) end