AdoccaMemcache 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/am_memcache.rb +30 -14
  3. metadata +3 -3
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
  require './lib/adocca_memcache.rb'
6
6
 
7
- Hoe.new('AdoccaMemcache', '0.1.8') do |p|
7
+ Hoe.new('AdoccaMemcache', '0.1.9') do |p|
8
8
  p.rubyforge_name = 'adocca-plugins'
9
9
  p.author = 'adocca Entertainment AB'
10
10
  p.summary = 'A client library to simplify using memcached with Ruby on Rails projects.'
@@ -143,8 +143,8 @@ module Adocca
143
143
  v, cache_key, flags, bytes = response.split(/ /)
144
144
  rval = sock.read(bytes.to_i)
145
145
 
146
- sock.gets
147
- sock.gets
146
+ sock.timeout_gets(LIVELINESS_TIMEOUT)
147
+ sock.timeout_gets(LIVELINESS_TIMEOUT)
148
148
  rescue Exception => err
149
149
  server.mark_dead(err.message)
150
150
 
@@ -251,8 +251,8 @@ module Adocca
251
251
 
252
252
  v, key, flags, bytes = response.split(/ /)
253
253
  value = sock.read(bytes.to_i)
254
- sock.gets
255
- sock.gets
254
+ sock.timeout_gets(LIVELINESS_TIMEOUT)
255
+ sock.timeout_gets(LIVELINESS_TIMEOUT)
256
256
  rescue Exception => err
257
257
  server.mark_dead(err.message)
258
258
  self.class.log_error(err)
@@ -272,10 +272,8 @@ module Adocca
272
272
  sock = server.socket
273
273
  unless sock.nil?
274
274
  begin
275
- timeout(LIVELINESS_TIMEOUT) do
276
- sock.write "flush_all\r\n"
277
- sock.gets
278
- end
275
+ sock.timeout_write("flush_all\r\n", LIVELINESS_TIMEOUT)
276
+ sock.timeout_gets(LIVELINESS_TIMEOUT)
279
277
  rescue Exception => err
280
278
  server.mark_dead(err.message)
281
279
  self.class.log_error(err)
@@ -410,6 +408,25 @@ module Adocca
410
408
  !self.socket.nil?
411
409
  end
412
410
 
411
+ module TimeoutSocket
412
+ class TimeoutError < RuntimeError
413
+ end
414
+ def timeout_write(message, timeout)
415
+ if IO.select(nil, [self], nil, timeout)
416
+ self.write(message)
417
+ else
418
+ raise TimeoutError, "Timeout reached for #{self}.timeout_write(#{message.inspect}, #{timeout})"
419
+ end
420
+ end
421
+ def timeout_gets(timeout)
422
+ if IO.select([self], nil, nil, timeout)
423
+ self.gets
424
+ else
425
+ raise TimeoutError, "Timeout reached for #{self}.timeout_gets(#{timeout})"
426
+ end
427
+ end
428
+ end
429
+
413
430
  # Try to connect to the memcached server targeted by this object.
414
431
  # Returns the connected socket object on success or nil on failure.
415
432
  def socket
@@ -423,6 +440,7 @@ module Adocca
423
440
  @sock = timeout(CONNECT_TIMEOUT) {
424
441
  TCPSocket::new(@host, @port)
425
442
  }
443
+ @sock.extend(TimeoutSocket)
426
444
  @retry = nil
427
445
  @status = "CONNECTED"
428
446
  rescue Exception => err
@@ -492,7 +510,7 @@ module Adocca
492
510
  def send_command(key, command)
493
511
  sock_send_command(key, command)[0]
494
512
  end
495
-
513
+
496
514
  #
497
515
  # Will send a command to the proper server for this key
498
516
  # and return the response, socket and server
@@ -510,11 +528,9 @@ module Adocca
510
528
 
511
529
  response = nil
512
530
 
513
- timeout(LIVELINESS_TIMEOUT) do
514
- sock.write "#{command}\r\n"
515
- [sock.gets, sock, server]
516
- end
517
-
531
+ sock.timeout_write("#{command}\r\n", LIVELINESS_TIMEOUT)
532
+ [sock.timeout_gets(LIVELINESS_TIMEOUT), sock, server]
533
+
518
534
  rescue Exception => err
519
535
  server.mark_dead(err.message) if server
520
536
  self.class.log_error(err)
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: AdoccaMemcache
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.8
7
- date: 2007-02-12 00:00:00 +01:00
6
+ version: 0.1.9
7
+ date: 2007-02-16 00:00:00 +01:00
8
8
  summary: A client library to simplify using memcached with Ruby on Rails projects.
9
9
  require_paths:
10
10
  - lib
@@ -59,5 +59,5 @@ dependencies:
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 1.1.4
62
+ version: 1.2.0
63
63
  version: