Class: Libuv::Signal

Inherits:
Handle show all
Defined in:
lib/libuv/signal.rb

Constant Summary collapse

SIGNALS =
{
    :HUP => 1,
    :SIGHUP => 1,
    :INT => 2,
    :SIGINT => 2,
    :TERM => 15,
    :SIGTERM => 15,
    :BREAK => 21,
    :SIGBREAK => 21,
    :WINCH => 28,
    :SIGWINCH => 28
}

Constants included from Assertions

Assertions::MSG_NO_PROC

Constants inherited from Q::Promise

Q::Promise::MAKE_PROMISE

Instance Attribute Summary

Attributes inherited from Handle

#closed, #reactor, #storage

Attributes inherited from Q::Promise

#trace

Instance Method Summary collapse

Methods inherited from Handle

#active?, #close, #closed?, #closing?, #ref, #unref

Methods included from Assertions

#assert_block, #assert_boolean, #assert_type

Methods included from Resource

#check_result, #check_result!, #resolve, #to_ptr

Methods inherited from Q::DeferredPromise

#resolved?, #then

Methods inherited from Q::Promise

#catch, #finally, #progress, #ruby_catch, #value

Constructor Details

#initialize(reactor) ⇒ Signal

Returns a new instance of Signal.

Parameters:

  • reactor (::Libuv::Reactor)

    reactor this signal handler will be associated

  • callback (Proc)

    callback to be called when the signal is triggered



26
27
28
29
30
31
32
33
# File 'lib/libuv/signal.rb', line 26

def initialize(reactor)
    @reactor = reactor

    signal_ptr = ::Libuv::Ext.allocate_handle_signal
    error = check_result(::Libuv::Ext.signal_init(reactor.handle, signal_ptr))

    super(signal_ptr, error)
end

Instance Method Details

#start(signal) ⇒ Object

Enables the signal handler.



36
37
38
39
40
41
42
# File 'lib/libuv/signal.rb', line 36

def start(signal)
    return if @closed
    signal = SIGNALS[signal] if signal.is_a? Symbol
    error = check_result ::Libuv::Ext.signal_start(handle, callback(:on_sig), signal)
    reject(error) if error
    self
end

#stopObject

Disables the signal handler.



45
46
47
48
49
50
# File 'lib/libuv/signal.rb', line 45

def stop
    return if @closed
    error = check_result ::Libuv::Ext.signal_stop(handle)
    reject(error) if error
    self
end