Class: UV::Loop
- Inherits:
-
Object
- Object
- UV::Loop
- Extended by:
- ClassMethods
- Includes:
- Assertions, Resource
- Defined in:
- lib/uv/loop.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#async(&block) ⇒ Object
Public: Get a new Async handle.
-
#check ⇒ Object
Public: Get a new Check handle.
-
#fs ⇒ Object
Public: Get a new Filesystem instance.
-
#fs_event(path, &block) ⇒ Object
Public: Get a new FSEvent instance.
-
#idle ⇒ Object
Public: Get a new Idle handle.
-
#initialize(pointer) ⇒ Loop
constructor
Internal: Initialize a loop using an FFI::Pointer.
-
#lookup_error(err) ⇒ Object
Internal: Get last error from the loop.
-
#now ⇒ Object
Public: Get current time in microseconds.
-
#pipe(ipc = false) ⇒ Object
Public: Get a new Pipe instance.
-
#prepare ⇒ Object
Public: Get a new Prepare handle.
-
#run(run_type = :UV_RUN_DEFAULT) ⇒ Object
Public: Run the actual event loop.
-
#run_once ⇒ Object
Public: (Deprecated - use loop.run with a run_type specified) Runs outstanding events once, yields control back.
-
#signal ⇒ Object
Public: Get a new Signal handle.
- #stop ⇒ Object
-
#tcp ⇒ Object
Public: Get a new TCP instance.
-
#timer ⇒ Object
Public: Get a new timer instance.
-
#to_ptr ⇒ Object
Internal: Get a hold of internal loop pointer instance.
-
#tty(fileno, readable = false) ⇒ Object
Public: Get a new TTY instance.
-
#udp ⇒ Object
Public: Get a new UDP instance.
-
#update_time ⇒ Object
Public: forces loop time update, useful for getting more granular times.
-
#work(callback = nil, op = nil, &block) ⇒ Object
Public: Do some work in the libuv thread pool.
Methods included from ClassMethods
Methods included from Resource
Methods included from Assertions
#assert_arity, #assert_block, #assert_boolean, #assert_signal, #assert_type
Constructor Details
#initialize(pointer) ⇒ Loop
Internal: Initialize a loop using an FFI::Pointer
Returns nothing
35 36 37 38 |
# File 'lib/uv/loop.rb', line 35 def initialize(pointer) # :notnew: @pointer = pointer @loop = self end |
Instance Method Details
#async(&block) ⇒ Object
Public: Get a new Async handle
Returns UV::Async
Raises ArgumentError if block is not given and is not expecting one argument exactly
237 238 239 240 241 242 243 244 245 246 |
# File 'lib/uv/loop.rb', line 237 def async(&block) assert_block(block) assert_arity(1, block) async_ptr = UV.create_handle(:uv_async) async = Async.new(self, async_ptr, &block) check_result! UV.async_init(@pointer, async_ptr, async.callback(:on_async)) async end |
#check ⇒ Object
Public: Get a new Check handle
Returns UV::Check
215 216 217 218 219 220 |
# File 'lib/uv/loop.rb', line 215 def check check_ptr = UV.create_handle(:uv_check) check_result! UV.check_init(@pointer, check_ptr) Check.new(self, check_ptr) end |
#fs ⇒ Object
Public: Get a new Filesystem instance
Returns UV::Filesystem
269 270 271 |
# File 'lib/uv/loop.rb', line 269 def fs Filesystem.new(self) end |
#fs_event(path, &block) ⇒ Object
Public: Get a new FSEvent instance
Returns UV::FSEvent
276 277 278 279 280 281 282 283 284 285 |
# File 'lib/uv/loop.rb', line 276 def fs_event(path, &block) assert_block(block) assert_arity(3, block) fs_event_ptr = UV.create_handle(:uv_fs_event) fs_event = FSEvent.new(self, fs_event_ptr, &block) check_result! UV.fs_event_init(@pointer, fs_event_ptr, path, fs_event.callback(:on_fs_event), 0) fs_event end |
#idle ⇒ Object
Public: Get a new Idle handle
Returns UV::Handle
225 226 227 228 229 230 |
# File 'lib/uv/loop.rb', line 225 def idle idle_ptr = UV.create_handle(:uv_idle) check_result! UV.idle_init(@pointer, idle_ptr) Idle.new(self, idle_ptr) end |
#lookup_error(err) ⇒ Object
Internal: Get last error from the loop
Returns one of UV::Error or nil
129 130 131 132 133 134 135 136 |
# File 'lib/uv/loop.rb', line 129 def lookup_error(err) name = UV.err_name(err) msg = UV.strerror(err) return nil if name == "OK" Error.const_get(name.to_sym).new(msg) end |
#now ⇒ Object
Public: Get current time in microseconds
Returns timestamp with microseconds as an Integer
122 123 124 |
# File 'lib/uv/loop.rb', line 122 def now UV.now(@pointer) end |
#pipe(ipc = false) ⇒ Object
Public: Get a new Pipe instance
ipc - Boolean wether handle will be used for ipc, useful for sharing tcp socket
between processes
Returns UV::Pipe
193 194 195 196 197 198 199 200 |
# File 'lib/uv/loop.rb', line 193 def pipe(ipc = false) assert_boolean(ipc) pipe_ptr = UV.create_handle(:uv_pipe) check_result! UV.pipe_init(@pointer, pipe_ptr, ipc ? 1 : 0) Pipe.new(self, pipe_ptr) end |
#prepare ⇒ Object
Public: Get a new Prepare handle
Returns UV::Prepare
205 206 207 208 209 210 |
# File 'lib/uv/loop.rb', line 205 def prepare prepare_ptr = UV.create_handle(:uv_prepare) check_result! UV.prepare_init(@pointer, prepare_ptr) Prepare.new(self, prepare_ptr) end |
#run(run_type = :UV_RUN_DEFAULT) ⇒ Object
Public: Run the actual event loop. This method will block for the duration of event loop
Returns nothing.
Raises UV::Error::UNKNOWN Raises UV::Error::EOF Raises UV::Error::EADDRINFO Raises UV::Error::EACCES Raises UV::Error::EAGAIN Raises UV::Error::EADDRINUSE Raises UV::Error::EADDRNOTAVAIL Raises UV::Error::EAFNOSUPPORT Raises UV::Error::EALREADY Raises UV::Error::EBADF Raises UV::Error::EBUSY Raises UV::Error::ECONNABORTED Raises UV::Error::ECONNREFUSED Raises UV::Error::ECONNRESET Raises UV::Error::EDESTADDRREQ Raises UV::Error::EFAULT Raises UV::Error::EHOSTUNREACH Raises UV::Error::EINTR Raises UV::Error::EINVAL Raises UV::Error::EISCONN Raises UV::Error::EMFILE Raises UV::Error::EMSGSIZE Raises UV::Error::ENETDOWN Raises UV::Error::ENETUNREACH Raises UV::Error::ENFILE Raises UV::Error::ENOBUFS Raises UV::Error::ENOMEM Raises UV::Error::ENOTDIR Raises UV::Error::EISDIR Raises UV::Error::ENONET Raises UV::Error::ENOTCONN Raises UV::Error::ENOTSOCK Raises UV::Error::ENOTSUP Raises UV::Error::ENOENT Raises UV::Error::ENOSYS Raises UV::Error::EPIPE Raises UV::Error::EPROTO Raises UV::Error::EPROTONOSUPPORT Raises UV::Error::EPROTOTYPE Raises UV::Error::ETIMEDOUT Raises UV::Error::ECHARSE Raises UV::Error::EAIFAMNOSUPPORT Raises UV::Error::EAISERVICE Raises UV::Error::EAISOCKTYPE Raises UV::Error::ESHUTDOWN Raises UV::Error::EEXIST Raises UV::Error::ESRCH Raises UV::Error::ENAMETOOLONG Raises UV::Error::EPERM Raises UV::Error::ELOOP Raises UV::Error::EXDEV Raises UV::Error::ENOTEMPTY Raises UV::Error::ENOSPC
97 98 99 |
# File 'lib/uv/loop.rb', line 97 def run(run_type = :UV_RUN_DEFAULT) check_result! UV.run(@pointer, run_type) end |
#run_once ⇒ Object
Public: (Deprecated - use loop.run with a run_type specified) Runs outstanding events once, yields control back
Returns nothing
104 105 106 |
# File 'lib/uv/loop.rb', line 104 def run_once run(:UV_RUN_ONCE) end |
#signal ⇒ Object
Public: Get a new Signal handle
Returns UV::Signal
290 291 292 293 294 295 |
# File 'lib/uv/loop.rb', line 290 def signal signal_ptr = UV.create_handle(:uv_signal) check_result! UV.signal_init(@pointer, signal_ptr) Signal.new(self, signal_ptr) end |
#stop ⇒ Object
108 109 110 |
# File 'lib/uv/loop.rb', line 108 def stop check_result! UV.stop(@pointer) end |
#tcp ⇒ Object
Public: Get a new TCP instance
Returns UV::TCP instance
151 152 153 154 155 156 |
# File 'lib/uv/loop.rb', line 151 def tcp tcp_ptr = UV.create_handle(:uv_tcp) check_result! UV.tcp_init(@pointer, tcp_ptr) TCP.new(self, tcp_ptr) end |
#timer ⇒ Object
Public: Get a new timer instance
Returns UV::Timer
141 142 143 144 145 146 |
# File 'lib/uv/loop.rb', line 141 def timer timer_ptr = UV.create_handle(:uv_timer) check_result! UV.timer_init(@pointer, timer_ptr) Timer.new(self, timer_ptr) end |
#to_ptr ⇒ Object
Internal: Get a hold of internal loop pointer instance
Returns FFI::Pointer
300 301 302 |
# File 'lib/uv/loop.rb', line 300 def to_ptr @pointer end |
#tty(fileno, readable = false) ⇒ Object
Public: Get a new TTY instance
fileno - Integer file descriptor of a tty device. readable - Boolean wether TTY is readable or not
Returns UV::TTY
Raises ArgumentError if fileno argument is not an Integer Raises Argument error if readable is not a Boolean
177 178 179 180 181 182 183 184 185 |
# File 'lib/uv/loop.rb', line 177 def tty(fileno, readable = false) assert_type(Integer, fileno, "io#fileno must return an integer file descriptor, #{fileno.inspect} given") assert_boolean(readable) tty_ptr = UV.create_handle(:uv_tty) check_result! UV.tty_init(@pointer, tty_ptr, fileno, readable ? 1 : 0) TTY.new(self, tty_ptr) end |
#udp ⇒ Object
Public: Get a new UDP instance
Returns UV::UDP instance
161 162 163 164 165 166 |
# File 'lib/uv/loop.rb', line 161 def udp udp_ptr = UV.create_handle(:uv_udp) check_result! UV.udp_init(@pointer, udp_ptr) UV::UDP.new(self, udp_ptr) end |
#update_time ⇒ Object
Public: forces loop time update, useful for getting more granular times
Returns nothing
115 116 117 |
# File 'lib/uv/loop.rb', line 115 def update_time UV.update_time(@pointer) end |
#work(callback = nil, op = nil, &block) ⇒ Object
Public: Do some work in the libuv thread pool
Returns UV::Work
Raises ArgumentError if block is not given and if the block or optional callback are expecting any arguments
253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/uv/loop.rb', line 253 def work(callback = nil, op = nil, &block) block = block || op assert_block(block) assert_arity(0, block) if not callback.nil? assert_block(callback) assert_arity(0, callback) end work = Work.new(self, block, callback) end |