libuv 0.11.22 → 0.12.0

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 +19 -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 -89
  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 +78 -74
  15. data/lib/libuv/ext/ext.rb +260 -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 +281 -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 +60 -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 +153 -154
  37. data/lib/libuv/pipe.rb +184 -203
  38. data/lib/libuv/prepare.rb +56 -56
  39. data/lib/libuv/signal.rb +51 -51
  40. data/lib/libuv/tcp.rb +334 -334
  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 +61 -60
  48. data/spec/cpu_spec.rb +10 -10
  49. data/spec/defer_spec.rb +980 -980
  50. data/spec/dns_spec.rb +96 -90
  51. data/spec/filesystem_spec.rb +270 -261
  52. data/spec/idle_spec.rb +56 -56
  53. data/spec/pipe_spec.rb +160 -160
  54. data/spec/tcp_spec.rb +271 -267
  55. metadata +64 -51
@@ -1,233 +1,233 @@
1
- module Libuv
2
- class Filesystem
3
- include Assertions, Resource, Listener, FsChecks
4
-
5
-
6
- def initialize(loop)
7
- @loop = loop
8
- end
9
-
10
- def unlink(path)
11
- assert_type(String, path, "path must be a String")
12
- @unlink_deferred = @loop.defer
13
-
14
- request = ::Libuv::Ext.create_request(:uv_fs)
15
- pre_check @unlink_deferred, request, ::Libuv::Ext.fs_unlink(@loop, request, path, callback(:on_unlink))
16
- @unlink_deferred.promise
17
- end
18
-
19
- def mkdir(path, mode = 0777)
20
- assert_type(String, path, "path must be a String")
21
- assert_type(Integer, mode, "mode must be an Integer")
22
- @mkdir_deferred = @loop.defer
23
-
24
- request = ::Libuv::Ext.create_request(:uv_fs)
25
- pre_check @mkdir_deferred, request, ::Libuv::Ext.fs_mkdir(@loop, request, path, mode, callback(:on_mkdir))
26
- @mkdir_deferred.promise
27
- end
28
-
29
- def rmdir(path)
30
- assert_type(String, path, "path must be a String")
31
- @rmdir_deferred = @loop.defer
32
-
33
- request = ::Libuv::Ext.create_request(:uv_fs)
34
- pre_check @rmdir_deferred, request, ::Libuv::Ext.fs_rmdir(@loop, request, path, callback(:on_rmdir))
35
- @rmdir_deferred.promise
36
- end
37
-
38
- def readdir(path)
39
- assert_type(String, path, "path must be a String")
40
- @readdir_deferred = @loop.defer
41
-
42
- request = ::Libuv::Ext.create_request(:uv_fs)
43
- pre_check @readdir_deferred, request, ::Libuv::Ext.fs_readdir(@loop, request, path, 0, callback(:on_readdir))
44
- @readdir_deferred.promise
45
- end
46
-
47
- def rename(old_path, new_path)
48
- assert_type(String, old_path, "old_path must be a String")
49
- assert_type(String, new_path, "new_path must be a String")
50
- @rename_deferred = @loop.defer
51
-
52
- request = ::Libuv::Ext.create_request(:uv_fs)
53
- pre_check @rename_deferred, request, ::Libuv::Ext.fs_rename(@loop, request, old_path, new_path, callback(:on_rename))
54
- @rename_deferred.promise
55
- end
56
-
57
- def chmod(path, mode)
58
- assert_type(String, path, "path must be a String")
59
- assert_type(Integer, mode, "mode must be an Integer")
60
- @chmod_deferred = @loop.defer
61
-
62
- request = ::Libuv::Ext.create_request(:uv_fs)
63
- pre_check @chmod_deferred, request, ::Libuv::Ext.fs_chmod(@loop, request, path, mode, callback(:on_chmod))
64
- @chmod_deferred.promise
65
- end
66
-
67
- def utime(path, atime, mtime)
68
- assert_type(String, path, "path must be a String")
69
- assert_type(Integer, atime, "atime must be an Integer")
70
- assert_type(Integer, mtime, "mtime must be an Integer")
71
- @utime_deferred = @loop.defer
72
-
73
- request = ::Libuv::Ext.create_request(:uv_fs)
74
- pre_check @utime_deferred, request, ::Libuv::Ext.fs_utime(@loop, request, path, atime, mtime, callback(:on_utime))
75
- @utime_deferred.promise
76
- end
77
-
78
- def lstat(path)
79
- assert_type(String, path, "path must be a String")
80
- @stat_deferred = @loop.defer
81
-
82
- request = ::Libuv::Ext.create_request(:uv_fs)
83
- pre_check @stat_deferred, request, ::Libuv::Ext.fs_lstat(@loop, request, path, callback(:on_stat))
84
- @stat_deferred.promise
85
- end
86
-
87
- def link(old_path, new_path)
88
- assert_type(String, old_path, "old_path must be a String")
89
- assert_type(String, new_path, "new_path must be a String")
90
- @link_deferred = @loop.defer
91
-
92
- request = ::Libuv::Ext.create_request(:uv_fs)
93
- pre_check @link_deferred, request, ::Libuv::Ext.fs_link(@loop, request, old_path, new_path, callback(:on_link))
94
- @link_deferred.promise
95
- end
96
-
97
- def symlink(old_path, new_path)
98
- assert_type(String, old_path, "old_path must be a String")
99
- assert_type(String, new_path, "new_path must be a String")
100
- @symlink_deferred = @loop.defer
101
-
102
- request = ::Libuv::Ext.create_request(:uv_fs)
103
- pre_check @symlink_deferred, request, ::Libuv::Ext.fs_symlink(@loop, request, old_path, new_path, 0, callback(:on_symlink))
104
- @symlink_deferred.promise
105
- end
106
-
107
- def readlink(path)
108
- assert_type(String, path, "path must be a String")
109
- @readlink_deferred = @loop.defer
110
-
111
- request = ::Libuv::Ext.create_request(:uv_fs)
112
- pre_check @readlink_deferred, request, ::Libuv::Ext.fs_readlink(@loop, request, path, callback(:on_readlink))
113
- @readlink_deferred.promise
114
- end
115
-
116
- def chown(path, uid, gid)
117
- assert_type(String, path, "path must be a String")
118
- assert_type(Integer, uid, "uid must be an Integer")
119
- assert_type(Integer, gid, "gid must be an Integer")
120
- @chown_deferred = @loop.defer
121
-
122
- request = ::Libuv::Ext.create_request(:uv_fs)
123
- pre_check @chown_deferred, request, ::Libuv::Ext.fs_chown(@loop, request, path, uid, gid, callback(:on_chown))
124
- @chown_deferred.promise
125
- end
126
-
127
-
128
- private
129
-
130
-
131
- def on_unlink(req)
132
- if post_check(req, @unlink_deferred)
133
- path = req[:path]
134
- cleanup(req)
135
- @unlink_deferred.resolve(path)
136
- end
137
- @unlink_deferred = nil
138
- end
139
-
140
- def on_mkdir(req)
141
- if post_check(req, @mkdir_deferred)
142
- path = req[:path]
143
- cleanup(req)
144
- @mkdir_deferred.resolve(path)
145
- end
146
- @mkdir_deferred = nil
147
- end
148
-
149
- def on_rmdir(req)
150
- if post_check(req, @rmdir_deferred)
151
- path = req[:path]
152
- cleanup(req)
153
- @rmdir_deferred.resolve(path)
154
- end
155
- @rmdir_deferred = nil
156
- end
157
-
158
- def on_readdir(req)
159
- if post_check(req, @readdir_deferred)
160
- num_files = req[:result]
161
- string_ptr = req[:ptr]
162
- files = string_ptr.null? ? [] : string_ptr.read_array_of_type(FFI::TYPE_STRING, :read_string, num_files)
163
- cleanup(req)
164
- @readdir_deferred.resolve(files)
165
- end
166
- @readdir_deferred = nil
167
- end
168
-
169
- def on_rename(req)
170
- if post_check(req, @rename_deferred)
171
- path = req[:path]
172
- cleanup(req)
173
- @rename_deferred.resolve(path)
174
- end
175
- @rename_deferred = nil
176
- end
177
-
178
- def on_chmod(req)
179
- if post_check(req, @chmod_deferred)
180
- path = req[:path]
181
- cleanup(req)
182
- @chmod_deferred.resolve(path)
183
- end
184
- @chmod_deferred = nil
185
- end
186
-
187
- def on_utime(req)
188
- if post_check(req, @utime_deferred)
189
- path = req[:path]
190
- cleanup(req)
191
- @utime_deferred.resolve(path)
192
- end
193
- @utime_deferred = nil
194
- end
195
-
196
- def on_link(req)
197
- if post_check(req, @link_deferred)
198
- path = req[:path]
199
- cleanup(req)
200
- @link_deferred.resolve(path)
201
- end
202
- @link_deferred = nil
203
- end
204
-
205
- def on_symlink(req)
206
- if post_check(req, @symlink_deferred)
207
- path = req[:path]
208
- cleanup(req)
209
- @symlink_deferred.resolve(path)
210
- end
211
- @symlink_deferred = nil
212
- end
213
-
214
- def on_readlink(req)
215
- if post_check(req, @readlink_deferred)
216
- string_ptr = req[:ptr]
217
- path = string_ptr.null? ? nil : string_ptr.read_string_to_null
218
- cleanup(req)
219
- @readlink_deferred.resolve(path)
220
- end
221
- @readlink_deferred = nil
222
- end
223
-
224
- def on_chown(req)
225
- if post_check(req, @chown_deferred)
226
- path = req[:path]
227
- cleanup(req)
228
- @chown_deferred.resolve(path)
229
- end
230
- @chown_deferred = nil
231
- end
232
- end
1
+ module Libuv
2
+ class Filesystem
3
+ include Assertions, Resource, Listener, FsChecks
4
+
5
+
6
+ def initialize(loop)
7
+ @loop = loop
8
+ end
9
+
10
+ def unlink(path)
11
+ assert_type(String, path, "path must be a String")
12
+ @unlink_deferred = @loop.defer
13
+
14
+ request = ::Libuv::Ext.create_request(:uv_fs)
15
+ pre_check @unlink_deferred, request, ::Libuv::Ext.fs_unlink(@loop, request, path, callback(:on_unlink))
16
+ @unlink_deferred.promise
17
+ end
18
+
19
+ def mkdir(path, mode = 0777)
20
+ assert_type(String, path, "path must be a String")
21
+ assert_type(Integer, mode, "mode must be an Integer")
22
+ @mkdir_deferred = @loop.defer
23
+
24
+ request = ::Libuv::Ext.create_request(:uv_fs)
25
+ pre_check @mkdir_deferred, request, ::Libuv::Ext.fs_mkdir(@loop, request, path, mode, callback(:on_mkdir))
26
+ @mkdir_deferred.promise
27
+ end
28
+
29
+ def rmdir(path)
30
+ assert_type(String, path, "path must be a String")
31
+ @rmdir_deferred = @loop.defer
32
+
33
+ request = ::Libuv::Ext.create_request(:uv_fs)
34
+ pre_check @rmdir_deferred, request, ::Libuv::Ext.fs_rmdir(@loop, request, path, callback(:on_rmdir))
35
+ @rmdir_deferred.promise
36
+ end
37
+
38
+ def readdir(path)
39
+ assert_type(String, path, "path must be a String")
40
+ @readdir_deferred = @loop.defer
41
+
42
+ request = ::Libuv::Ext.create_request(:uv_fs)
43
+ pre_check @readdir_deferred, request, ::Libuv::Ext.fs_readdir(@loop, request, path, 0, callback(:on_readdir))
44
+ @readdir_deferred.promise
45
+ end
46
+
47
+ def rename(old_path, new_path)
48
+ assert_type(String, old_path, "old_path must be a String")
49
+ assert_type(String, new_path, "new_path must be a String")
50
+ @rename_deferred = @loop.defer
51
+
52
+ request = ::Libuv::Ext.create_request(:uv_fs)
53
+ pre_check @rename_deferred, request, ::Libuv::Ext.fs_rename(@loop, request, old_path, new_path, callback(:on_rename))
54
+ @rename_deferred.promise
55
+ end
56
+
57
+ def chmod(path, mode)
58
+ assert_type(String, path, "path must be a String")
59
+ assert_type(Integer, mode, "mode must be an Integer")
60
+ @chmod_deferred = @loop.defer
61
+
62
+ request = ::Libuv::Ext.create_request(:uv_fs)
63
+ pre_check @chmod_deferred, request, ::Libuv::Ext.fs_chmod(@loop, request, path, mode, callback(:on_chmod))
64
+ @chmod_deferred.promise
65
+ end
66
+
67
+ def utime(path, atime, mtime)
68
+ assert_type(String, path, "path must be a String")
69
+ assert_type(Integer, atime, "atime must be an Integer")
70
+ assert_type(Integer, mtime, "mtime must be an Integer")
71
+ @utime_deferred = @loop.defer
72
+
73
+ request = ::Libuv::Ext.create_request(:uv_fs)
74
+ pre_check @utime_deferred, request, ::Libuv::Ext.fs_utime(@loop, request, path, atime, mtime, callback(:on_utime))
75
+ @utime_deferred.promise
76
+ end
77
+
78
+ def lstat(path)
79
+ assert_type(String, path, "path must be a String")
80
+ @stat_deferred = @loop.defer
81
+
82
+ request = ::Libuv::Ext.create_request(:uv_fs)
83
+ pre_check @stat_deferred, request, ::Libuv::Ext.fs_lstat(@loop, request, path, callback(:on_stat))
84
+ @stat_deferred.promise
85
+ end
86
+
87
+ def link(old_path, new_path)
88
+ assert_type(String, old_path, "old_path must be a String")
89
+ assert_type(String, new_path, "new_path must be a String")
90
+ @link_deferred = @loop.defer
91
+
92
+ request = ::Libuv::Ext.create_request(:uv_fs)
93
+ pre_check @link_deferred, request, ::Libuv::Ext.fs_link(@loop, request, old_path, new_path, callback(:on_link))
94
+ @link_deferred.promise
95
+ end
96
+
97
+ def symlink(old_path, new_path)
98
+ assert_type(String, old_path, "old_path must be a String")
99
+ assert_type(String, new_path, "new_path must be a String")
100
+ @symlink_deferred = @loop.defer
101
+
102
+ request = ::Libuv::Ext.create_request(:uv_fs)
103
+ pre_check @symlink_deferred, request, ::Libuv::Ext.fs_symlink(@loop, request, old_path, new_path, 0, callback(:on_symlink))
104
+ @symlink_deferred.promise
105
+ end
106
+
107
+ def readlink(path)
108
+ assert_type(String, path, "path must be a String")
109
+ @readlink_deferred = @loop.defer
110
+
111
+ request = ::Libuv::Ext.create_request(:uv_fs)
112
+ pre_check @readlink_deferred, request, ::Libuv::Ext.fs_readlink(@loop, request, path, callback(:on_readlink))
113
+ @readlink_deferred.promise
114
+ end
115
+
116
+ def chown(path, uid, gid)
117
+ assert_type(String, path, "path must be a String")
118
+ assert_type(Integer, uid, "uid must be an Integer")
119
+ assert_type(Integer, gid, "gid must be an Integer")
120
+ @chown_deferred = @loop.defer
121
+
122
+ request = ::Libuv::Ext.create_request(:uv_fs)
123
+ pre_check @chown_deferred, request, ::Libuv::Ext.fs_chown(@loop, request, path, uid, gid, callback(:on_chown))
124
+ @chown_deferred.promise
125
+ end
126
+
127
+
128
+ private
129
+
130
+
131
+ def on_unlink(req)
132
+ if post_check(req, @unlink_deferred)
133
+ path = req[:path]
134
+ cleanup(req)
135
+ @unlink_deferred.resolve(path)
136
+ end
137
+ @unlink_deferred = nil
138
+ end
139
+
140
+ def on_mkdir(req)
141
+ if post_check(req, @mkdir_deferred)
142
+ path = req[:path]
143
+ cleanup(req)
144
+ @mkdir_deferred.resolve(path)
145
+ end
146
+ @mkdir_deferred = nil
147
+ end
148
+
149
+ def on_rmdir(req)
150
+ if post_check(req, @rmdir_deferred)
151
+ path = req[:path]
152
+ cleanup(req)
153
+ @rmdir_deferred.resolve(path)
154
+ end
155
+ @rmdir_deferred = nil
156
+ end
157
+
158
+ def on_readdir(req)
159
+ if post_check(req, @readdir_deferred)
160
+ num_files = req[:result]
161
+ string_ptr = req[:ptr]
162
+ files = string_ptr.null? ? [] : string_ptr.read_array_of_type(FFI::TYPE_STRING, :read_string, num_files)
163
+ cleanup(req)
164
+ @readdir_deferred.resolve(files)
165
+ end
166
+ @readdir_deferred = nil
167
+ end
168
+
169
+ def on_rename(req)
170
+ if post_check(req, @rename_deferred)
171
+ path = req[:path]
172
+ cleanup(req)
173
+ @rename_deferred.resolve(path)
174
+ end
175
+ @rename_deferred = nil
176
+ end
177
+
178
+ def on_chmod(req)
179
+ if post_check(req, @chmod_deferred)
180
+ path = req[:path]
181
+ cleanup(req)
182
+ @chmod_deferred.resolve(path)
183
+ end
184
+ @chmod_deferred = nil
185
+ end
186
+
187
+ def on_utime(req)
188
+ if post_check(req, @utime_deferred)
189
+ path = req[:path]
190
+ cleanup(req)
191
+ @utime_deferred.resolve(path)
192
+ end
193
+ @utime_deferred = nil
194
+ end
195
+
196
+ def on_link(req)
197
+ if post_check(req, @link_deferred)
198
+ path = req[:path]
199
+ cleanup(req)
200
+ @link_deferred.resolve(path)
201
+ end
202
+ @link_deferred = nil
203
+ end
204
+
205
+ def on_symlink(req)
206
+ if post_check(req, @symlink_deferred)
207
+ path = req[:path]
208
+ cleanup(req)
209
+ @symlink_deferred.resolve(path)
210
+ end
211
+ @symlink_deferred = nil
212
+ end
213
+
214
+ def on_readlink(req)
215
+ if post_check(req, @readlink_deferred)
216
+ string_ptr = req[:ptr]
217
+ path = string_ptr.null? ? nil : string_ptr.read_string_to_null
218
+ cleanup(req)
219
+ @readlink_deferred.resolve(path)
220
+ end
221
+ @readlink_deferred = nil
222
+ end
223
+
224
+ def on_chown(req)
225
+ if post_check(req, @chown_deferred)
226
+ path = req[:path]
227
+ cleanup(req)
228
+ @chown_deferred.resolve(path)
229
+ end
230
+ @chown_deferred = nil
231
+ end
232
+ end
233
233
  end