mt-libuv 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.gitmodules +6 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +24 -0
  6. data/Gemfile +9 -0
  7. data/LICENSE +24 -0
  8. data/README.md +195 -0
  9. data/Rakefile +31 -0
  10. data/ext/README.md +6 -0
  11. data/ext/Rakefile +28 -0
  12. data/lib/mt-libuv/async.rb +51 -0
  13. data/lib/mt-libuv/check.rb +59 -0
  14. data/lib/mt-libuv/coroutines.rb +79 -0
  15. data/lib/mt-libuv/dns.rb +98 -0
  16. data/lib/mt-libuv/error.rb +88 -0
  17. data/lib/mt-libuv/ext/ext.rb +322 -0
  18. data/lib/mt-libuv/ext/platform/darwin_x64.rb +61 -0
  19. data/lib/mt-libuv/ext/platform/unix.rb +69 -0
  20. data/lib/mt-libuv/ext/platform/windows.rb +83 -0
  21. data/lib/mt-libuv/ext/tasks/mac.rb +24 -0
  22. data/lib/mt-libuv/ext/tasks/unix.rb +42 -0
  23. data/lib/mt-libuv/ext/tasks/win.rb +29 -0
  24. data/lib/mt-libuv/ext/tasks.rb +27 -0
  25. data/lib/mt-libuv/ext/types.rb +253 -0
  26. data/lib/mt-libuv/fiber_pool.rb +83 -0
  27. data/lib/mt-libuv/file.rb +309 -0
  28. data/lib/mt-libuv/filesystem.rb +263 -0
  29. data/lib/mt-libuv/fs_event.rb +37 -0
  30. data/lib/mt-libuv/handle.rb +108 -0
  31. data/lib/mt-libuv/idle.rb +59 -0
  32. data/lib/mt-libuv/mixins/accessors.rb +41 -0
  33. data/lib/mt-libuv/mixins/assertions.rb +25 -0
  34. data/lib/mt-libuv/mixins/fs_checks.rb +96 -0
  35. data/lib/mt-libuv/mixins/listener.rb +69 -0
  36. data/lib/mt-libuv/mixins/net.rb +42 -0
  37. data/lib/mt-libuv/mixins/resource.rb +30 -0
  38. data/lib/mt-libuv/mixins/stream.rb +276 -0
  39. data/lib/mt-libuv/pipe.rb +217 -0
  40. data/lib/mt-libuv/prepare.rb +59 -0
  41. data/lib/mt-libuv/q.rb +475 -0
  42. data/lib/mt-libuv/reactor.rb +567 -0
  43. data/lib/mt-libuv/signal.rb +62 -0
  44. data/lib/mt-libuv/spawn.rb +113 -0
  45. data/lib/mt-libuv/tcp.rb +465 -0
  46. data/lib/mt-libuv/timer.rb +107 -0
  47. data/lib/mt-libuv/tty.rb +42 -0
  48. data/lib/mt-libuv/udp.rb +302 -0
  49. data/lib/mt-libuv/version.rb +5 -0
  50. data/lib/mt-libuv/work.rb +86 -0
  51. data/lib/mt-libuv.rb +80 -0
  52. data/mt-libuv.gemspec +62 -0
  53. data/spec/async_spec.rb +67 -0
  54. data/spec/coroutines_spec.rb +121 -0
  55. data/spec/cpu_spec.rb +10 -0
  56. data/spec/defer_spec.rb +906 -0
  57. data/spec/dns_spec.rb +110 -0
  58. data/spec/dsl_spec.rb +43 -0
  59. data/spec/filesystem_spec.rb +270 -0
  60. data/spec/idle_spec.rb +44 -0
  61. data/spec/pipe_spec.rb +151 -0
  62. data/spec/spawn_spec.rb +119 -0
  63. data/spec/tcp_spec.rb +272 -0
  64. data/spec/test.sh +4 -0
  65. data/spec/test_fail.sh +3 -0
  66. data/spec/test_read.sh +3 -0
  67. data/spec/timer_spec.rb +14 -0
  68. data/spec/udp_spec.rb +73 -0
  69. data/spec/zen_spec.rb +34 -0
  70. metadata +196 -0
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MTLibuv
4
+ class Error < StandardError
5
+ class E2BIG < Error; end
6
+ class EACCES < Error; end
7
+ class EADDRINUSE < Error; end
8
+ class EADDRNOTAVAIL < Error; end
9
+ class EAFNOSUPPORT < Error; end
10
+ class EAGAIN < Error; end
11
+ class EAI_ADDRFAMILY < Error; end
12
+ class EAI_AGAIN < Error; end
13
+ class EAI_BADFLAGS < Error; end
14
+ class EAI_BADHINTS < Error; end
15
+ class EAI_CANCELED < Error; end
16
+ class EAI_FAIL < Error; end
17
+ class EAI_FAMILY < Error; end
18
+ class EAI_MEMORY < Error; end
19
+ class EAI_NODATA < Error; end
20
+ class EAI_NONAME < Error; end
21
+ class EAI_OVERFLOW < Error; end
22
+ class EAI_PROTOCOL < Error; end
23
+ class EAI_SERVICE < Error; end
24
+ class EAI_SOCKTYPE < Error; end
25
+ class EALREADY < Error; end
26
+ class EBADF < Error; end
27
+ class EBUSY < Error; end
28
+ class ECANCELED < Error; end
29
+ class ECHARSET < Error; end
30
+ class ECONNABORTED < Error; end
31
+ class ECONNREFUSED < Error; end
32
+ class ECONNRESET < Error; end
33
+ class EDESTADDRREQ < Error; end
34
+ class EEXIST < Error; end
35
+ class EFAULT < Error; end
36
+ class EFBIG < Error; end
37
+ class EHOSTUNREACH < Error; end
38
+ class EINTR < Error; end
39
+ class EINVAL < Error; end
40
+ class EIO < Error; end
41
+ class EISCONN < Error; end
42
+ class EISDIR < Error; end
43
+ class ELOOP < Error; end
44
+ class EMFILE < Error; end
45
+ class EMSGSIZE < Error; end
46
+ class ENAMETOOLONG < Error; end
47
+ class ENETDOWN < Error; end
48
+ class ENETUNREACH < Error; end
49
+ class ENFILE < Error; end
50
+ class ENOBUFS < Error; end
51
+ class ENODEV < Error; end
52
+ class ENOENT < Error; end
53
+ class ENOMEM < Error; end
54
+ class ENONET < Error; end
55
+ class ENOPROTOOPT < Error; end
56
+ class ENOSPC < Error; end
57
+ class ENOSYS < Error; end
58
+ class ENOTCONN < Error; end
59
+ class ENOTDIR < Error; end
60
+ class ENOTEMPTY < Error; end
61
+ class ENOTSOCK < Error; end
62
+ class ENOTSUP < Error; end
63
+ class EPERM < Error; end
64
+ class EPIPE < Error; end
65
+ class EPROTO < Error; end
66
+ class EPROTONOSUPPORT < Error; end
67
+ class EPROTOTYPE < Error; end
68
+ class ERANGE < Error; end
69
+ class EROFS < Error; end
70
+ class ESHUTDOWN < Error; end
71
+ class ESPIPE < Error; end
72
+ class ESRCH < Error; end
73
+ class ETIMEDOUT < Error; end
74
+ class ETXTBSY < Error; end
75
+ class EXDEV < Error; end
76
+ class UNKNOWN < Error; end
77
+ class EOF < Error; end
78
+ class ENXIO < Error; end
79
+ class EMLINK < Error; end
80
+ class EHOSTDOWN < Error; end
81
+ class EREMOTEIO < Error; end
82
+
83
+ # Non-zero exit code
84
+ class ProcessExitCode < Error
85
+ attr_accessor :exit_status, :term_signal
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,322 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+ require 'ffi'
5
+
6
+ module MTLibuv
7
+ module Ext
8
+ extend Forwardable
9
+ extend FFI::Library
10
+ FFI::DEBUG = 10
11
+
12
+
13
+ # In windows each library requires its own module
14
+ module LIBC
15
+ extend FFI::Library
16
+ ffi_lib(FFI::Library::LIBC).first
17
+
18
+ attach_function :malloc, [:size_t], :pointer
19
+ attach_function :free, [:pointer], :void
20
+ end
21
+
22
+ def self.malloc(bytes)
23
+ ::MTLibuv::Ext::LIBC.malloc(bytes)
24
+ end
25
+
26
+ def self.free(pointer)
27
+ ::MTLibuv::Ext::LIBC.free(pointer)
28
+ end
29
+
30
+
31
+ def self.path_to_internal_libuv
32
+ @path_to_internal_libuv ||= ::File.expand_path("../../../../ext/libuv/lib/libuv.#{FFI::Platform::LIBSUFFIX}", __FILE__)
33
+ end
34
+
35
+
36
+ begin
37
+ lib_path = ::File.expand_path('../', path_to_internal_libuv)
38
+
39
+ # bias the library discovery to a path inside the gem first, then
40
+ # to the usual system paths
41
+ paths = [
42
+ lib_path,
43
+ '/usr/local/lib',
44
+ '/opt/local/lib',
45
+ '/usr/lib64'
46
+ ]
47
+
48
+ if FFI::Platform.mac?
49
+ # Using home/user/lib is the best we can do on OSX
50
+ # Primarily a dev platform so that is OK
51
+ paths.unshift "#{ENV['HOME']}/lib"
52
+ LIBUV_PATHS = paths.map{|path| "#{path}/libuv.1.#{FFI::Platform::LIBSUFFIX}"}
53
+ else
54
+ LIBUV_PATHS = paths.map{|path| "#{path}/libuv.#{FFI::Platform::LIBSUFFIX}"}
55
+ if FFI::Platform.windows?
56
+ module Kernel32
57
+ extend FFI::Library
58
+ ffi_lib 'Kernel32'
59
+
60
+ attach_function :add_dll_dir, :AddDllDirectory,
61
+ [ :buffer_in ], :pointer
62
+ end
63
+ # This ensures that externally loaded libraries like the libcouchbase gem
64
+ # will always use the same binary image and not load a second into memory
65
+ Kernel32.add_dll_dir "#{lib_path}\0".encode("UTF-16LE")
66
+ else # UNIX
67
+ # TODO:: ??
68
+ end
69
+ end
70
+
71
+ libuv = ffi_lib(LIBUV_PATHS + %w{libuv}).first
72
+ rescue LoadError
73
+ warn <<-WARNING
74
+ Unable to load this gem. The libuv library (or DLL) could not be found.
75
+ If this is a Windows platform, make sure libuv.dll is on the PATH.
76
+ For non-Windows platforms, make sure libuv is located in this search path:
77
+ #{LIBUV_PATHS.inspect}
78
+ WARNING
79
+ exit 255
80
+ end
81
+
82
+
83
+ require 'mt-libuv/ext/types'
84
+
85
+
86
+ attach_function :handle_size, :uv_handle_size, [:uv_handle_type], :size_t
87
+ attach_function :req_size, :uv_req_size, [:uv_req_type], :size_t
88
+
89
+
90
+ # We need to calculate where the FS request data is located using req_size
91
+ class FsRequest < FFI::Struct
92
+ layout :req_data, [:uint8, Ext.req_size(:req)],
93
+ :fs_type, :uv_fs_type,
94
+ :loop, :uv_loop_t,
95
+ :fs_callback, :pointer,
96
+ :result, :ssize_t,
97
+ :ptr, :pointer,
98
+ :path, :string,
99
+ :stat, UvStat
100
+ end
101
+ callback :uv_fs_cb, [FsRequest.by_ref], :void
102
+
103
+
104
+ attach_function :version_number, :uv_version, [], :uint
105
+ attach_function :version_string, :uv_version_string, [], :string
106
+ attach_function :loop_alive, :uv_loop_alive, [:uv_loop_t], :int
107
+
108
+ attach_function :loop_size, :uv_loop_size, [], :size_t, :blocking => false
109
+ attach_function :loop_init, :uv_loop_init, [:uv_loop_t], :int, :blocking => false
110
+ attach_function :loop_close, :uv_loop_close, [:uv_loop_t], :int, :blocking => false
111
+
112
+ attach_function :loop_new, :uv_loop_new, [], :uv_loop_t, :blocking => true
113
+ attach_function :loop_delete, :uv_loop_delete, [:uv_loop_t], :void, :blocking => true
114
+ attach_function :default_loop, :uv_default_loop, [], :uv_loop_t, :blocking => true
115
+ attach_function :run, :uv_run, [:uv_loop_t, :uv_run_mode], :int, :blocking => true
116
+ attach_function :stop, :uv_stop, [:uv_loop_t], :void, :blocking => true
117
+ attach_function :update_time, :uv_update_time, [:uv_loop_t], :void, :blocking => true
118
+ attach_function :now, :uv_now, [:uv_loop_t], :uint64
119
+
120
+ attach_function :backend_timeout, :uv_backend_timeout, [:uv_loop_t], :int, :blocking => true
121
+ attach_function :backend_fd, :uv_backend_fd, [:uv_loop_t], :int, :blocking => true
122
+
123
+ attach_function :strerror, :uv_strerror, [:int], :string
124
+ attach_function :err_name, :uv_err_name, [:int], :string
125
+
126
+ attach_function :ref, :uv_ref, [:uv_handle_t], :void
127
+ attach_function :unref, :uv_unref, [:uv_handle_t], :void
128
+ attach_function :has_ref, :uv_has_ref, [:uv_handle_t], :int
129
+ attach_function :is_active, :uv_is_active, [:uv_handle_t], :int
130
+ attach_function :walk, :uv_walk, [:uv_loop_t, :uv_walk_cb, :pointer], :void, :blocking => true
131
+ attach_function :close, :uv_close, [:uv_handle_t, :uv_close_cb], :void, :blocking => true
132
+ attach_function :is_closing, :uv_is_closing, [:uv_handle_t], :int, :blocking => true
133
+ # TODO:: Implement https://github.com/joyent/libuv/commit/0ecee213eac91beca141130cff2c7826242dab5a
134
+ # uv_recv_buffer_size
135
+ # uv_send_buffer_size
136
+ # https://github.com/joyent/libuv/commit/4ca9a363897cfa60f4e2229e4f15ac5abd7fd103
137
+ # uv_fileno
138
+
139
+ attach_function :buf_init, :uv_buf_init, [:pointer, :size_t], UvBuf.by_value
140
+
141
+ attach_function :listen, :uv_listen, [:uv_stream_t, :int, :uv_connection_cb], :int, :blocking => true
142
+ attach_function :accept, :uv_accept, [:uv_stream_t, :uv_stream_t], :int, :blocking => true
143
+ attach_function :read_start, :uv_read_start, [:uv_stream_t, :uv_alloc_cb, :uv_read_cb], :int, :blocking => true
144
+ attach_function :read_stop, :uv_read_stop, [:uv_stream_t], :int, :blocking => true
145
+ attach_function :try_write, :uv_try_write, [:uv_stream_t, :pointer, :uint], :int, :blocking => true
146
+ attach_function :write, :uv_write, [:uv_write_t, :uv_stream_t, :pointer, :uint, :uv_write_cb], :int, :blocking => true
147
+ attach_function :write2, :uv_write2, [:uv_write_t, :uv_stream_t, :pointer, :uint, :uv_stream_t, :uv_write_cb], :int, :blocking => true
148
+ attach_function :is_readable, :uv_is_readable, [:uv_stream_t], :int, :blocking => true
149
+ attach_function :is_writable, :uv_is_writable, [:uv_stream_t], :int, :blocking => true
150
+ attach_function :shutdown, :uv_shutdown, [:uv_shutdown_t, :uv_stream_t, :uv_shutdown_cb], :int, :blocking => true
151
+
152
+ attach_function :tcp_init, :uv_tcp_init, [:uv_loop_t, :uv_tcp_t], :int, :blocking => true
153
+ attach_function :tcp_init_ex, :uv_tcp_init_ex, [:uv_loop_t, :uv_tcp_t, :uint], :int, :blocking => true
154
+ attach_function :tcp_open, :uv_tcp_open, [:uv_tcp_t, :uv_os_sock_t], :int, :blocking => true
155
+ attach_function :tcp_nodelay, :uv_tcp_nodelay, [:uv_tcp_t, :int], :int, :blocking => true
156
+ attach_function :tcp_keepalive, :uv_tcp_keepalive, [:uv_tcp_t, :int, :uint], :int, :blocking => true
157
+ attach_function :tcp_simultaneous_accepts, :uv_tcp_simultaneous_accepts, [:uv_tcp_t, :int], :int, :blocking => true
158
+ attach_function :tcp_bind, :uv_tcp_bind, [:uv_tcp_t, :sockaddr_in, :uint], :int, :blocking => true
159
+ attach_function :tcp_getsockname, :uv_tcp_getsockname, [:uv_tcp_t, :pointer, :pointer], :int, :blocking => true
160
+ attach_function :tcp_getpeername, :uv_tcp_getpeername, [:uv_tcp_t, :pointer, :pointer], :int, :blocking => true
161
+ attach_function :tcp_connect, :uv_tcp_connect, [:uv_connect_t, :uv_tcp_t, :sockaddr_in, :uv_connect_cb], :int, :blocking => true
162
+
163
+ attach_function :udp_init, :uv_udp_init, [:uv_loop_t, :uv_udp_t], :int, :blocking => true
164
+ attach_function :udp_init_ex, :uv_udp_init_ex, [:uv_loop_t, :uv_udp_t, :uint], :int, :blocking => true
165
+ attach_function :udp_open, :uv_udp_open, [:uv_udp_t, :uv_os_sock_t], :int, :blocking => true
166
+ attach_function :udp_bind, :uv_udp_bind, [:uv_udp_t, :sockaddr_in, :uint], :int, :blocking => true
167
+ attach_function :udp_getsockname, :uv_udp_getsockname, [:uv_udp_t, :pointer, :pointer], :int, :blocking => true
168
+ attach_function :udp_set_membership, :uv_udp_set_membership, [:uv_udp_t, :string, :string, :uv_membership], :int, :blocking => true
169
+ attach_function :udp_set_multicast_loop, :uv_udp_set_multicast_loop, [:uv_udp_t, :int], :int, :blocking => true
170
+ attach_function :udp_set_multicast_ttl, :uv_udp_set_multicast_ttl, [:uv_udp_t, :int], :int, :blocking => true
171
+ attach_function :udp_set_broadcast, :uv_udp_set_broadcast, [:uv_udp_t, :int], :int, :blocking => true
172
+ attach_function :udp_set_ttl, :uv_udp_set_ttl, [:uv_udp_t, :int], :int, :blocking => true
173
+ attach_function :udp_try_send, :uv_udp_try_send, [:uv_udp_t, :pointer, :int, :sockaddr_in], :int, :blocking => true
174
+ attach_function :udp_send, :uv_udp_send, [:uv_udp_send_t, :uv_udp_t, :pointer, :int, :sockaddr_in, :uv_udp_send_cb], :int, :blocking => true
175
+ attach_function :udp_recv_start, :uv_udp_recv_start, [:uv_udp_t, :uv_alloc_cb, :uv_udp_recv_cb], :int, :blocking => true
176
+ attach_function :udp_recv_stop, :uv_udp_recv_stop, [:uv_udp_t], :int, :blocking => true
177
+
178
+ attach_function :tty_init, :uv_tty_init, [:uv_loop_t, :uv_tty_t, :uv_file, :int], :int, :blocking => true
179
+ attach_function :tty_set_mode, :uv_tty_set_mode, [:uv_tty_t, :int], :int, :blocking => true
180
+ attach_function :tty_reset_mode, :uv_tty_reset_mode, [], :void, :blocking => true
181
+ attach_function :tty_get_winsize, :uv_tty_get_winsize, [:uv_tty_t, :pointer, :pointer], :int, :blocking => true
182
+
183
+ attach_function :guess_handle, :uv_guess_handle, [:uv_file], :uv_handle_type, :blocking => true
184
+
185
+ attach_function :pipe_init, :uv_pipe_init, [:uv_loop_t, :uv_pipe_t, :int], :int, :blocking => true
186
+ attach_function :pipe_open, :uv_pipe_open, [:uv_pipe_t, :uv_file], :void, :blocking => true
187
+ attach_function :pipe_bind, :uv_pipe_bind, [:uv_pipe_t, :string], :int, :blocking => true
188
+ attach_function :pipe_connect, :uv_pipe_connect, [:uv_connect_t, :uv_pipe_t, :string, :uv_connect_cb], :void, :blocking => true
189
+ attach_function :pipe_pending_instances, :uv_pipe_pending_instances, [:uv_pipe_t, :int], :void, :blocking => true
190
+ attach_function :pipe_pending_count, :uv_pipe_pending_count, [:uv_pipe_t], :int, :blocking => true
191
+ attach_function :pipe_pending_type, :uv_pipe_pending_type, [:uv_pipe_t], :uv_handle_type, :blocking => true
192
+ attach_function :pipe_getsockname, :uv_pipe_getsockname, [:uv_pipe_t, :pointer, :pointer], :int, :blocking => true
193
+ attach_function :pipe_getpeername, :uv_pipe_getpeername, [:uv_pipe_t, :pointer, :pointer], :int, :blocking => true
194
+
195
+ attach_function :prepare_init, :uv_prepare_init, [:uv_loop_t, :uv_prepare_t], :int, :blocking => true
196
+ attach_function :prepare_start, :uv_prepare_start, [:uv_prepare_t, :uv_prepare_cb], :int, :blocking => true
197
+ attach_function :prepare_stop, :uv_prepare_stop, [:uv_prepare_t], :int, :blocking => true
198
+
199
+ attach_function :check_init, :uv_check_init, [:uv_loop_t, :uv_check_t], :int, :blocking => true
200
+ attach_function :check_start, :uv_check_start, [:uv_check_t, :uv_check_cb], :int, :blocking => true
201
+ attach_function :check_stop, :uv_check_stop, [:uv_check_t], :int, :blocking => true
202
+
203
+ attach_function :idle_init, :uv_idle_init, [:uv_loop_t, :uv_idle_t], :int, :blocking => true
204
+ attach_function :idle_start, :uv_idle_start, [:uv_idle_t, :uv_idle_cb], :int, :blocking => true
205
+ attach_function :idle_stop, :uv_idle_stop, [:uv_idle_t], :int, :blocking => true
206
+
207
+ attach_function :async_init, :uv_async_init, [:uv_loop_t, :uv_async_t, :uv_async_cb], :int, :blocking => true
208
+ attach_function :async_send, :uv_async_send, [:uv_async_t], :int, :blocking => true
209
+
210
+ attach_function :timer_init, :uv_timer_init, [:uv_loop_t, :uv_timer_t], :int, :blocking => true
211
+ attach_function :timer_start, :uv_timer_start, [:uv_timer_t, :uv_timer_cb, :int64_t, :int64_t], :int, :blocking => true
212
+ attach_function :timer_stop, :uv_timer_stop, [:uv_timer_t], :int, :blocking => true
213
+ attach_function :timer_again, :uv_timer_again, [:uv_timer_t], :int, :blocking => true
214
+ attach_function :timer_set_repeat, :uv_timer_set_repeat, [:uv_timer_t, :int64_t], :void, :blocking => true
215
+ attach_function :timer_get_repeat, :uv_timer_get_repeat, [:uv_timer_t], :int64_t, :blocking => true
216
+ #:addrinfo
217
+ attach_function :getaddrinfo, :uv_getaddrinfo, [:uv_loop_t, :uv_getaddrinfo_t, :uv_getaddrinfo_cb, :string, :string, UvAddrinfo.by_ref], :int
218
+ attach_function :freeaddrinfo, :uv_freeaddrinfo, [UvAddrinfo.by_ref], :void
219
+
220
+ attach_function :spawn, :uv_spawn, [:uv_loop_t, :uv_process_t, UvProcessOptions.by_ref], :int, :blocking => true
221
+ attach_function :process_kill, :uv_process_kill, [:uv_process_t, :int], :int, :blocking => true
222
+ attach_function :kill, :uv_kill, [:int, :int], :int, :blocking => true
223
+ attach_function :queue_work, :uv_queue_work, [:uv_loop_t, :uv_work_t, :uv_work_cb, :uv_after_work_cb], :int, :blocking => true
224
+ attach_function :cancel, :uv_cancel, [:pointer], :int, :blocking => true
225
+ attach_function :setup_args, :uv_setup_args, [:int, :varargs], :pointer, :blocking => true
226
+ attach_function :get_process_title, :uv_get_process_title, [:pointer, :size_t], :int, :blocking => true
227
+ attach_function :set_process_title, :uv_set_process_title, [:string], :int, :blocking => true
228
+ attach_function :resident_set_memory, :uv_resident_set_memory, [:size_t], :int, :blocking => true
229
+
230
+ attach_function :uptime, :uv_uptime, [:pointer], :int, :blocking => true
231
+ attach_function :cpu_info, :uv_cpu_info, [:uv_cpu_info_t, :pointer], :int, :blocking => true
232
+ attach_function :loadavg, :uv_loadavg, [:pointer], :void, :blocking => true
233
+ attach_function :free_cpu_info, :uv_free_cpu_info, [:uv_cpu_info_t, :int], :void, :blocking => true
234
+ attach_function :interface_addresses, :uv_interface_addresses, [:uv_interface_address_t, :pointer], :int, :blocking => true
235
+ attach_function :free_interface_addresses, :uv_free_interface_addresses, [:uv_interface_address_t, :int], :void, :blocking => true
236
+
237
+ attach_function :fs_req_cleanup, :uv_fs_req_cleanup, [:uv_fs_t], :void, :blocking => true
238
+ attach_function :fs_close, :uv_fs_close, [:uv_loop_t, :uv_fs_t, :uv_file, :uv_fs_cb], :int, :blocking => true
239
+ attach_function :fs_open, :uv_fs_open, [:uv_loop_t, :uv_fs_t, :string, :int, :int, :uv_fs_cb], :int, :blocking => true
240
+ attach_function :fs_read, :uv_fs_read, [:uv_loop_t, :uv_fs_t, :uv_file, :pointer, :uint, :off_t, :uv_fs_cb], :int, :blocking => true
241
+ attach_function :fs_unlink, :uv_fs_unlink, [:uv_loop_t, :uv_fs_t, :string, :uv_fs_cb], :int, :blocking => true
242
+ attach_function :fs_write, :uv_fs_write, [:uv_loop_t, :uv_fs_t, :uv_file, :pointer, :uint, :off_t, :uv_fs_cb], :int, :blocking => true
243
+ attach_function :fs_mkdir, :uv_fs_mkdir, [:uv_loop_t, :uv_fs_t, :string, :int, :uv_fs_cb], :int, :blocking => true
244
+ attach_function :fs_rmdir, :uv_fs_rmdir, [:uv_loop_t, :uv_fs_t, :string, :uv_fs_cb], :int, :blocking => true
245
+ attach_function :fs_readdir, :uv_fs_scandir, [:uv_loop_t, :uv_fs_t, :string, :int, :uv_fs_cb], :int, :blocking => true
246
+ attach_function :fs_readdir_next, :uv_fs_scandir_next, [:uv_fs_t, :uv_dirent_t], :int, :blocking => true
247
+ attach_function :fs_stat, :uv_fs_stat, [:uv_loop_t, :uv_fs_t, :string, :uv_fs_cb], :int, :blocking => true
248
+ attach_function :fs_fstat, :uv_fs_fstat, [:uv_loop_t, :uv_fs_t, :uv_file, :uv_fs_cb], :int, :blocking => true
249
+ attach_function :fs_rename, :uv_fs_rename, [:uv_loop_t, :uv_fs_t, :string, :string, :uv_fs_cb], :int, :blocking => true
250
+ attach_function :fs_fsync, :uv_fs_fsync, [:uv_loop_t, :uv_fs_t, :uv_file, :uv_fs_cb], :int, :blocking => true
251
+ attach_function :fs_fdatasync, :uv_fs_fdatasync, [:uv_loop_t, :uv_fs_t, :uv_file, :uv_fs_cb], :int, :blocking => true
252
+ attach_function :fs_ftruncate, :uv_fs_ftruncate, [:uv_loop_t, :uv_fs_t, :uv_file, :off_t, :uv_fs_cb], :int, :blocking => true
253
+ attach_function :fs_sendfile, :uv_fs_sendfile, [:uv_loop_t, :uv_fs_t, :uv_file, :uv_file, :off_t, :size_t, :uv_fs_cb], :int, :blocking => true
254
+ attach_function :fs_chmod, :uv_fs_chmod, [:uv_loop_t, :uv_fs_t, :string, :int, :uv_fs_cb], :int, :blocking => true
255
+ attach_function :fs_utime, :uv_fs_utime, [:uv_loop_t, :uv_fs_t, :string, :double, :double, :uv_fs_cb], :int, :blocking => true
256
+ attach_function :fs_futime, :uv_fs_futime, [:uv_loop_t, :uv_fs_t, :uv_file, :double, :double, :uv_fs_cb], :int, :blocking => true
257
+ attach_function :fs_access, :uv_fs_access, [:uv_loop_t, :uv_fs_t, :string, :int, :uv_fs_cb], :int, :blocking => true
258
+ attach_function :fs_lstat, :uv_fs_lstat, [:uv_loop_t, :uv_fs_t, :string, :uv_fs_cb], :int, :blocking => true
259
+ attach_function :fs_link, :uv_fs_link, [:uv_loop_t, :uv_fs_t, :string, :string, :uv_fs_cb], :int, :blocking => true
260
+ attach_function :fs_symlink, :uv_fs_symlink, [:uv_loop_t, :uv_fs_t, :string, :string, :int, :uv_fs_cb], :int, :blocking => true
261
+ attach_function :fs_readlink, :uv_fs_readlink, [:uv_loop_t, :uv_fs_t, :string, :uv_fs_cb], :int, :blocking => true
262
+ attach_function :fs_fchmod, :uv_fs_fchmod, [:uv_loop_t, :uv_fs_t, :uv_file, :int, :uv_fs_cb], :int, :blocking => true
263
+ attach_function :fs_chown, :uv_fs_chown, [:uv_loop_t, :uv_fs_t, :string, :int, :int, :uv_fs_cb], :int, :blocking => true
264
+ attach_function :fs_fchown, :uv_fs_fchown, [:uv_loop_t, :uv_fs_t, :uv_file, :int, :int, :uv_fs_cb], :int, :blocking => true
265
+
266
+ attach_function :fs_event_init, :uv_fs_event_init, [:uv_loop_t, :uv_fs_event_t, :string, :uv_fs_event_cb, :int], :int, :blocking => true
267
+
268
+ attach_function :ip4_addr, :uv_ip4_addr, [:string, :int, :sockaddr_in4], :int
269
+ attach_function :ip6_addr, :uv_ip6_addr, [:string, :int, :sockaddr_in6], :int
270
+ attach_function :ip4_name, :uv_ip4_name, [:sockaddr_in4, :pointer, :size_t], :int
271
+ attach_function :ip6_name, :uv_ip6_name, [:sockaddr_in6, :pointer, :size_t], :int
272
+ #TODO:: attach_function :inet_ntop, :uv_inet_ntop, [:int, :pointer, ]
273
+ #TODO:: attach_function :uv_inet_pton
274
+
275
+ attach_function :exepath, :uv_exepath, [:pointer, :size_t], :int, :blocking => true
276
+ attach_function :cwd, :uv_cwd, [:pointer, :size_t], :int, :blocking => true
277
+ attach_function :chdir, :uv_chdir, [:string], :int, :blocking => true
278
+ attach_function :get_free_memory, :uv_get_free_memory, [], :uint64, :blocking => true
279
+ attach_function :get_total_memory, :uv_get_total_memory, [], :uint64, :blocking => true
280
+ attach_function :hrtime, :uv_hrtime, [], :uint64, :blocking => true
281
+ attach_function :disable_stdio_inheritance, :uv_disable_stdio_inheritance, [], :void, :blocking => true
282
+ attach_function :dlopen, :uv_dlopen, [:string, :uv_lib_t], :int, :blocking => true
283
+ attach_function :dlclose, :uv_dlclose, [:uv_lib_t], :int, :blocking => true
284
+ attach_function :dlsym, :uv_dlsym, [:uv_lib_t, :string, :pointer], :int, :blocking => true
285
+ attach_function :dlerror, :uv_dlerror, [:uv_lib_t], :string
286
+
287
+ attach_function :mutex_init, :uv_mutex_init, [:uv_mutex_t], :int, :blocking => true
288
+ attach_function :mutex_destroy, :uv_mutex_destroy, [:uv_mutex_t], :void, :blocking => true
289
+ attach_function :mutex_lock, :uv_mutex_lock, [:uv_mutex_t], :void, :blocking => true
290
+ attach_function :mutex_trylock, :uv_mutex_trylock, [:uv_mutex_t], :int, :blocking => true
291
+ attach_function :mutex_unlock, :uv_mutex_unlock, [:uv_mutex_t], :void, :blocking => true
292
+
293
+ attach_function :signal_init, :uv_signal_init, [:uv_loop_t, :uv_signal_t], :int, :blocking => true
294
+ attach_function :signal_start, :uv_signal_start, [:uv_signal_t, :uv_signal_cb, :int], :int, :blocking => true
295
+ attach_function :signal_stop, :uv_signal_stop, [:uv_signal_t], :int, :blocking => true
296
+
297
+ attach_function :rwlock_init, :uv_rwlock_init, [:uv_rwlock_t], :int, :blocking => true
298
+ attach_function :rwlock_destroy, :uv_rwlock_destroy, [:uv_rwlock_t], :void, :blocking => true
299
+ attach_function :rwlock_rdlock, :uv_rwlock_rdlock, [:uv_rwlock_t], :void, :blocking => true
300
+ attach_function :rwlock_tryrdlock, :uv_rwlock_tryrdlock, [:uv_rwlock_t], :int, :blocking => true
301
+ attach_function :rwlock_rdunlock, :uv_rwlock_rdunlock, [:uv_rwlock_t], :void, :blocking => true
302
+ attach_function :rwlock_wrlock, :uv_rwlock_wrlock, [:uv_rwlock_t], :void, :blocking => true
303
+ attach_function :rwlock_trywrlock, :uv_rwlock_trywrlock, [:uv_rwlock_t], :int, :blocking => true
304
+ attach_function :rwlock_wrunlock, :uv_rwlock_wrunlock, [:uv_rwlock_t], :void, :blocking => true
305
+
306
+ attach_function :once, :uv_once, [:uv_once_t, :uv_cb], :void, :blocking => true
307
+ attach_function :thread_create, :uv_thread_create, [:uv_thread_t, :uv_cb], :int, :blocking => true
308
+ attach_function :thread_join, :uv_thread_join, [:uv_thread_t], :int, :blocking => true
309
+
310
+
311
+ # Predetermine the handle sizes
312
+ enum_type(:uv_handle_type).symbols.each do |handle_type|
313
+ handle_size = Ext.handle_size(handle_type)
314
+ define_singleton_method(:"allocate_handle_#{handle_type}") { ::MTLibuv::Ext::LIBC.malloc(handle_size) }
315
+ end
316
+
317
+ enum_type(:uv_req_type).symbols.each do |request_type|
318
+ request_size = Ext.req_size(request_type)
319
+ define_singleton_method(:"allocate_request_#{request_type}") { ::MTLibuv::Ext::LIBC.malloc(request_size) }
320
+ end
321
+ end
322
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MTLibuv
4
+ module Ext
5
+ class UvFSStat < FFI::Struct
6
+ layout :st_dev, :dev_t, :st_mode, :mode_t, :st_nlink, :nlink_t,
7
+ :st_ino, :ino_t, :st_uid, :uid_t, :st_gid, :gid_t, :st_rdev,
8
+ :dev_t, :st_atime, :time_t, :st_mtime, :time_t, :st_ctime,
9
+ :time_t, :st_size, :off_t, :st_blocks, :blkcnt_t, :st_blksize,
10
+ :blksize_t, :st_flags, :uint32, :st_gen, :uint32, :st_lspare,
11
+ :int32, :st_qspare_0, :int64, :st_qspare_1, :int64
12
+ end
13
+
14
+ class Sockaddr < FFI::Struct
15
+ layout :sa_len, :uint8,
16
+ :sa_family, :sa_family_t,
17
+ :sa_data, [:char, 14]
18
+ end
19
+
20
+ class InAddr < FFI::Struct
21
+ layout :s_addr, :in_addr_t
22
+ end
23
+
24
+ class SockaddrIn < FFI::Struct
25
+ layout :sin_len, :uint8,
26
+ :sin_family, :sa_family_t,
27
+ :sin_port, :in_port_t,
28
+ :sin_addr, InAddr,
29
+ :sin_zero, [:char, 8]
30
+ end
31
+
32
+ class U6Addr < FFI::Union
33
+ layout :__u6_addr8, [:uint8, 16],
34
+ :__u6_addr16, [:uint16, 8]
35
+ end
36
+
37
+ class In6Addr < FFI::Struct
38
+ layout :__u6_addr, U6Addr
39
+ end
40
+
41
+ class SockaddrIn6 < FFI::Struct
42
+ layout :sin6_len, :uint8,
43
+ :sin6_family, :sa_family_t,
44
+ :sin6_port, :in_port_t,
45
+ :sin6_flowinfo, :uint32,
46
+ :sin6_addr, In6Addr,
47
+ :sin6_scope_id, :uint32
48
+ end
49
+
50
+ class UvAddrinfo < FFI::Struct
51
+ layout :flags, :int,
52
+ :family, :int,
53
+ :socktype, :int,
54
+ :protocol, :int,
55
+ :addrlen, :socklen_t,
56
+ :canonname, :string,
57
+ :addr, Sockaddr.by_ref,
58
+ :next, UvAddrinfo.by_ref
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MTLibuv
4
+ module Ext
5
+ typedef :int, :uv_os_sock_t
6
+
7
+ # blksize_t, in_addr_t is not yet part of types.conf on linux
8
+ typedef :long, :blksize_t
9
+ typedef :uint32, :in_addr_t
10
+ typedef :ushort, :in_port_t
11
+
12
+ class InAddr < FFI::Struct
13
+ layout :s_addr, :in_addr_t
14
+ end
15
+
16
+ class SockaddrIn < FFI::Struct
17
+ layout :sin_family, :sa_family_t,
18
+ :sin_port, :in_port_t,
19
+ :sin_addr, InAddr,
20
+ :sin_zero, [:char, 8]
21
+ end
22
+
23
+ class U6Addr < FFI::Union
24
+ layout :__u6_addr8, [:uint8, 16],
25
+ :__u6_addr16, [:uint16, 8]
26
+ end
27
+
28
+ class In6Addr < FFI::Struct
29
+ layout :__u6_addr, U6Addr
30
+ end
31
+
32
+ class SockaddrIn6 < FFI::Struct
33
+ layout :sin6_family, :sa_family_t,
34
+ :sin6_port, :in_port_t,
35
+ :sin6_flowinfo, :uint32,
36
+ :sin6_addr, In6Addr,
37
+ :sin6_scope_id, :uint32
38
+ end
39
+
40
+ class UvBuf < FFI::Struct
41
+ layout :base, :pointer, :len, :size_t
42
+ end
43
+
44
+ class UvFSStat < FFI::Struct
45
+ layout :st_dev, :dev_t, :st_ino, :ino_t, :st_mode, :mode_t, :st_nlink, :nlink_t,
46
+ :st_uid, :uid_t, :st_gid, :gid_t, :st_rdev, :dev_t, :st_size, :off_t,
47
+ :st_blksize, :blksize_t, :st_blocks, :blkcnt_t, :st_atime, :time_t,
48
+ :st_mtime, :time_t, :st_ctime, :time_t
49
+ end
50
+
51
+ attach_function :ntohs, [:ushort], :ushort, :blocking => true
52
+
53
+ class Sockaddr < FFI::Struct
54
+ layout :sa_family, :sa_family_t,
55
+ :sa_data, [:char, 14]
56
+ end
57
+
58
+ class UvAddrinfo < FFI::Struct
59
+ layout :flags, :int,
60
+ :family, :int,
61
+ :socktype, :int,
62
+ :protocol, :int,
63
+ :addrlen, :socklen_t,
64
+ :addr, Sockaddr.by_ref,
65
+ :canonname, :string,
66
+ :next, UvAddrinfo.by_ref
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MTLibuv
4
+ module Ext
5
+ typedef :uint32_t, :in_addr_t
6
+ typedef :uint16, :in_port_t
7
+ typedef :int, :mode_t
8
+ # http://stackoverflow.com/questions/1953639/is-it-safe-to-cast-socket-to-int-under-win64
9
+ typedef :int, :uv_os_sock_t
10
+
11
+ module WS2
12
+ extend FFI::Library
13
+ ffi_lib('Ws2_32.dll').first # this is for ntohs
14
+ attach_function :ntohs, [:ushort], :ushort, :blocking => true
15
+ end
16
+
17
+ def self.ntohs(ushort)
18
+ ::MTLibuv::Ext::WS2.ntohs(ushort)
19
+ end
20
+
21
+ # win32 has a different uv_buf_t layout to everything else.
22
+ class UvBuf < FFI::Struct
23
+ layout :len, :ulong, :base, :pointer
24
+ end
25
+
26
+ # win32 uses _stati64
27
+ class UvFSStat < FFI::Struct
28
+ layout :st_gid, :gid_t, :st_atime, :time_t, :st_ctime, :time_t, :st_dev, :dev_t,
29
+ :st_ino, :ino_t, :st_mode, :mode_t, :st_mtime, :time_t, :st_nlink, :nlink_t,
30
+ :st_rdev, :dev_t, :st_size, :off_t, :st_uid, :uid_t
31
+ end
32
+
33
+
34
+
35
+ class Sockaddr < FFI::Struct
36
+ layout :sa_len, :uint8,
37
+ :sa_family, :sa_family_t,
38
+ :sa_data, [:char, 14]
39
+ end
40
+
41
+ class InAddr < FFI::Struct
42
+ layout :s_addr, :in_addr_t
43
+ end
44
+
45
+ class SockaddrIn < FFI::Struct
46
+ layout :sin_family, :sa_family_t,
47
+ :sin_port, :in_port_t,
48
+ :sin_addr, InAddr,
49
+ :sin_zero, [:char, 8]
50
+ end
51
+
52
+ class U6Addr < FFI::Union
53
+ layout :__u6_addr8, [:uint8, 16],
54
+ :__u6_addr16, [:uint16, 8]
55
+ end
56
+
57
+ class In6Addr < FFI::Struct
58
+ layout :__u6_addr, U6Addr
59
+ end
60
+
61
+ class SockaddrIn6 < FFI::Struct
62
+ layout :sin6_len, :uint8,
63
+ :sin6_family, :sa_family_t,
64
+ :sin6_port, :in_port_t,
65
+ :sin6_flowinfo, :uint32,
66
+ :sin6_addr, In6Addr,
67
+ :sin6_scope_id, :uint32
68
+ end
69
+
70
+
71
+
72
+ class UvAddrinfo < FFI::Struct
73
+ layout :flags, :int,
74
+ :family, :int,
75
+ :socktype, :int,
76
+ :protocol, :int,
77
+ :addrlen, :size_t,
78
+ :canonname, :string,
79
+ :addr, Sockaddr.by_ref,
80
+ :next, UvAddrinfo.by_ref
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ file "ext/libuv/.libs/libuv.1.#{FFI::Platform::LIBSUFFIX}" => 'ext/libuv/build' do
4
+ Dir.chdir("ext/libuv") do |path|
5
+ system "sh", "autogen.sh"
6
+ system "./configure"
7
+ system "make"
8
+ end
9
+ end
10
+
11
+ file "ext/libuv/lib/libuv.#{FFI::Platform::LIBSUFFIX}" => "ext/libuv/.libs/libuv.1.#{FFI::Platform::LIBSUFFIX}" do
12
+ FileUtils.mkdir('ext/libuv/lib') unless File.directory?('ext/libuv/lib')
13
+
14
+ user_lib = "#{ENV['HOME']}/lib"
15
+ FileUtils.mkdir(user_lib) unless File.directory?(user_lib)
16
+
17
+ # Useful for building other libraries that wish to use Libuv
18
+ FileUtils.cp("ext/libuv/.libs/libuv.1.#{FFI::Platform::LIBSUFFIX}", "ext/libuv/lib/libuv.#{FFI::Platform::LIBSUFFIX}")
19
+
20
+ # Primrary load location - falls back to above if not available
21
+ FileUtils.cp("ext/libuv/.libs/libuv.1.#{FFI::Platform::LIBSUFFIX}", "#{user_lib}/libuv.1.#{FFI::Platform::LIBSUFFIX}")
22
+ end
23
+
24
+ CLOBBER.include("ext/libuv/.libs/libuv.1.#{FFI::Platform::LIBSUFFIX}")