# File lib/memcache/event_machine.rb, line 127
127: def can_read?(size)
128: @buf.size >= @index + size
129: end
# File lib/memcache/event_machine.rb, line 83
83: def close
84: @connected = false
85: close_connection(true)
86: end
# File lib/memcache/event_machine.rb, line 79
79: def closed?
80: !@connected
81: end
# File lib/memcache/event_machine.rb, line 109
109: def gets
110: while true
111: # Read to ensure we have some data in the buffer
112: line = read(2)
113: # Reset the buffer index to zero
114: @buf = @buf.slice(@index..1)
115: @index = 0
116: if eol = @buf.index(SEP)
117: line << yank(eol + SEP.size)
118: break
119: else
120: # EOL not in the current buffer
121: line << yank(@buf.size)
122: end
123: end
124: line
125: end
# File lib/memcache/event_machine.rb, line 144
144: def post_init
145: @connected = true
146: succeed
147: end
# File lib/memcache/event_machine.rb, line 92
92: def read(size)
93: if can_read?(size)
94: yank(size)
95: else
96: fiber = Fiber.current
97: @size = size
98: @callback = proc { |data|
99: fiber.resume(data)
100: }
101: # TODO Can leak fiber if the connection dies while
102: # this fiber is yielded, waiting for data
103: Fiber.yield
104: end
105: end
EM callbacks
# File lib/memcache/event_machine.rb, line 133
133: def receive_data(data)
134: @buf << data
135:
136: if @callback and can_read?(@size)
137: callback = @callback
138: data = yank(@size)
139: @callback = @size = nil
140: callback.call(data)
141: end
142: end
# File lib/memcache/event_machine.rb, line 161
161: def yank(len)
162: data = @buf.slice(@index, len)
163: @index += len
164: @index = @buf.size if @index > @buf.size
165: if @index >= BUFFER_SIZE
166: @buf = @buf.slice(@index..1)
167: @index = 0
168: end
169: data
170: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.