em-jack 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/em-jack.rb CHANGED
@@ -11,6 +11,6 @@ end
11
11
 
12
12
  module EMJack
13
13
  module VERSION
14
- STRING = '0.0.9'
14
+ STRING = '0.1.0'
15
15
  end
16
16
  end
@@ -3,7 +3,7 @@ require 'eventmachine'
3
3
  module EMJack
4
4
  class BeanstalkConnection < EM::Connection
5
5
  attr_accessor :client
6
-
6
+
7
7
  def connection_completed
8
8
  @client.connected
9
9
  end
@@ -11,18 +11,18 @@ module EMJack
11
11
  def receive_data(data)
12
12
  @client.received(data)
13
13
  end
14
-
14
+
15
15
  def send(command, *args)
16
16
  cmd = command.to_s
17
17
  cmd << " #{args.join(" ")}" unless args.length == 0
18
18
  cmd << "\r\n"
19
19
  send_data(cmd)
20
20
  end
21
-
21
+
22
22
  def send_with_data(command, data, *args)
23
23
  send_data("#{command.to_s} #{args.join(" ")}\r\n#{data}\r\n")
24
24
  end
25
-
25
+
26
26
  def unbind
27
27
  @client.disconnected
28
28
  end
@@ -185,7 +185,7 @@ module EMJack
185
185
 
186
186
  m = msg.to_s
187
187
 
188
- callback { @conn.send_with_data(:put, m, pri, delay, ttr, m.length) }
188
+ callback { @conn.send_with_data(:put, m, pri, delay, ttr, m.bytesize) }
189
189
 
190
190
  add_deferrable(&blk)
191
191
  end
@@ -253,11 +253,15 @@ module EMJack
253
253
  next unless handles
254
254
  bytes = bytes.to_i
255
255
 
256
- # if this handler requires us to receive a body make sure we can get
257
- # the full length of body. If not, we'll go around and wait for more
258
- # data to be received
259
- body, @data = extract_body!(bytes, @data) unless bytes <= 0
260
- break if body.nil? && bytes > 0
256
+ if bytes > 0
257
+ # if this handler requires us to receive a body make sure we can get
258
+ # the full length of body. If not, we'll go around and wait for more
259
+ # data to be received
260
+ body, @data = extract_body!(bytes, @data) unless bytes <= 0
261
+ break if body.nil?
262
+ else
263
+ @data = @data[(@data.index(/\r\n/) + 2)..-1]
264
+ end
261
265
 
262
266
  handled = h.handle(df, first, body, self)
263
267
  break if handled
@@ -269,14 +273,13 @@ module EMJack
269
273
  break unless handled
270
274
  next unless @data.index(/\r\n/)
271
275
 
272
- @data = @data[(@data.index(/\r\n/) + 2)..-1]
273
276
  @data = "" if @data.nil?
274
277
  end
275
278
  end
276
279
 
277
280
  def extract_body!(bytes, data)
278
281
  rem = data[(data.index(/\r\n/) + 2)..-1]
279
- return [nil, data] if rem.length < bytes
282
+ return [nil, data] if rem.bytesize < bytes
280
283
 
281
284
  body = rem[0..(bytes - 1)]
282
285
  data = rem[(bytes + 2)..-1]
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 9
9
- version: 0.0.9
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - dan sinclair
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-25 00:00:00 -04:00
17
+ date: 2010-03-30 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency