Skip to content

Commit

Permalink
add prepare, check, idle and async handles, remove Net module where u…
Browse files Browse the repository at this point in the history
…nnecessary
  • Loading branch information
avalanche123 committed Apr 11, 2012
1 parent 7f6471c commit af88df3
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/uv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,8 @@ class SockaddrIn6 < FFI::Struct
autoload :UDP, 'uv/udp'
autoload :TTY, 'uv/tty'
autoload :Pipe, 'uv/pipe'
autoload :Prepare, 'uv/prepare'
autoload :Check, 'uv/check'
autoload :Idle, 'uv/idle'
autoload :Async, 'uv/async'
end
25 changes: 25 additions & 0 deletions lib/uv/async.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module UV
class Async
include Handle, Resource, Listener

def initialize(loop, &block)
raise "no block given" unless block_given?
@async_block = block
end

def send
check_result UV.async_send(handle)
end

private
def on_async(handle, status)
@async_block.call(check_result(status))
end

def create_handle
ptr = UV.malloc(UV.handle_size(:uv_async))
check_result! UV.async_init(loop.pointer, ptr, callback(:on_async))
ptr
end
end
end
20 changes: 20 additions & 0 deletions lib/uv/check.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module UV
class Check
include Handle, Resource, Listener

def start(&block)
raise "no block given" unless block_given?
@check_block = block
check_result! UV.check_start(handle, callback(:on_check))
end

def stop
check_result! UV.check_stop(handle)
end

private
def on_check(handle, status)
@check_block.call(check_result(status))
end
end
end
20 changes: 20 additions & 0 deletions lib/uv/idle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module UV
class Idle
include Handle, Resource, Listener

def start(&block)
raise "no block given" unless block_given?
@idle_block = block
check_result! UV.idle_start(handle, callback(:on_idle))
end

def stop
check_result! UV.idle_stop(handle)
end

private
def on_idle(handle, status)
@idle_block.call(check_result(status))
end
end
end
16 changes: 16 additions & 0 deletions lib/uv/loop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ def pipe(ipc = false)
Pipe.new(self, ipc)
end

def prepare
Prepare.new(self)
end

def check
Check.new(self)
end

def idle
Idle.new(self)
end

def async(&block)
Async.new(self, &block)
end

attr_reader :pointer
end
end
2 changes: 1 addition & 1 deletion lib/uv/pipe.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module UV
class Pipe
include Stream, Handle, Resource, Listener, Net
include Stream, Handle, Resource, Listener

def initialize(loop, ipc = false)
super(loop)
Expand Down
20 changes: 20 additions & 0 deletions lib/uv/prepare.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module UV
class Prepare
include Handle, Resource, Listener

def start(&block)
raise "no block given" unless block_given?
@prepare_block = block
check_result! UV.prepare_start(handle, callback(:on_prepare))
end

def stop
check_result! UV.prepare_stop(handle)
end

private
def on_prepare(handle, status)
@prepare_block.call(check_result(status))
end
end
end
2 changes: 1 addition & 1 deletion lib/uv/tty.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module UV
class TTY
include Stream, Handle, Resource, Listener, Net
include Stream, Handle, Resource, Listener

def initialize(loop, io, readable = true)
super(loop)
Expand Down

0 comments on commit af88df3

Please sign in to comment.