Module: MemCache::EventedServer
- Defined in:
- lib/memcache/event_machine.rb
Overview
DEFAULT_OPTIONS = false
Instance Method Summary collapse
Instance Method Details
#close ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/memcache/event_machine.rb', line 50 def close sock = Thread.current[fiber_key] if sock sock.close if !sock.closed? Thread.current[fiber_key] = nil end @retry = nil @status = "NOT CONNECTED" end |
#fiber_key ⇒ Object
17 18 19 |
# File 'lib/memcache/event_machine.rb', line 17 def fiber_key @fiber_key ||= "memcached-#{@host}-#{@port}" end |
#socket ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/memcache/event_machine.rb', line 21 def socket sock = Thread.current[fiber_key] return sock if sock and not sock.closed? Thread.current[fiber_key] = nil # If the host was dead, don't retry for a while. return if @retry and @retry > Time.now Thread.current[fiber_key] ||= begin sock = EM::SocketConnection.connect(@host, @port, @timeout) yielding = true fiber = Fiber.current sock.callback do @status = 'CONNECTED' @retry = nil yielding = false fiber.resume if Fiber.current != fiber end sock.errback do sock = nil yielding = false fiber.resume if Fiber.current != fiber end Fiber.yield if yielding sock end end |