Skip to content

Commit

Permalink
Make json drb data a local. Fix spec. #78
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Mar 6, 2015
1 parent ff4451b commit 3b587e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/cosmos/io/json_drb.rb
Expand Up @@ -26,7 +26,6 @@ module Cosmos
class JsonDRb
MINIMUM_REQUEST_TIME = 0.0001

@@data = ''
@@debug = false

# @return [Integer] The number of JSON-RPC requests processed
Expand Down Expand Up @@ -193,14 +192,15 @@ def self.receive_message(socket, data)
# @param required_num_bytes [Integer] The minimum number of bytes to read
# before returning
def self.get_at_least_x_bytes_of_data(socket, current_data, required_num_bytes)
@data ||= ''
while (current_data.length < required_num_bytes)
begin
socket.read_nonblock(65535, @@data)
if @@data.length == 0
socket.read_nonblock(65535, @data)
if @data.length == 0
current_data.replace('')
return
end
current_data << @@data
current_data << @data
rescue IO::WaitReadable
IO.fast_select([socket], nil, nil, nil)
retry
Expand Down
4 changes: 2 additions & 2 deletions spec/io/json_drb_spec.rb
Expand Up @@ -125,8 +125,8 @@ module Cosmos
it "returns nil if 4 bytes of data aren't available" do
@json.start_service('127.0.0.1', 7777, self)
socket = TCPSocket.open('127.0.0.1',7777)
# Stub recv_nonblock so it returns nothing
allow(socket).to receive(:recv_nonblock) { "" }
# Stub read_nonblock so it returns nothing
allow(socket).to receive(:read_nonblock) { "" }
sleep 0.1
JsonDRb.send_data(socket, "\x00")
response_data = JsonDRb.receive_message(socket, '')
Expand Down

0 comments on commit 3b587e8

Please sign in to comment.