Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

clear callbacks

  • Loading branch information...
commit 269d96c8a23b2553d36f4da7c1f027720ac3d4f7 1 parent 97e256d
@avalanche123 authored
View
1  lib/uv/async.rb
@@ -21,7 +21,6 @@ def on_async(handle, status)
def on_close(pointer)
super
- @async_block = nil
end
public :callback
View
9 lib/uv/listener.rb
@@ -3,7 +3,7 @@
module UV
module Listener
@@methods = Hash.new { |hash, object_id| hash[object_id] = Hash.new }
- @@procs = {}
+ @@procs = Hash.new { |hash, object_id| hash[object_id] = Hash.new }
class << self
def define_callback(object_id, name, callback)
@@ -12,12 +12,13 @@ def define_callback(object_id, name, callback)
def undefine_callbacks(object_id)
@@methods.delete(object_id)
+ @@procs.delete(object_id)
nil
end
- def callback(&block)
- @@procs[block.object_id] = Proc.new do |*args|
- @@procs.delete(block.object_id)
+ def callback(object_id, &block)
+ @@procs[object_id][block.object_id] = Proc.new do |*args|
+ @@procs[object_id].delete(block.object_id)
block.call(*args)
end
end
View
17 lib/uv/stream.rb
@@ -48,7 +48,7 @@ def write(data, &block)
size = data.respond_to?(:bytesize) ? data.bytesize : data.size
buffer = UV.buf_init(FFI::MemoryPointer.from_string(data), size)
- callback = Listener.callback {|req, status| UV.free(req); block.call(check_result(status))}
+ callback = Listener.callback(object_id) {|req, status| UV.free(req); block.call(check_result(status))}
check_result! UV.write(UV.allocate_request_write, handle, buffer, 1, callback)
@@ -59,8 +59,9 @@ def shutdown(&block)
assert_block(block)
assert_arity(1, block)
- callback = Listener.callback {|req, status| UV.free(req); block.call(check_result(status))}
- check_result! UV.shutdown(UV.allocate_request_shutdown, handle, callback)
+ @shutdown_block = block
+
+ check_result! UV.shutdown(UV.allocate_request_shutdown, handle, callback(:on_shutdown))
self
end
@@ -93,13 +94,19 @@ def on_read(handle, nread, buf)
elsif nread == 0
UV.free(base) if base
else
- # base = UV.realloc(base, nread)
+ base = UV.realloc(base, nread)
data = base.read_string(nread)
- # buf[:base] = base
+ buf[:base] = base
@read_block.call(nil, data)
end
end
+ def on_shutdown(req, status)
+ UV.free(req)
+ @shutdown_block.call(check_result(status))
+ @shutdown_block = nil
+ end
+
def on_close(pointer)
super
@listen_block = nil if @listen_block
View
6 spec/shared_examples/stream.rb
@@ -79,12 +79,8 @@
end
it "calls UV.shutdown" do
- callback = double('shutdown callback')
-
- UV::Listener.should_receive(:callback).and_return(callback)
-
UV.should_receive(:allocate_request_shutdown).and_return(shutdown_request)
- UV.should_receive(:shutdown).with(shutdown_request, pointer, callback)
+ UV.should_receive(:shutdown).with(shutdown_request, pointer, subject.method(:on_shutdown))
subject.shutdown { |e| }
end
Please sign in to comment.
Something went wrong with that request. Please try again.