lib/em-jack/connection.rb in em-jack-0.0.9 vs lib/em-jack/connection.rb in em-jack-0.1.0
- old
+ new
@@ -183,11 +183,11 @@
ttr = (opts[:ttr] || 300).to_i
ttr = 300 if ttr < 0
m = msg.to_s
- callback { @conn.send_with_data(:put, m, pri, delay, ttr, m.length) }
+ callback { @conn.send_with_data(:put, m, pri, delay, ttr, m.bytesize) }
add_deferrable(&blk)
end
def each_job(timeout = nil, &blk)
@@ -251,15 +251,19 @@
handles, bytes = h.handles?(first)
next unless handles
bytes = bytes.to_i
- # if this handler requires us to receive a body make sure we can get
- # the full length of body. If not, we'll go around and wait for more
- # data to be received
- body, @data = extract_body!(bytes, @data) unless bytes <= 0
- break if body.nil? && bytes > 0
+ if bytes > 0
+ # if this handler requires us to receive a body make sure we can get
+ # the full length of body. If not, we'll go around and wait for more
+ # data to be received
+ body, @data = extract_body!(bytes, @data) unless bytes <= 0
+ break if body.nil?
+ else
+ @data = @data[(@data.index(/\r\n/) + 2)..-1]
+ end
handled = h.handle(df, first, body, self)
break if handled
end
@@ -267,17 +271,16 @@
# not handled means there wasn't enough data to process a complete response
break unless handled
next unless @data.index(/\r\n/)
- @data = @data[(@data.index(/\r\n/) + 2)..-1]
@data = "" if @data.nil?
end
end
def extract_body!(bytes, data)
rem = data[(data.index(/\r\n/) + 2)..-1]
- return [nil, data] if rem.length < bytes
+ return [nil, data] if rem.bytesize < bytes
body = rem[0..(bytes - 1)]
data = rem[(bytes + 2)..-1]
data = "" if data.nil?