libuv 0.11.21 → 0.11.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -17
  3. data/.gitmodules +3 -3
  4. data/.rspec +1 -1
  5. data/.travis.yml +16 -16
  6. data/Gemfile +4 -4
  7. data/LICENSE +23 -23
  8. data/README.md +89 -88
  9. data/Rakefile +31 -31
  10. data/lib/libuv.rb +54 -54
  11. data/lib/libuv/async.rb +47 -47
  12. data/lib/libuv/check.rb +55 -55
  13. data/lib/libuv/dns.rb +85 -85
  14. data/lib/libuv/error.rb +74 -73
  15. data/lib/libuv/ext/ext.rb +258 -258
  16. data/lib/libuv/ext/platform/darwin_x64.rb +23 -23
  17. data/lib/libuv/ext/platform/linux.rb +7 -7
  18. data/lib/libuv/ext/platform/unix.rb +29 -29
  19. data/lib/libuv/ext/platform/windows.rb +40 -40
  20. data/lib/libuv/ext/tasks.rb +31 -31
  21. data/lib/libuv/ext/tasks/mac.rb +23 -23
  22. data/lib/libuv/ext/tasks/unix.rb +23 -23
  23. data/lib/libuv/ext/tasks/win.rb +14 -14
  24. data/lib/libuv/ext/types.rb +238 -238
  25. data/lib/libuv/file.rb +269 -269
  26. data/lib/libuv/filesystem.rb +232 -232
  27. data/lib/libuv/fs_event.rb +31 -31
  28. data/lib/libuv/handle.rb +85 -85
  29. data/lib/libuv/idle.rb +56 -56
  30. data/lib/libuv/loop.rb +412 -412
  31. data/lib/libuv/mixins/assertions.rb +23 -23
  32. data/lib/libuv/mixins/fs_checks.rb +58 -58
  33. data/lib/libuv/mixins/listener.rb +34 -34
  34. data/lib/libuv/mixins/net.rb +40 -40
  35. data/lib/libuv/mixins/resource.rb +27 -27
  36. data/lib/libuv/mixins/stream.rb +154 -154
  37. data/lib/libuv/pipe.rb +203 -203
  38. data/lib/libuv/prepare.rb +56 -56
  39. data/lib/libuv/signal.rb +51 -51
  40. data/lib/libuv/tcp.rb +334 -332
  41. data/lib/libuv/timer.rb +85 -85
  42. data/lib/libuv/tty.rb +37 -37
  43. data/lib/libuv/udp.rb +240 -240
  44. data/lib/libuv/version.rb +3 -3
  45. data/lib/libuv/work.rb +75 -75
  46. data/libuv.gemspec +56 -56
  47. data/spec/async_spec.rb +60 -60
  48. data/spec/cpu_spec.rb +10 -10
  49. data/spec/defer_spec.rb +980 -980
  50. data/spec/dns_spec.rb +90 -90
  51. data/spec/filesystem_spec.rb +261 -250
  52. data/spec/idle_spec.rb +56 -56
  53. data/spec/pipe_spec.rb +160 -160
  54. data/spec/tcp_spec.rb +267 -267
  55. metadata +55 -61
data/lib/libuv/async.rb CHANGED
@@ -1,47 +1,47 @@
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
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
data/lib/libuv/check.rb CHANGED
@@ -1,56 +1,56 @@
1
- module Libuv
2
- class Check < Handle
3
-
4
-
5
- # @param loop [::Libuv::Loop] loop this check will be associated
6
- # @param callback [Proc] callback to be called on loop check
7
- def initialize(loop, callback = nil, &blk)
8
- @loop = loop
9
- @callback = callback || blk
10
-
11
- check_ptr = ::Libuv::Ext.create_handle(:uv_check)
12
- error = check_result(::Libuv::Ext.check_init(loop.handle, check_ptr))
13
-
14
- super(check_ptr, error)
15
- end
16
-
17
- # Enables the check handler.
18
- def start
19
- return if @closed
20
- error = check_result ::Libuv::Ext.check_start(handle, callback(:on_check))
21
- reject(error) if error
22
- end
23
-
24
- # Disables the check handler.
25
- def stop
26
- return if @closed
27
- error = check_result ::Libuv::Ext.check_stop(handle)
28
- reject(error) if error
29
- end
30
-
31
- # Used to update the callback that will be triggered on loop check
32
- #
33
- # @param callback [Proc] the callback to be called on loop check
34
- def progress(callback = nil, &blk)
35
- @callback = callback || blk
36
- end
37
-
38
-
39
- private
40
-
41
-
42
- def on_check(handle, status)
43
- e = check_result(status)
44
-
45
- if e
46
- reject(e)
47
- else
48
- begin
49
- @callback.call
50
- rescue Exception => e
51
- @loop.log :error, :check_cb, e
52
- end
53
- end
54
- end
55
- end
1
+ module Libuv
2
+ class Check < Handle
3
+
4
+
5
+ # @param loop [::Libuv::Loop] loop this check will be associated
6
+ # @param callback [Proc] callback to be called on loop check
7
+ def initialize(loop, callback = nil, &blk)
8
+ @loop = loop
9
+ @callback = callback || blk
10
+
11
+ check_ptr = ::Libuv::Ext.create_handle(:uv_check)
12
+ error = check_result(::Libuv::Ext.check_init(loop.handle, check_ptr))
13
+
14
+ super(check_ptr, error)
15
+ end
16
+
17
+ # Enables the check handler.
18
+ def start
19
+ return if @closed
20
+ error = check_result ::Libuv::Ext.check_start(handle, callback(:on_check))
21
+ reject(error) if error
22
+ end
23
+
24
+ # Disables the check handler.
25
+ def stop
26
+ return if @closed
27
+ error = check_result ::Libuv::Ext.check_stop(handle)
28
+ reject(error) if error
29
+ end
30
+
31
+ # Used to update the callback that will be triggered on loop check
32
+ #
33
+ # @param callback [Proc] the callback to be called on loop check
34
+ def progress(callback = nil, &blk)
35
+ @callback = callback || blk
36
+ end
37
+
38
+
39
+ private
40
+
41
+
42
+ def on_check(handle, status)
43
+ e = check_result(status)
44
+
45
+ if e
46
+ reject(e)
47
+ else
48
+ begin
49
+ @callback.call
50
+ rescue Exception => e
51
+ @loop.log :error, :check_cb, e
52
+ end
53
+ end
54
+ end
55
+ end
56
56
  end
data/lib/libuv/dns.rb CHANGED
@@ -1,86 +1,86 @@
1
- module Libuv
2
- class Dns < Q::DeferredPromise
3
- include Resource, Listener, Net
4
-
5
-
6
- attr_reader :results
7
- attr_reader :domain
8
- attr_reader :port
9
- attr_reader :hint
10
-
11
-
12
- HINTS = {
13
- :IPv4 => ::Libuv::Ext::UvAddrinfo.new,
14
- :IPv6 => ::Libuv::Ext::UvAddrinfo.new
15
- }
16
- HINTS[:IPv4].tap do |hint|
17
- hint[:family] = Socket::Constants::AF_INET
18
- hint[:socktype] = Socket::Constants::SOCK_STREAM
19
- hint[:protocol] = Socket::Constants::IPPROTO_TCP
20
- end
21
- HINTS[:IPv6].tap do |hint|
22
- hint[:family] = Socket::Constants::AF_INET6
23
- hint[:socktype] = Socket::Constants::SOCK_STREAM
24
- hint[:protocol] = Socket::Constants::IPPROTO_TCP
25
- end
26
-
27
-
28
- # @param loop [::Libuv::Loop] loop this work request will be associated
29
- # @param domain [String] the domain name to resolve
30
- # @param port [Integer, String] the port we wish to use
31
- def initialize(loop, domain, port, hint = :IPv4)
32
- super(loop, loop.defer)
33
-
34
- @domain = domain
35
- @port = port
36
- @hint = hint
37
- @complete = false
38
- @pointer = ::Libuv::Ext.create_request(:uv_getaddrinfo)
39
- @error = nil # error in callback
40
-
41
- error = check_result ::Libuv::Ext.getaddrinfo(@loop, @pointer, callback(:on_complete), domain, port.to_s, HINTS[hint])
42
- if error
43
- ::Libuv::Ext.free(@pointer)
44
- @complete = true
45
- @defer.reject(error)
46
- end
47
- end
48
-
49
- # Indicates if the lookup has completed yet or not.
50
- #
51
- # @return [true, false]
52
- def completed?
53
- return @complete
54
- end
55
-
56
-
57
- private
58
-
59
-
60
- def on_complete(req, status, addrinfo)
61
- @complete = true
62
- ::Libuv::Ext.free(req)
63
-
64
- e = check_result(status)
65
- if e
66
- @defer.reject(e)
67
- else
68
- begin
69
- current = addrinfo
70
- @results = []
71
- while !current.null?
72
- @results << get_ip_and_port(current[:addr])
73
- current = current[:next]
74
- end
75
- @defer.resolve(@results)
76
- rescue Exception => e
77
- @defer.reject(e)
78
- end
79
- ::Libuv::Ext.freeaddrinfo(addrinfo)
80
- end
81
-
82
- # Clean up references
83
- clear_callbacks
84
- end
85
- end
1
+ module Libuv
2
+ class Dns < Q::DeferredPromise
3
+ include Resource, Listener, Net
4
+
5
+
6
+ attr_reader :results
7
+ attr_reader :domain
8
+ attr_reader :port
9
+ attr_reader :hint
10
+
11
+
12
+ HINTS = {
13
+ :IPv4 => ::Libuv::Ext::UvAddrinfo.new,
14
+ :IPv6 => ::Libuv::Ext::UvAddrinfo.new
15
+ }
16
+ HINTS[:IPv4].tap do |hint|
17
+ hint[:family] = FFI::Platform.windows? ? 2 : Socket::Constants::AF_INET
18
+ hint[:socktype] = Socket::Constants::SOCK_STREAM
19
+ hint[:protocol] = Socket::Constants::IPPROTO_TCP
20
+ end
21
+ HINTS[:IPv6].tap do |hint|
22
+ hint[:family] = FFI::Platform.windows? ? 23 : Socket::Constants::AF_INET6
23
+ hint[:socktype] = Socket::Constants::SOCK_STREAM
24
+ hint[:protocol] = Socket::Constants::IPPROTO_TCP
25
+ end
26
+
27
+
28
+ # @param loop [::Libuv::Loop] loop this work request will be associated
29
+ # @param domain [String] the domain name to resolve
30
+ # @param port [Integer, String] the port we wish to use
31
+ def initialize(loop, domain, port, hint = :IPv4)
32
+ super(loop, loop.defer)
33
+
34
+ @domain = domain
35
+ @port = port
36
+ @hint = hint
37
+ @complete = false
38
+ @pointer = ::Libuv::Ext.create_request(:uv_getaddrinfo)
39
+ @error = nil # error in callback
40
+
41
+ error = check_result ::Libuv::Ext.getaddrinfo(@loop, @pointer, callback(:on_complete), domain, port.to_s, HINTS[hint])
42
+ if error
43
+ ::Libuv::Ext.free(@pointer)
44
+ @complete = true
45
+ @defer.reject(error)
46
+ end
47
+ end
48
+
49
+ # Indicates if the lookup has completed yet or not.
50
+ #
51
+ # @return [true, false]
52
+ def completed?
53
+ return @complete
54
+ end
55
+
56
+
57
+ private
58
+
59
+
60
+ def on_complete(req, status, addrinfo)
61
+ @complete = true
62
+ ::Libuv::Ext.free(req)
63
+
64
+ e = check_result(status)
65
+ if e
66
+ @defer.reject(e)
67
+ else
68
+ begin
69
+ current = addrinfo
70
+ @results = []
71
+ while !current.null?
72
+ @results << get_ip_and_port(current[:addr])
73
+ current = current[:next]
74
+ end
75
+ @defer.resolve(@results)
76
+ rescue Exception => e
77
+ @defer.reject(e)
78
+ end
79
+ ::Libuv::Ext.freeaddrinfo(addrinfo)
80
+ end
81
+
82
+ # Clean up references
83
+ clear_callbacks
84
+ end
85
+ end
86
86
  end
data/lib/libuv/error.rb CHANGED
@@ -1,73 +1,74 @@
1
- module Libuv
2
- class Error < StandardError
3
- class EACCES < Error; end
4
- class EADDRINUSE < Error; end
5
- class EADDRNOTAVAIL < Error; end
6
- class EAFNOSUPPORT < Error; end
7
- class EAGAIN < Error; end
8
- class EAI_ADDRFAMILY < Error; end
9
- class EAI_AGAIN < Error; end
10
- class EAI_BADFLAGS < Error; end
11
- class EAI_BADHINTS < Error; end
12
- class EAI_CANCELED < Error; end
13
- class EAI_FAIL < Error; end
14
- class EAI_FAMILY < Error; end
15
- class EAI_MEMORY < Error; end
16
- class EAI_NODATA < Error; end
17
- class EAI_NONAME < Error; end
18
- class EAI_OVERFLOW < Error; end
19
- class EAI_PROTOCOL < Error; end
20
- class EAI_SERVICE < Error; end
21
- class EAI_SOCKTYPE < Error; end
22
- class EAI_SYSTEM < Error; end
23
- class EALREADY < Error; end
24
- class EBADF < Error; end
25
- class EBUSY < Error; end
26
- class ECANCELED < Error; end
27
- class ECHARSET < Error; end
28
- class ECONNABORTED < Error; end
29
- class ECONNREFUSED < Error; end
30
- class ECONNRESET < Error; end
31
- class EDESTADDRREQ < Error; end
32
- class EEXIST < Error; end
33
- class EFAULT < Error; end
34
- class EHOSTUNREACH < Error; end
35
- class EINTR < Error; end
36
- class EINVAL < Error; end
37
- class EIO < Error; end
38
- class EISCONN < Error; end
39
- class EISDIR < Error; end
40
- class ELOOP < Error; end
41
- class EMFILE < Error; end
42
- class EMSGSIZE < Error; end
43
- class ENAMETOOLONG < Error; end
44
- class ENETDOWN < Error; end
45
- class ENETUNREACH < Error; end
46
- class ENFILE < Error; end
47
- class ENOBUFS < Error; end
48
- class ENODEV < Error; end
49
- class ENOENT < Error; end
50
- class ENOMEM < Error; end
51
- class ENONET < Error; end
52
- class ENOSPC < Error; end
53
- class ENOSYS < Error; end
54
- class ENOTCONN < Error; end
55
- class ENOTDIR < Error; end
56
- class ENOTEMPTY < Error; end
57
- class ENOTSOCK < Error; end
58
- class ENOTSUP < Error; end
59
- class EPERM < Error; end
60
- class EPIPE < Error; end
61
- class EPROTO < Error; end
62
- class EPROTONOSUPPORT < Error; end
63
- class EPROTOTYPE < Error; end
64
- class EROFS < Error; end
65
- class ESHUTDOWN < Error; end
66
- class ESPIPE < Error; end
67
- class ESRCH < Error; end
68
- class ETIMEDOUT < Error; end
69
- class EXDEV < Error; end
70
- class UNKNOWN < Error; end
71
- class EOF < Error; end
72
- end
73
- end
1
+ module Libuv
2
+ class Error < StandardError
3
+ class EACCES < Error; end
4
+ class EADDRINUSE < Error; end
5
+ class EADDRNOTAVAIL < Error; end
6
+ class EAFNOSUPPORT < Error; end
7
+ class EAGAIN < Error; end
8
+ class EAI_ADDRFAMILY < Error; end
9
+ class EAI_AGAIN < Error; end
10
+ class EAI_BADFLAGS < Error; end
11
+ class EAI_BADHINTS < Error; end
12
+ class EAI_CANCELED < Error; end
13
+ class EAI_FAIL < Error; end
14
+ class EAI_FAMILY < Error; end
15
+ class EAI_MEMORY < Error; end
16
+ class EAI_NODATA < Error; end
17
+ class EAI_NONAME < Error; end
18
+ class EAI_OVERFLOW < Error; end
19
+ class EAI_PROTOCOL < Error; end
20
+ class EAI_SERVICE < Error; end
21
+ class EAI_SOCKTYPE < Error; end
22
+ class EAI_SYSTEM < Error; end
23
+ class EALREADY < Error; end
24
+ class EBADF < Error; end
25
+ class EBUSY < Error; end
26
+ class ECANCELED < Error; end
27
+ class ECHARSET < Error; end
28
+ class ECONNABORTED < Error; end
29
+ class ECONNREFUSED < Error; end
30
+ class ECONNRESET < Error; end
31
+ class EDESTADDRREQ < Error; end
32
+ class EEXIST < Error; end
33
+ class EFAULT < Error; end
34
+ class EFBIG < Error; end
35
+ class EHOSTUNREACH < Error; end
36
+ class EINTR < Error; end
37
+ class EINVAL < Error; end
38
+ class EIO < Error; end
39
+ class EISCONN < Error; end
40
+ class EISDIR < Error; end
41
+ class ELOOP < Error; end
42
+ class EMFILE < Error; end
43
+ class EMSGSIZE < Error; end
44
+ class ENAMETOOLONG < Error; end
45
+ class ENETDOWN < Error; end
46
+ class ENETUNREACH < Error; end
47
+ class ENFILE < Error; end
48
+ class ENOBUFS < Error; end
49
+ class ENODEV < Error; end
50
+ class ENOENT < Error; end
51
+ class ENOMEM < Error; end
52
+ class ENONET < Error; end
53
+ class ENOSPC < Error; end
54
+ class ENOSYS < Error; end
55
+ class ENOTCONN < Error; end
56
+ class ENOTDIR < Error; end
57
+ class ENOTEMPTY < Error; end
58
+ class ENOTSOCK < Error; end
59
+ class ENOTSUP < Error; end
60
+ class EPERM < Error; end
61
+ class EPIPE < Error; end
62
+ class EPROTO < Error; end
63
+ class EPROTONOSUPPORT < Error; end
64
+ class EPROTOTYPE < Error; end
65
+ class EROFS < Error; end
66
+ class ESHUTDOWN < Error; end
67
+ class ESPIPE < Error; end
68
+ class ESRCH < Error; end
69
+ class ETIMEDOUT < Error; end
70
+ class EXDEV < Error; end
71
+ class UNKNOWN < Error; end
72
+ class EOF < Error; end
73
+ end
74
+ end