libuv 0.10.0 → 0.10.2

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 (55) hide show
  1. data/.gitignore +17 -17
  2. data/.gitmodules +3 -3
  3. data/.rspec +1 -1
  4. data/.travis.yml +16 -16
  5. data/Gemfile +2 -2
  6. data/LICENSE +23 -23
  7. data/README.md +82 -73
  8. data/Rakefile +31 -31
  9. data/lib/libuv.rb +53 -34
  10. data/lib/libuv/async.rb +47 -33
  11. data/lib/libuv/check.rb +55 -48
  12. data/lib/libuv/error.rb +70 -70
  13. data/lib/libuv/ext/ext.rb +264 -256
  14. data/lib/libuv/ext/platform/darwin_x64.rb +12 -12
  15. data/lib/libuv/ext/platform/linux.rb +7 -7
  16. data/lib/libuv/ext/platform/unix.rb +13 -13
  17. data/lib/libuv/ext/platform/windows.rb +26 -26
  18. data/lib/libuv/ext/tasks.rb +27 -27
  19. data/lib/libuv/ext/tasks/mac.rb +23 -23
  20. data/lib/libuv/ext/tasks/unix.rb +23 -23
  21. data/lib/libuv/ext/tasks/win.rb +11 -11
  22. data/lib/libuv/ext/types.rb +234 -229
  23. data/lib/libuv/file.rb +192 -0
  24. data/lib/libuv/filesystem.rb +233 -0
  25. data/lib/libuv/fs_event.rb +31 -31
  26. data/lib/libuv/handle.rb +85 -81
  27. data/lib/libuv/idle.rb +56 -49
  28. data/lib/libuv/loop.rb +338 -310
  29. data/lib/libuv/{assertions.rb → mixins/assertions.rb} +23 -23
  30. data/lib/libuv/mixins/fs_checks.rb +55 -0
  31. data/lib/libuv/{listener.rb → mixins/listener.rb} +34 -34
  32. data/lib/libuv/{net.rb → mixins/net.rb} +37 -37
  33. data/lib/libuv/{resource.rb → mixins/resource.rb} +27 -27
  34. data/lib/libuv/{stream.rb → mixins/stream.rb} +143 -123
  35. data/lib/libuv/pipe.rb +197 -97
  36. data/lib/libuv/prepare.rb +56 -49
  37. data/lib/libuv/q.rb +1 -1
  38. data/lib/libuv/signal.rb +51 -0
  39. data/lib/libuv/tcp.rb +204 -193
  40. data/lib/libuv/timer.rb +88 -75
  41. data/lib/libuv/tty.rb +37 -34
  42. data/lib/libuv/udp.rb +273 -255
  43. data/lib/libuv/version.rb +3 -3
  44. data/lib/libuv/work.rb +63 -61
  45. data/libuv.gemspec +54 -54
  46. data/spec/async_spec.rb +60 -60
  47. data/spec/cpu_spec.rb +10 -0
  48. data/spec/defer_spec.rb +980 -980
  49. data/spec/filesystem_spec.rb +119 -0
  50. data/spec/idle_spec.rb +56 -56
  51. data/spec/pipe_spec.rb +153 -148
  52. data/spec/tcp_spec.rb +203 -188
  53. metadata +73 -49
  54. checksums.yaml +0 -15
  55. data/lib/libuv/simple_async.rb +0 -28
data/.gitignore CHANGED
@@ -1,17 +1,17 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- html
6
- pkg
7
- doc
8
- tmp
9
- rerun.txt
10
- Gemfile.lock
11
- .bundle
12
- .idea
13
- *.rbc
14
- .yardoc
15
- bin
16
- Gemfile-custom
17
- ext/*
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ html
6
+ pkg
7
+ doc
8
+ tmp
9
+ rerun.txt
10
+ Gemfile.lock
11
+ .bundle
12
+ .idea
13
+ *.rbc
14
+ .yardoc
15
+ bin
16
+ Gemfile-custom
17
+ ext/*
data/.gitmodules CHANGED
@@ -1,3 +1,3 @@
1
- [submodule "ext/libuv"]
2
- path = ext/libuv
3
- url = https://github.com/joyent/libuv.git
1
+ [submodule "ext/libuv"]
2
+ path = ext/libuv
3
+ url = https://github.com/joyent/libuv.git
data/.rspec CHANGED
@@ -1 +1 @@
1
- --format progress
1
+ --format progress
data/.travis.yml CHANGED
@@ -1,16 +1,16 @@
1
- language: ruby
2
- rvm:
3
- - "1.9.3"
4
- - "2.0.0"
5
- - rbx-20mode
6
- - jruby-19mode
7
- - jruby-20mode
8
- branches:
9
- only:
10
- - master
11
- before_install:
12
- - sudo apt-get install subversion
13
- - git submodule update --init --recursive
14
- - echo "yes" | gem uninstall ffi -a
15
- before_script:
16
- - rake compile
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0.0"
5
+ - rbx-20mode
6
+ - jruby-19mode
7
+ - jruby-20mode
8
+ branches:
9
+ only:
10
+ - master
11
+ before_install:
12
+ - sudo apt-get install subversion
13
+ - git submodule update --init --recursive
14
+ - echo "yes" | gem uninstall ffi -a
15
+ before_script:
16
+ - rake compile
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source "https://rubygems.org"
2
- gemspec
1
+ source "https://rubygems.org"
2
+ gemspec
data/LICENSE CHANGED
@@ -1,24 +1,24 @@
1
- Copyright (c) 2004-2013 Cotag Media
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is furnished
8
- to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all
11
- copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
20
-
21
- ===
22
-
23
- This license applies to all parts of uvrb (Ruby FFI bindings for libuv only)
1
+ Copyright (c) 2004-2013 Cotag Media
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is furnished
8
+ to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
20
+
21
+ ===
22
+
23
+ This license applies to all parts of uvrb (Ruby FFI bindings for libuv only)
24
24
  Libuv itself [is using Node license](https://github.com/joyent/libuv/blob/master/LICENSE)
data/README.md CHANGED
@@ -1,73 +1,82 @@
1
- # Libuv FFI bindings for Ruby
2
-
3
- [![Build Status](https://travis-ci.org/cotag/libuv.png?branch=master)](https://travis-ci.org/cotag/libuv)
4
-
5
- [Libuv](https://github.com/joyent/libuv) is a cross platform asynchronous IO implementation that powers NodeJS. It supports sockets, both UDP and TCP, filesystem watch, TTY, Pipes and other asynchronous primitives like timer, check, prepare and idle.
6
-
7
- The Libuv gem contains Libuv and a Ruby wrapper that implements [pipelined promises](http://en.wikipedia.org/wiki/Futures_and_promises#Promise_pipelining) for asynchronous flow control
8
-
9
- ## Usage
10
-
11
- Create a new libuv loop or use a default one
12
-
13
- ```ruby
14
- require 'libuv'
15
-
16
- loop = Libuv::Loop.default
17
- # or
18
- # loop = Libuv::Loop.new
19
-
20
- loop.run do
21
- timer = loop.timer do |error|
22
- p error if error
23
- puts "50 seconds passed"
24
- timer.close
25
- loop.stop
26
- end
27
- timer.start(50000)
28
- end
29
- ```
30
-
31
- Check out the [yard documentation](http://rubydoc.info/gems/libuv/Libuv/Loop)
32
-
33
-
34
- ## Installation
35
-
36
- ```Shell
37
- gem install libuv
38
- ```
39
-
40
- or
41
-
42
- ```shell
43
- git clone https://github.com/cotag/libuv.git
44
- cd libuv
45
- bundle install
46
- rake compile
47
- ```
48
-
49
- ### Prerequisites
50
-
51
- * The installation requires __subversion__ to be installed on your system and available on the PATH
52
- * Windows users will require a copy of Visual Studio 2010 or later. [Visual Studio Express](http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products) works fine.
53
-
54
- or
55
-
56
- if you have a compatible `libuv.(so | dylib | dll)` on the PATH already, setting the environmental variable `USE_GLOBAL_LIBUV` will prevent compiling the packaged version.
57
-
58
-
59
- ## What's supported
60
-
61
- * TCP
62
- * UDP
63
- * TTY
64
- * Pipe
65
- * Timer
66
- * Prepare
67
- * Check
68
- * Idle
69
- * Async
70
- * Filesystem Events
71
- * Errors
72
- * Work queue (thread pool)
73
-
1
+ # Libuv FFI bindings for Ruby
2
+
3
+ [![Build Status](https://travis-ci.org/cotag/libuv.png?branch=master)](https://travis-ci.org/cotag/libuv)
4
+
5
+ [Libuv](https://github.com/joyent/libuv) is a cross platform asynchronous IO implementation that powers NodeJS. It supports sockets, both UDP and TCP, filesystem watch, TTY, Pipes and other asynchronous primitives like timer, check, prepare and idle.
6
+
7
+ The Libuv gem contains Libuv and a Ruby wrapper that implements [pipelined promises](http://en.wikipedia.org/wiki/Futures_and_promises#Promise_pipelining) for asynchronous flow control
8
+
9
+ ## Usage
10
+
11
+ Create a new libuv loop or use a default one
12
+
13
+ ```ruby
14
+ require 'libuv'
15
+
16
+ loop = Libuv::Loop.default
17
+ # or
18
+ # loop = Libuv::Loop.new
19
+
20
+ loop.run do
21
+ timer = loop.timer do
22
+ puts "5 seconds passed"
23
+ timer.close
24
+ loop.stop
25
+ end
26
+ timer.catch do |error|
27
+ puts "error with timer: #{error}"
28
+ end
29
+ timer.finally do
30
+ puts "timer handle was closed"
31
+ end
32
+ timer.start(5000)
33
+ end
34
+ ```
35
+
36
+ Check out the [yard documentation](http://rubydoc.info/gems/libuv/Libuv/Loop)
37
+
38
+
39
+ ## Installation
40
+
41
+ ```Shell
42
+ gem install libuv
43
+ ```
44
+
45
+ or
46
+
47
+ ```shell
48
+ git clone https://github.com/cotag/libuv.git
49
+ cd libuv
50
+ bundle install
51
+ rake compile
52
+ ```
53
+
54
+ ### Prerequisites
55
+
56
+ * The installation requires __subversion__ to be installed on your system and available on the PATH
57
+ * Windows users will require a copy of Visual Studio 2010 or later. [Visual Studio Express](http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products) works fine.
58
+
59
+ or
60
+
61
+ * setting the environmental variable `USE_GLOBAL_LIBUV` will prevent compiling the packaged version.
62
+ * if you have a compatible `libuv.(so | dylib | dll)` on the PATH already
63
+
64
+
65
+ ## What's supported
66
+
67
+ * TCP
68
+ * UDP
69
+ * TTY
70
+ * Pipe
71
+ * Timer
72
+ * Prepare
73
+ * Check
74
+ * Idle
75
+ * Async
76
+ * Signals
77
+ * Filesystem Events
78
+ * File manipulation
79
+ * Filesystem manipulation
80
+ * Errors
81
+ * Work queue (thread pool)
82
+
data/Rakefile CHANGED
@@ -1,31 +1,31 @@
1
- require 'rubygems'
2
- require 'rspec/core/rake_task' # testing framework
3
- require 'yard' # yard documentation
4
- require 'ffi' # loads the extension
5
- require 'rake/clean' # for the :clobber rake task
6
- require 'libuv/ext/tasks' # platform specific rake tasks used by compile
7
-
8
-
9
-
10
- # By default we don't run network tests
11
- task :default => :limited_spec
12
- RSpec::Core::RakeTask.new(:limited_spec) do |t|
13
- # Exclude network tests and tests that won't run on java (real io)
14
- t.rspec_opts = "--tag ~network --tag ~real_io"
15
- end
16
- RSpec::Core::RakeTask.new(:spec)
17
-
18
-
19
- desc "Run all tests"
20
- task :test => [:spec]
21
-
22
-
23
- YARD::Rake::YardocTask.new do |t|
24
- t.files = ['lib/**/*.rb', '-', 'ext/README.md', 'README.md']
25
- end
26
-
27
-
28
- desc "Compile libuv from submodule"
29
- task :compile => ["ext/libuv.#{FFI::Platform::LIBSUFFIX}"]
30
-
31
- CLOBBER.include("ext/libuv.#{FFI::Platform::LIBSUFFIX}")
1
+ require 'rubygems'
2
+ require 'rspec/core/rake_task' # testing framework
3
+ require 'yard' # yard documentation
4
+ require 'ffi' # loads the extension
5
+ require 'rake/clean' # for the :clobber rake task
6
+ require 'libuv/ext/tasks' # platform specific rake tasks used by compile
7
+
8
+
9
+
10
+ # By default we don't run network tests
11
+ task :default => :limited_spec
12
+ RSpec::Core::RakeTask.new(:limited_spec) do |t|
13
+ # Exclude network tests
14
+ t.rspec_opts = "--tag ~network"
15
+ end
16
+ RSpec::Core::RakeTask.new(:spec)
17
+
18
+
19
+ desc "Run all tests"
20
+ task :test => [:spec]
21
+
22
+
23
+ YARD::Rake::YardocTask.new do |t|
24
+ t.files = ['lib/**/*.rb', '-', 'ext/README.md', 'README.md']
25
+ end
26
+
27
+
28
+ desc "Compile libuv from submodule"
29
+ task :compile => ["ext/libuv.#{FFI::Platform::LIBSUFFIX}"]
30
+
31
+ CLOBBER.include("ext/libuv.#{FFI::Platform::LIBSUFFIX}")
data/lib/libuv.rb CHANGED
@@ -1,34 +1,53 @@
1
- require 'forwardable'
2
- require 'ffi'
3
-
4
- module Libuv
5
- require 'libuv/ext/ext' # The libuv ffi ext
6
- require 'libuv/q' # The promise library
7
-
8
- autoload :Assertions, 'libuv/assertions' # Common code to check arguments
9
- autoload :Resource, 'libuv/resource' # Common code to check for errors
10
- autoload :Listener, 'libuv/listener' # Common callback code
11
-
12
- autoload :Error, 'libuv/error' # List of errors (matching those in uv.h)
13
- autoload :Net, 'libuv/net' # Common functions for tcp and udp
14
-
15
- autoload :Handle, 'libuv/handle' # Libuv handle base class
16
-
17
- autoload :Loop, 'libuv/loop' # The libuv reactor or event loop
18
- autoload :Timer, 'libuv/timer' # High resolution timer
19
- autoload :Check, 'libuv/check' # Called before processing events on the loop
20
- autoload :Prepare, 'libuv/prepare' # Called at the end of a loop cycle
21
- autoload :Idle, 'libuv/idle' # Called when there are no events to process
22
- autoload :Async, 'libuv/async' # Provide a threadsafe way to signal the event loop (uses promises)
23
- autoload :SimpleAsync, 'libuv/simple_async' # Same as above using a simple callback
24
- autoload :Work, 'libuv/work' # Provide work to be completed on another thread (thread pool)
25
-
26
- # Streams
27
- autoload :Stream, 'libuv/stream'
28
- autoload :TCP, 'libuv/tcp' # Communicate over TCP
29
- autoload :Pipe, 'libuv/pipe' # Communicate over Pipes
30
- autoload :TTY, 'libuv/tty' # Terminal output
31
-
32
- autoload :UDP, 'libuv/udp' # Communicate over UDP
33
- autoload :FSEvent, 'libuv/fs_event' # Notifies of changes to files and folders as they occur
34
- end
1
+ require 'forwardable'
2
+ require 'ffi'
3
+
4
+ module Libuv
5
+ require 'libuv/ext/ext' # The libuv ffi ext
6
+ require 'libuv/error' # List of errors (matching those in uv.h)
7
+ require 'libuv/q' # The promise library
8
+
9
+ require 'libuv/mixins/assertions' # Common code to check arguments
10
+ require 'libuv/mixins/fs_checks' # Common code to check file system results
11
+ require 'libuv/mixins/resource' # Common code to check for errors
12
+ require 'libuv/mixins/listener' # Common callback code
13
+ require 'libuv/mixins/stream' # For all libuv streams (tcp, pipes, tty)
14
+ require 'libuv/mixins/net' # Common functions for tcp and udp
15
+
16
+ # -- The classes required for a loop instance --
17
+ require 'libuv/handle' # Base class for most libuv functionality
18
+ require 'libuv/async' # Provide a threadsafe way to signal the event loop
19
+ require 'libuv/timer' # High resolution timer
20
+ require 'libuv/loop' # The libuv reactor or event loop
21
+ # --
22
+
23
+ require 'libuv/filesystem' # Async directory manipulation
24
+ require 'libuv/fs_event' # Notifies of changes to files and folders as they occur
25
+ require 'libuv/prepare' # Called at the end of a loop cycle
26
+ require 'libuv/signal' # Used to handle OS signals
27
+ require 'libuv/check' # Called before processing events on the loop
28
+ require 'libuv/file' # Async file reading and writing
29
+ require 'libuv/idle' # Called when there are no events to process
30
+ require 'libuv/work' # Provide work to be completed on another thread (thread pool)
31
+ require 'libuv/udp' # Communicate over UDP
32
+
33
+ # Streams
34
+ require 'libuv/pipe' # Communicate over Pipes
35
+ require 'libuv/tcp' # Communicate over TCP
36
+ require 'libuv/tty' # Terminal output
37
+
38
+
39
+ # Returns the number of CPU cores on the host platform
40
+ #
41
+ # @return [Fixnum, nil] representing the number of CPU cores or nil if failed
42
+ def self.cpu_count
43
+ cpu_info = FFI::MemoryPointer.new(:pointer)
44
+ cpu_count = FFI::MemoryPointer.new(:int)
45
+ if ::Libuv::Ext.cpu_info(cpu_info, cpu_count) >= 0
46
+ count = cpu_count.read_int
47
+ ::Libuv::Ext.free_cpu_info(cpu_info.read_pointer, count)
48
+ return count
49
+ else
50
+ return nil
51
+ end
52
+ end
53
+ end
data/lib/libuv/async.rb CHANGED
@@ -1,33 +1,47 @@
1
- module Libuv
2
- class Async < Handle
3
-
4
-
5
- def initialize(loop)
6
- @loop = loop
7
- async_ptr = ::Libuv::Ext.create_handle(:uv_async)
8
- error = check_result(::Libuv::Ext.async_init(loop.handle, async_ptr, callback(:on_async)))
9
-
10
- super(async_ptr, error)
11
- end
12
-
13
- def call
14
- return if @closed
15
- error = check_result ::Libuv::Ext.async_send(handle)
16
- reject(error) if error
17
- end
18
-
19
-
20
- private
21
-
22
-
23
- def on_async(handle, status)
24
- e = check_result(status)
25
-
26
- if e
27
- reject(e)
28
- else
29
- defer.notify(self) # notify of a call
30
- end
31
- end
32
- end
33
- end
1
+ module Libuv
2
+ class Async < Handle
3
+
4
+
5
+ # @param loop [::Libuv::Loop] loop this async callback will be associated
6
+ def initialize(loop, callback = nil, &blk)
7
+ @loop = loop
8
+ @callback = callback || blk
9
+ async_ptr = ::Libuv::Ext.create_handle(:uv_async)
10
+ error = check_result(::Libuv::Ext.async_init(loop.handle, async_ptr, callback(:on_async)))
11
+
12
+ super(async_ptr, error)
13
+ end
14
+
15
+ # Triggers a notify event, calling everything in the notify chain
16
+ def call
17
+ return if @closed
18
+ error = check_result ::Libuv::Ext.async_send(handle)
19
+ reject(error) if error
20
+ end
21
+
22
+ # Used to update the callback that will be triggered when async is called
23
+ #
24
+ # @param callback [Proc] the callback to be called on loop prepare
25
+ def progress(callback = nil, &blk)
26
+ @callback = callback || blk
27
+ end
28
+
29
+
30
+ private
31
+
32
+
33
+ def on_async(handle, status)
34
+ e = check_result(status)
35
+
36
+ if e
37
+ reject(e)
38
+ else
39
+ begin
40
+ @callback.call
41
+ rescue Exception => e
42
+ @loop.log :error, :async_cb, e
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end