uvrb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/.gitignore +17 -0
  2. data/.gitmodules +3 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +13 -0
  5. data/Formula/libuv.rb +20 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +24 -0
  8. data/README.rdoc +70 -0
  9. data/Rakefile +29 -0
  10. data/examples/example +0 -0
  11. data/examples/example.c +37 -0
  12. data/examples/example.rb +29 -0
  13. data/examples/example_oop.rb +26 -0
  14. data/examples/python.py +1 -0
  15. data/examples/ruby.rb +1 -0
  16. data/examples/tcp_client_oop.rb +31 -0
  17. data/examples/tcp_example +0 -0
  18. data/examples/tcp_example.c +68 -0
  19. data/examples/tcp_example.rb +41 -0
  20. data/examples/tcp_example_oop.rb +43 -0
  21. data/examples/tcp_example_plain.rb +19 -0
  22. data/examples/tty_example.rb +20 -0
  23. data/features/async.feature +38 -0
  24. data/features/idle.feature +44 -0
  25. data/features/pipe.feature +150 -0
  26. data/features/prepare_and_check.feature +49 -0
  27. data/features/step_definitions/additional_cli_steps.rb +20 -0
  28. data/features/support/env.rb +6 -0
  29. data/lib/uv.rb +248 -0
  30. data/lib/uv/assertions.rb +24 -0
  31. data/lib/uv/async.rb +24 -0
  32. data/lib/uv/check.rb +27 -0
  33. data/lib/uv/error.rb +58 -0
  34. data/lib/uv/file.rb +221 -0
  35. data/lib/uv/file/stat.rb +35 -0
  36. data/lib/uv/filesystem.rb +335 -0
  37. data/lib/uv/fs_event.rb +21 -0
  38. data/lib/uv/handle.rb +65 -0
  39. data/lib/uv/idle.rb +27 -0
  40. data/lib/uv/listener.rb +26 -0
  41. data/lib/uv/loop.rb +326 -0
  42. data/lib/uv/net.rb +31 -0
  43. data/lib/uv/pipe.rb +47 -0
  44. data/lib/uv/prepare.rb +27 -0
  45. data/lib/uv/resource.rb +20 -0
  46. data/lib/uv/stream.rb +105 -0
  47. data/lib/uv/tasks.rb +27 -0
  48. data/lib/uv/tasks/mac.rb +23 -0
  49. data/lib/uv/tasks/unix.rb +23 -0
  50. data/lib/uv/tasks/win.rb +2 -0
  51. data/lib/uv/tcp.rb +162 -0
  52. data/lib/uv/timer.rb +48 -0
  53. data/lib/uv/tty.rb +30 -0
  54. data/lib/uv/types.rb +249 -0
  55. data/lib/uv/types/darwin_x64.rb +10 -0
  56. data/lib/uv/types/linux.rb +6 -0
  57. data/lib/uv/types/unix.rb +12 -0
  58. data/lib/uv/types/windows.rb +13 -0
  59. data/lib/uv/udp.rb +215 -0
  60. data/lib/uv/version.rb +3 -0
  61. data/lib/uvrb.rb +1 -0
  62. data/spec/shared_examples/handle.rb +54 -0
  63. data/spec/shared_examples/stream.rb +109 -0
  64. data/spec/spec_helper.rb +26 -0
  65. data/spec/uv/async_spec.rb +18 -0
  66. data/spec/uv/check_spec.rb +30 -0
  67. data/spec/uv/file_spec.rb +177 -0
  68. data/spec/uv/filesystem_spec.rb +246 -0
  69. data/spec/uv/fs_event_spec.rb +10 -0
  70. data/spec/uv/idle_spec.rb +30 -0
  71. data/spec/uv/loop_spec.rb +241 -0
  72. data/spec/uv/pipe_spec.rb +54 -0
  73. data/spec/uv/prepare_spec.rb +30 -0
  74. data/spec/uv/tcp_spec.rb +134 -0
  75. data/spec/uv/timer_spec.rb +61 -0
  76. data/spec/uv/tty_spec.rb +53 -0
  77. data/spec/uv/udp_spec.rb +190 -0
  78. data/uvrb.gemspec +28 -0
  79. metadata +247 -0
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'uvrb'
4
+
5
+ loop = UV::Loop.default
6
+
7
+ server = loop.tcp
8
+
9
+ server.bind("0.0.0.0", 10000)
10
+
11
+ server.listen(128) do |err|
12
+ if err
13
+ p err
14
+ end
15
+ client = server.accept
16
+
17
+ client.start_read do |err, data|
18
+ puts data
19
+ if err
20
+ p err
21
+ client.close {}
22
+ end
23
+ client.stop_read
24
+ client.write("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 12\r\n\r\nhello world\n") do |err|
25
+ if err
26
+ p err
27
+ end
28
+ client.close {}
29
+ end
30
+ end
31
+ end
32
+
33
+ stoper = loop.timer
34
+ stoper.start(50000, 0) do |e|
35
+ puts "50 seconds passed"
36
+ server.close {}
37
+ stoper.close {}
38
+ if e
39
+ raise e
40
+ end
41
+ end
42
+
43
+ loop.run
@@ -0,0 +1,19 @@
1
+ require 'socket'
2
+ require 'thread'
3
+ require 'timeout'
4
+
5
+ server = TCPServer.new(10000)
6
+ server.listen(128)
7
+
8
+ Timeout.timeout(50) do
9
+ while(client = server.accept)
10
+ client.puts "HTTP/1.1 200 OK\r\n"
11
+ client.puts "Content-Type: text/plain\r\n"
12
+ client.puts "Content-Length: 12\r\n"
13
+ client.puts "\r\n"
14
+ client.puts "hello world\n"
15
+ client.close
16
+ client = nil
17
+ end
18
+ end
19
+
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'uvrb'
4
+
5
+ loop = UV::Loop.default
6
+
7
+ stdin = loop.tty($stdin.fileno, true)
8
+ stdin.enable_raw_mode
9
+ stdin.start_read do |data|
10
+ $stdout << data
11
+ end
12
+
13
+ stoper = loop.timer
14
+ stoper.start(25000, 0) do
15
+ puts "25 seconds passed"
16
+ stdin.close
17
+ stoper.close
18
+ end
19
+
20
+ loop.run
@@ -0,0 +1,38 @@
1
+ Feature: wake up another event loop
2
+
3
+ UV::Loop cannot be shared by multiple threads. To wake up a control loop in a different
4
+ thread, use UV::Loop#async, which is thread safe
5
+
6
+ Scenario: wake up an event loop from a different thread
7
+ Given a file named "async_example.rb" with:
8
+ """
9
+ require 'uvrb'
10
+
11
+ count = 0
12
+ loop = UV::Loop.default
13
+
14
+ timer = loop.timer
15
+ timer.start(0, 100) do |e|
16
+ count += 1
17
+ sleep(0.2)
18
+ end
19
+
20
+ callback = loop.async do |e|
21
+ stopper = loop.timer
22
+ stopper.start(1000, 0) do |e|
23
+ timer.close {}
24
+ callback.close {}
25
+ stopper.close {}
26
+ end
27
+ end
28
+
29
+ Thread.new(callback) do |proc|
30
+ proc.call
31
+ end
32
+
33
+ loop.run
34
+
35
+ abort "failure, count is #{count}" if count >= 11
36
+ """
37
+ When I run `ruby async_example.rb`
38
+ Then the exit status should be 0
@@ -0,0 +1,44 @@
1
+ Feature: triggering callbacks while nothing else is happening
2
+
3
+ Idle watchers trigger events when no other events of the same or higher priority are
4
+ pending (prepare, check and other idle watchers do not count).
5
+
6
+ That is, as long as your process is busy handling sockets or timeouts (or even signals,
7
+ imagine) of the same or higher priority it will not be triggered. But when your process
8
+ is idle (or only lower-priority watchers are pending), the idle watchers are being
9
+ called once per event loop iteration - until stopped, that is, or your process receives
10
+ more events and becomes busy again with higher priority stuff.
11
+
12
+ Scenario: when you've got nothing better to do...
13
+ Given a file named "idle_example.rb" with:
14
+ """
15
+ require 'uvrb'
16
+
17
+ idle_calls = 0
18
+ loop = UV::Loop.default
19
+
20
+ idle = loop.idle
21
+ idle.start do |e|
22
+ raise e if e
23
+ idle_calls += 1
24
+ end
25
+
26
+ timer = loop.timer
27
+ timer.start(1, 0) do |e|
28
+ raise e if e
29
+ end
30
+
31
+ stopper = loop.timer
32
+ stopper.start(10, 0) do |e|
33
+ raise e if e
34
+ idle.close {}
35
+ timer.close {}
36
+ stopper.close {}
37
+ end
38
+
39
+ loop.run
40
+
41
+ abort "idle not called #{idle_calls}" unless idle_calls > 0
42
+ """
43
+ When I run `ruby idle_example.rb`
44
+ Then the exit status should be 0
@@ -0,0 +1,150 @@
1
+ Feature: Named pipes
2
+
3
+ Unix domain sockets and named pipes are useful for inter-process communication.
4
+
5
+ Scenario: bidirectional inter process communication
6
+ Given a file named "ipc_server_example.rb" with:
7
+ """
8
+ require 'uvrb'
9
+
10
+ pong = "pong"
11
+ loop = UV::Loop.default
12
+
13
+ server = loop.pipe
14
+
15
+ server.bind("/tmp/ipc-example.ipc")
16
+ server.listen(128) do |e|
17
+ raise e if e
18
+
19
+ client = server.accept
20
+
21
+ client.start_read do |e, data|
22
+ raise e if e
23
+
24
+ client.write(pong) do |e|
25
+ raise e if e
26
+
27
+ client.close {}
28
+ server.close {}
29
+ end
30
+ end
31
+ end
32
+
33
+ stopper = loop.timer
34
+
35
+ stopper.start(2800, 0) do |e|
36
+ raise e if e
37
+
38
+ server.close {}
39
+ stopper.close {}
40
+ end
41
+
42
+ begin
43
+ loop.run
44
+ end
45
+ """
46
+ And a file named "ipc_client_example.rb" with:
47
+ """
48
+ require 'uvrb'
49
+
50
+ ping = "ping"
51
+ loop = UV::Loop.default
52
+
53
+ client = loop.pipe
54
+
55
+ client.connect("/tmp/ipc-example.ipc") do |e|
56
+ raise e if e
57
+
58
+ client.start_read do |e, pong|
59
+ raise e if e
60
+
61
+ puts "received #{pong} from server"
62
+
63
+ client.close {}
64
+ end
65
+
66
+ client.write(ping) do |e|
67
+ raise e if e
68
+
69
+ puts "sent #{ping} to server"
70
+ end
71
+ end
72
+
73
+ begin
74
+ loop.run
75
+ rescue UV::Error::EOF, UV::Error::EBADF => e
76
+ exit 0
77
+ end
78
+ """
79
+ When I run `ruby ipc_server_example.rb` interactively
80
+ And I run `ruby ipc_client_example.rb`
81
+ Then the output should contain ping pong exchange
82
+
83
+ Scenario: unidirectional pipeline
84
+ Given a named pipe "/tmp/exchange-pipe.pipe"
85
+ And a file named "pipe_producer_example.rb" with:
86
+ """
87
+ require 'uvrb'
88
+
89
+ loop = UV::Loop.default
90
+
91
+ pipe = File.open("/tmp/exchange-pipe.pipe", File::RDWR|File::NONBLOCK)
92
+ producer = loop.pipe
93
+
94
+ producer.open(pipe.fileno)
95
+
96
+ heartbeat = loop.timer
97
+
98
+ heartbeat.start(0, 200) do |e|
99
+ raise e if e
100
+
101
+ producer.write("workload") { |e| raise e if e }
102
+ end
103
+
104
+ stopper = loop.timer
105
+
106
+ stopper.start(2800, 0) do |e|
107
+ raise e if e
108
+
109
+ heartbeat.close {}
110
+ producer.close {}
111
+ stopper.close {}
112
+ end
113
+
114
+ begin
115
+ loop.run
116
+ end
117
+ """
118
+ And a file named "pipe_consumer_example.rb" with:
119
+ """
120
+ require 'uvrb'
121
+
122
+ loop = UV::Loop.default
123
+
124
+ pipe = File.open("/tmp/exchange-pipe.pipe", File::RDWR|File::NONBLOCK)
125
+ consumer = loop.pipe
126
+
127
+ consumer.open(pipe.fileno)
128
+
129
+ consumer.start_read do |e, workload|
130
+ raise e if e
131
+
132
+ puts "received #{workload}"
133
+ end
134
+
135
+ stopper = loop.timer
136
+
137
+ stopper.start(2000, 0) do |e|
138
+ raise e if e
139
+
140
+ consumer.close {}
141
+ stopper.close {}
142
+ end
143
+
144
+ begin
145
+ loop.run
146
+ end
147
+ """
148
+ When I run `ruby pipe_producer_example.rb` interactively
149
+ And I run `ruby pipe_consumer_example.rb`
150
+ Then the output should contain consumed workload
@@ -0,0 +1,49 @@
1
+ Feature: customise your event loop
2
+
3
+ Prepare and check watchers are usually (but not always) used in tandem: prepare watchers
4
+ get invoked before the process blocks and check watchers afterwards.
5
+
6
+ Scenario: prepare loop
7
+ Given a file named "prepare_check_example.rb" with:
8
+ """
9
+ require 'uvrb'
10
+
11
+ loop = UV::Loop.default
12
+
13
+ prepared = false
14
+ checked = false
15
+
16
+ prepare = loop.prepare
17
+ prepare.start do |e|
18
+ puts "preparing"
19
+ abort e.inspect if e
20
+ prepared = true
21
+ end
22
+
23
+ check = loop.check
24
+ check.start do |e|
25
+ puts "checking"
26
+ abort e.inspect if e
27
+ abort "not prepared" unless prepared
28
+ checked = true
29
+ end
30
+
31
+ timer = loop.timer
32
+ timer.start(0, 200) do |e|
33
+ puts "running cycles"
34
+ end
35
+
36
+ stopper = loop.timer
37
+ stopper.start(2000, 0) do |e|
38
+ timer.close {}
39
+ prepare.close {}
40
+ check.close {}
41
+ stopper.close {}
42
+ end
43
+
44
+ loop.run
45
+
46
+ abort "not checked" unless checked
47
+ """
48
+ When I run `ruby prepare_check_example.rb`
49
+ Then the exit status should be 0
@@ -0,0 +1,20 @@
1
+ Then /^the output should contain ping pong exchange$/ do
2
+ step %q{the exit status should be 0}
3
+ step %q{the output should contain "sent ping to server"}
4
+ step %q{the output should contain "received pong from server"}
5
+ end
6
+
7
+ Then /^the output should contain consumed workload$/ do
8
+ step %q{the exit status should be 0}
9
+ step %q{the output should contain "received workload"}
10
+ end
11
+
12
+ Given /^a named pipe "(.*?)"$/ do |path|
13
+ if RUBY_PLATFORM.downcase.include?("mswin")
14
+ f = File.open(path, 'w+')
15
+ f.close
16
+ else
17
+ system "/usr/bin/mkfifo", path
18
+ end
19
+ at_exit { File.unlink(path) }
20
+ end
@@ -0,0 +1,6 @@
1
+ require 'aruba/cucumber'
2
+ require 'rspec/expectations'
3
+
4
+ Before do
5
+ @aruba_timeout_seconds = 5
6
+ end
data/lib/uv.rb ADDED
@@ -0,0 +1,248 @@
1
+ require 'ffi'
2
+
3
+ module UV
4
+ extend FFI::Library
5
+ FFI::DEBUG = 10
6
+ ffi_lib(FFI::Library::LIBC).first
7
+ begin
8
+ # bias the library discovery to a path inside the gem first, then
9
+ # to the usual system paths
10
+ path_to_internal_libuv = File.dirname(__FILE__) + '/../ext'
11
+ LIBUV_PATHS = [
12
+ path_to_internal_libuv, '/usr/local/lib', '/opt/local/lib', '/usr/lib64'
13
+ ].map{|path| "#{path}/libuv.#{FFI::Platform::LIBSUFFIX}"}
14
+ libuv = ffi_lib(LIBUV_PATHS + %w{libuv}).first
15
+ rescue LoadError
16
+ warn <<-WARNING
17
+ Unable to load this gem. The libuv library (or DLL) could not be found.
18
+ If this is a Windows platform, make sure libuv.dll is on the PATH.
19
+ For non-Windows platforms, make sure libuv is located in this search path:
20
+ #{LIBUV_PATHS.inspect}
21
+ WARNING
22
+ exit 255
23
+ end
24
+
25
+ require 'uv/types'
26
+
27
+ attach_function :loop_new, :uv_loop_new, [], :uv_loop_t
28
+ attach_function :loop_delete, :uv_loop_delete, [:uv_loop_t], :void
29
+ attach_function :default_loop, :uv_default_loop, [], :uv_loop_t
30
+ @blocking = true
31
+ attach_function :run, :uv_run, [:uv_loop_t], :int
32
+ attach_function :run_once, :uv_run_once, [:uv_loop_t], :int
33
+ attach_function :update_time, :uv_update_time, [:uv_loop_t], :void
34
+ attach_function :now, :uv_now, [:uv_loop_t], :int64
35
+
36
+ attach_function :last_error, :uv_last_error, [:uv_loop_t], :uv_err_t
37
+ attach_function :strerror, :uv_strerror, [:uv_err_t], :string
38
+ attach_function :err_name, :uv_err_name, [:uv_err_t], :string
39
+
40
+ attach_function :ref, :uv_ref, [:uv_handle_t], :void
41
+ attach_function :unref, :uv_unref, [:uv_handle_t], :void
42
+ attach_function :is_active, :uv_is_active, [:uv_handle_t], :int
43
+ attach_function :close, :uv_close, [:uv_handle_t, :uv_close_cb], :void
44
+ attach_function :is_closing, :uv_is_closing, [:uv_handle_t], :int
45
+
46
+ attach_function :buf_init, :uv_buf_init, [:pointer, :size_t], :uv_buf_t
47
+ attach_function :strlcpy, :uv_strlcpy, [:string, :string, :size_t], :size_t
48
+ attach_function :strlcat, :uv_strlcat, [:string, :string, :size_t], :size_t
49
+
50
+ attach_function :listen, :uv_listen, [:uv_stream_t, :int, :uv_connection_cb], :int
51
+ attach_function :accept, :uv_accept, [:uv_stream_t, :uv_stream_t], :int
52
+ attach_function :read_start, :uv_read_start, [:uv_stream_t, :uv_alloc_cb, :uv_read_cb], :int
53
+ attach_function :read_stop, :uv_read_stop, [:uv_stream_t], :int
54
+ attach_function :read2_start, :uv_read2_start, [:uv_stream_t, :uv_alloc_cb, :uv_read2_cb], :int
55
+ attach_function :write, :uv_write, [:uv_write_t, :uv_stream_t, :pointer, :int, :uv_write_cb], :int
56
+ attach_function :write2, :uv_write2, [:uv_write_t, :uv_stream_t, :pointer, :int, :uv_stream_t, :uv_write_cb], :int
57
+ attach_function :is_readable, :uv_is_readable, [:uv_stream_t], :int
58
+ attach_function :is_writable, :uv_is_writable, [:uv_stream_t], :int
59
+ attach_function :shutdown, :uv_shutdown, [:uv_shutdown_t, :uv_stream_t, :uv_shutdown_cb], :int
60
+
61
+ attach_function :tcp_init, :uv_tcp_init, [:uv_loop_t, :uv_tcp_t], :int
62
+ attach_function :tcp_nodelay, :uv_tcp_nodelay, [:uv_tcp_t, :int], :int
63
+ attach_function :tcp_keepalive, :uv_tcp_keepalive, [:uv_tcp_t, :int, :uint], :int
64
+ attach_function :tcp_simultaneous_accepts, :uv_tcp_simultaneous_accepts, [:uv_tcp_t, :int], :int
65
+ attach_function :tcp_bind, :uv_tcp_bind, [:uv_tcp_t, :sockaddr_in], :int
66
+ attach_function :tcp_bind6, :uv_tcp_bind6, [:uv_tcp_t, :sockaddr_in6], :int
67
+ attach_function :tcp_getsockname, :uv_tcp_getsockname, [:uv_tcp_t, :pointer, :pointer], :int
68
+ attach_function :tcp_getpeername, :uv_tcp_getpeername, [:uv_tcp_t, :pointer, :pointer], :int
69
+ attach_function :tcp_connect, :uv_tcp_connect, [:uv_connect_t, :uv_tcp_t, :sockaddr_in, :uv_connect_cb], :int
70
+ attach_function :tcp_connect6, :uv_tcp_connect6, [:uv_connect_t, :uv_tcp_t, :sockaddr_in6, :uv_connect_cb], :int
71
+
72
+ attach_function :udp_init, :uv_udp_init, [:uv_loop_t, :uv_udp_t], :int
73
+ attach_function :udp_bind, :uv_udp_bind, [:uv_udp_t, :sockaddr_in, :uint], :int
74
+ attach_function :udp_bind6, :uv_udp_bind6, [:uv_udp_t, :sockaddr_in6, :uint], :int
75
+ attach_function :udp_getsockname, :uv_udp_getsockname, [:uv_udp_t, :pointer, :pointer], :int
76
+ attach_function :udp_set_membership, :uv_udp_set_membership, [:uv_udp_t, :string, :string, :uv_membership], :int
77
+ attach_function :udp_set_multicast_loop, :uv_udp_set_multicast_loop, [:uv_udp_t, :int], :int
78
+ attach_function :udp_set_multicast_ttl, :uv_udp_set_multicast_ttl, [:uv_udp_t, :int], :int
79
+ attach_function :udp_set_broadcast, :uv_udp_set_broadcast, [:uv_udp_t, :int], :int
80
+ attach_function :udp_set_ttl, :uv_udp_set_ttl, [:uv_udp_t, :int], :int
81
+ attach_function :udp_send, :uv_udp_send, [:uv_udp_send_t, :uv_udp_t, :pointer, :int, :sockaddr_in, :uv_udp_send_cb], :int
82
+ attach_function :udp_send6, :uv_udp_send6, [:uv_udp_send_t, :uv_udp_t, :pointer, :int, :sockaddr_in6, :uv_udp_send_cb], :int
83
+ attach_function :udp_recv_start, :uv_udp_recv_start, [:uv_udp_t, :uv_alloc_cb, :uv_udp_recv_cb], :int
84
+ attach_function :udp_recv_stop, :uv_udp_recv_stop, [:uv_udp_t], :int
85
+
86
+ attach_function :tty_init, :uv_tty_init, [:uv_loop_t, :uv_tty_t, :uv_file, :int], :int
87
+ attach_function :tty_set_mode, :uv_tty_set_mode, [:uv_tty_t, :int], :int
88
+ attach_function :tty_reset_mode, :uv_tty_reset_mode, [], :void
89
+ attach_function :tty_get_winsize, :uv_tty_get_winsize, [:uv_tty_t, :pointer, :pointer], :int
90
+
91
+ attach_function :guess_handle, :uv_guess_handle, [:uv_file], :uv_handle_type
92
+
93
+ attach_function :pipe_init, :uv_pipe_init, [:uv_loop_t, :uv_pipe_t, :int], :int
94
+ attach_function :pipe_open, :uv_pipe_open, [:uv_pipe_t, :uv_file], :void
95
+ attach_function :pipe_bind, :uv_pipe_bind, [:uv_pipe_t, :string], :int
96
+ attach_function :pipe_connect, :uv_pipe_connect, [:uv_connect_t, :uv_pipe_t, :string, :uv_connect_cb], :void
97
+ attach_function :pipe_pending_instances, :uv_pipe_pending_instances, [:uv_pipe_t, :int], :void
98
+
99
+ attach_function :prepare_init, :uv_prepare_init, [:uv_loop_t, :uv_prepare_t], :int
100
+ attach_function :prepare_start, :uv_prepare_start, [:uv_prepare_t, :uv_prepare_cb], :int
101
+ attach_function :prepare_stop, :uv_prepare_stop, [:uv_prepare_t], :int
102
+
103
+ attach_function :check_init, :uv_check_init, [:uv_loop_t, :uv_check_t], :int
104
+ attach_function :check_start, :uv_check_start, [:uv_check_t, :uv_check_cb], :int
105
+ attach_function :check_stop, :uv_check_stop, [:uv_check_t], :int
106
+
107
+ attach_function :idle_init, :uv_idle_init, [:uv_loop_t, :uv_idle_t], :int
108
+ attach_function :idle_start, :uv_idle_start, [:uv_idle_t, :uv_idle_cb], :int
109
+ attach_function :idle_stop, :uv_idle_stop, [:uv_idle_t], :int
110
+
111
+ attach_function :async_init, :uv_async_init, [:uv_loop_t, :uv_async_t, :uv_async_cb], :int
112
+ attach_function :async_send, :uv_async_send, [:uv_async_t], :int
113
+
114
+ attach_function :timer_init, :uv_timer_init, [:uv_loop_t, :uv_timer_t], :int
115
+ attach_function :timer_start, :uv_timer_start, [:uv_timer_t, :uv_timer_cb, :int64_t, :int64_t], :int
116
+ attach_function :timer_stop, :uv_timer_stop, [:uv_timer_t], :int
117
+ attach_function :timer_again, :uv_timer_again, [:uv_timer_t], :int
118
+ attach_function :timer_set_repeat, :uv_timer_set_repeat, [:uv_timer_t, :int64_t], :void
119
+ attach_function :timer_get_repeat, :uv_timer_get_repeat, [:uv_timer_t], :int64_t
120
+
121
+ attach_function :ares_init_options, :uv_ares_init_options, [:uv_loop_t, :ares_channel, :ares_options, :int], :int
122
+ attach_function :ares_destroy, :uv_ares_destroy, [:uv_loop_t, :ares_channel], :void
123
+
124
+ attach_function :getaddrinfo, :uv_getaddrinfo, [:uv_loop_t, :uv_getaddrinfo_t, :uv_getaddrinfo_cb, :string, :string, :addrinfo], :int
125
+ attach_function :freeaddrinfo, :uv_freeaddrinfo, [:addrinfo], :void
126
+
127
+ attach_function :spawn, :uv_spawn, [:uv_loop_t, :uv_process_t, :uv_options_t], :int
128
+ attach_function :process_kill, :uv_process_kill, [:uv_process_t, :int], :int
129
+ attach_function :kill, :uv_kill, [:int, :int], :uv_err_t
130
+ attach_function :queue_work, :uv_queue_work, [:uv_loop_t, :uv_work_t, :uv_work_cb, :uv_after_work_cb], :int
131
+ attach_function :setup_args, :uv_setup_args, [:int, :varargs], :varargs
132
+ attach_function :get_process_title, :uv_get_process_title, [:pointer, :size_t], :uv_err_t
133
+ attach_function :set_process_title, :uv_set_process_title, [:string], :uv_err_t
134
+ attach_function :resident_set_memory, :uv_resident_set_memory, [:size_t], :uv_err_t
135
+
136
+ attach_function :uptime, :uv_uptime, [:pointer], :uv_err_t
137
+ attach_function :cpu_info, :uv_cpu_info, [:uv_cpu_info_t, :pointer], :uv_err_t
138
+ attach_function :loadavg, :uv_loadavg, [:pointer], :void
139
+ attach_function :free_cpu_info, :uv_free_cpu_info, [:uv_cpu_info_t, :int], :void
140
+ attach_function :interface_addresses, :uv_interface_addresses, [:uv_interface_address_t, :pointer], :uv_err_t
141
+ attach_function :free_interface_addresses, :uv_free_interface_addresses, [:uv_interface_address_t, :int], :void
142
+
143
+ attach_function :fs_req_result, :uv_fs_req_result, [:uv_fs_t], :ssize_t
144
+ attach_function :fs_req_stat, :uv_fs_req_stat, [:uv_fs_t], :uv_fs_stat_t
145
+ attach_function :fs_req_pointer, :uv_fs_req_pointer, [:uv_fs_t], :pointer
146
+
147
+ attach_function :fs_req_cleanup, :uv_fs_req_cleanup, [:uv_fs_t], :void
148
+ attach_function :fs_close, :uv_fs_close, [:uv_loop_t, :uv_fs_t, :uv_file, :uv_fs_cb], :int
149
+ attach_function :fs_open, :uv_fs_open, [:uv_loop_t, :uv_fs_t, :string, :int, :int, :uv_fs_cb], :int
150
+ attach_function :fs_read, :uv_fs_read, [:uv_loop_t, :uv_fs_t, :uv_file, :string, :size_t, :off_t, :uv_fs_cb], :int
151
+ attach_function :fs_unlink, :uv_fs_unlink, [:uv_loop_t, :uv_fs_t, :string, :uv_fs_cb], :int
152
+ attach_function :fs_write, :uv_fs_write, [:uv_loop_t, :uv_fs_t, :uv_file, :string, :size_t, :off_t, :uv_fs_cb], :int
153
+ attach_function :fs_mkdir, :uv_fs_mkdir, [:uv_loop_t, :uv_fs_t, :string, :int, :uv_fs_cb], :int
154
+ attach_function :fs_rmdir, :uv_fs_rmdir, [:uv_loop_t, :uv_fs_t, :string, :uv_fs_cb], :int
155
+ attach_function :fs_readdir, :uv_fs_readdir, [:uv_loop_t, :uv_fs_t, :string, :int, :uv_fs_cb], :int
156
+ attach_function :fs_stat, :uv_fs_stat, [:uv_loop_t, :uv_fs_t, :string, :uv_fs_cb], :int
157
+ attach_function :fs_fstat, :uv_fs_fstat, [:uv_loop_t, :uv_fs_t, :uv_file, :uv_fs_cb], :int
158
+ attach_function :fs_rename, :uv_fs_rename, [:uv_loop_t, :uv_fs_t, :string, :string, :uv_fs_cb], :int
159
+ attach_function :fs_fsync, :uv_fs_fsync, [:uv_loop_t, :uv_fs_t, :uv_file, :uv_fs_cb], :int
160
+ attach_function :fs_fdatasync, :uv_fs_fdatasync, [:uv_loop_t, :uv_fs_t, :uv_file, :uv_fs_cb], :int
161
+ attach_function :fs_ftruncate, :uv_fs_ftruncate, [:uv_loop_t, :uv_fs_t, :uv_file, :off_t, :uv_fs_cb], :int
162
+ 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
163
+ attach_function :fs_chmod, :uv_fs_chmod, [:uv_loop_t, :uv_fs_t, :string, :int, :uv_fs_cb], :int
164
+ attach_function :fs_utime, :uv_fs_utime, [:uv_loop_t, :uv_fs_t, :string, :double, :double, :uv_fs_cb], :int
165
+ attach_function :fs_futime, :uv_fs_futime, [:uv_loop_t, :uv_fs_t, :uv_file, :double, :double, :uv_fs_cb], :int
166
+ attach_function :fs_lstat, :uv_fs_lstat, [:uv_loop_t, :uv_fs_t, :string, :uv_fs_cb], :int
167
+ attach_function :fs_link, :uv_fs_link, [:uv_loop_t, :uv_fs_t, :string, :string, :uv_fs_cb], :int
168
+ attach_function :fs_symlink, :uv_fs_symlink, [:uv_loop_t, :uv_fs_t, :string, :string, :int, :uv_fs_cb], :int
169
+ attach_function :fs_readlink, :uv_fs_readlink, [:uv_loop_t, :uv_fs_t, :string, :uv_fs_cb], :int
170
+ attach_function :fs_fchmod, :uv_fs_fchmod, [:uv_loop_t, :uv_fs_t, :uv_file, :int, :uv_fs_cb], :int
171
+ attach_function :fs_chown, :uv_fs_chown, [:uv_loop_t, :uv_fs_t, :string, :int, :int, :uv_fs_cb], :int
172
+ attach_function :fs_fchown, :uv_fs_fchown, [:uv_loop_t, :uv_fs_t, :uv_file, :int, :int, :uv_fs_cb], :int
173
+
174
+ attach_function :fs_event_init, :uv_fs_event_init, [:uv_loop_t, :uv_fs_event_t, :string, :uv_fs_event_cb, :int], :int
175
+
176
+ attach_function :ip4_addr, :uv_ip4_addr, [:string, :int], :sockaddr_in
177
+ attach_function :ip6_addr, :uv_ip6_addr, [:string, :int], :sockaddr_in6
178
+ attach_function :ip4_name, :uv_ip4_name, [SockaddrIn.by_ref, :pointer, :size_t], :int
179
+ attach_function :ip6_name, :uv_ip6_name, [SockaddrIn6.by_ref, :pointer, :size_t], :int
180
+
181
+ attach_function :exepath, :uv_exepath, [:pointer, :size_t], :int
182
+ attach_function :cwd, :uv_cwd, [:pointer, :size_t], :uv_err_t
183
+ attach_function :chdir, :uv_chdir, [:string], :uv_err_t
184
+ attach_function :get_free_memory, :uv_get_free_memory, [], :uint64
185
+ attach_function :get_total_memory, :uv_get_total_memory, [], :uint64
186
+ attach_function :hrtime, :uv_hrtime, [], :uint64
187
+ attach_function :dlopen, :uv_dlopen, [:string, :uv_lib_t], :uv_err_t
188
+ attach_function :dlclose, :uv_dlclose, [:uv_lib_t], :uv_err_t
189
+ # attach_function :dlsym, :uv_dlsym, [:uv_lib_t], :ev_err_t
190
+ # attach_function :dlerror, :uv_dlerror, [:uv_lib_t], :string
191
+ # attach_function :dlerror_free, :uv_dlerror_free, [:uv_lib_t, :string], :void
192
+
193
+ attach_function :mutex_init, :uv_mutex_init, [:uv_mutex_t], :int
194
+ attach_function :mutex_destroy, :uv_mutex_destroy, [:uv_mutex_t], :void
195
+ attach_function :mutex_lock, :uv_mutex_lock, [:uv_mutex_t], :void
196
+ attach_function :mutex_trylock, :uv_mutex_trylock, [:uv_mutex_t], :int
197
+ attach_function :mutex_unlock, :uv_mutex_unlock, [:uv_mutex_t], :void
198
+
199
+ attach_function :rwlock_init, :uv_rwlock_init, [:uv_rwlock_t], :int
200
+ attach_function :rwlock_destroy, :uv_rwlock_destroy, [:uv_rwlock_t], :void
201
+ attach_function :rwlock_rdlock, :uv_rwlock_rdlock, [:uv_rwlock_t], :void
202
+ attach_function :rwlock_tryrdlock, :uv_rwlock_tryrdlock, [:uv_rwlock_t], :int
203
+ attach_function :rwlock_rdunlock, :uv_rwlock_rdunlock, [:uv_rwlock_t], :void
204
+ attach_function :rwlock_wrlock, :uv_rwlock_wrlock, [:uv_rwlock_t], :void
205
+ attach_function :rwlock_trywrlock, :uv_rwlock_trywrlock, [:uv_rwlock_t], :int
206
+ attach_function :rwlock_wrunlock, :uv_rwlock_wrunlock, [:uv_rwlock_t], :void
207
+
208
+ attach_function :once, :uv_once, [:uv_once_t, :uv_cb], :void
209
+ attach_function :thread_create, :uv_thread_create, [:uv_thread_t, :uv_cb], :int
210
+ attach_function :thread_join, :uv_thread_join, [:uv_thread_t], :int
211
+
212
+ # memory management
213
+ attach_function :malloc, [:size_t], :pointer
214
+ attach_function :free, [:pointer], :void
215
+ attach_function :ntohs, [:ushort], :ushort
216
+
217
+ attach_function :handle_size, :uv_handle_size, [:uv_handle_type], :size_t
218
+ attach_function :req_size, :uv_req_size, [:uv_req_type], :size_t
219
+
220
+ def self.create_handle(type)
221
+ UV.malloc(UV.handle_size(type))
222
+ end
223
+
224
+ def self.create_request(type)
225
+ UV.malloc(UV.req_size(type))
226
+ end
227
+
228
+ autoload :Resource, 'uv/resource'
229
+ autoload :Listener, 'uv/listener'
230
+ autoload :Net, 'uv/net'
231
+ autoload :Handle, 'uv/handle'
232
+ autoload :Stream, 'uv/stream'
233
+ autoload :Loop, 'uv/loop'
234
+ autoload :Error, 'uv/error'
235
+ autoload :Timer, 'uv/timer'
236
+ autoload :TCP, 'uv/tcp'
237
+ autoload :UDP, 'uv/udp'
238
+ autoload :TTY, 'uv/tty'
239
+ autoload :Pipe, 'uv/pipe'
240
+ autoload :Prepare, 'uv/prepare'
241
+ autoload :Check, 'uv/check'
242
+ autoload :Idle, 'uv/idle'
243
+ autoload :Async, 'uv/async'
244
+ autoload :Filesystem, 'uv/filesystem'
245
+ autoload :File, 'uv/file'
246
+ autoload :FSEvent, 'uv/fs_event'
247
+ autoload :Assertions, 'uv/assertions'
248
+ end