Sha256: e4a929cb356f590b4c5995b69c22fcd1cd5ef091fdfb452f88b1366d1bb19edc

Contents?: true

Size: 1.36 KB

Versions: 13

Compression:

Stored size: 1.36 KB

Contents

module Libuv
    class Signal < Handle


        define_callback function: :on_sig, params: [:pointer, :int]


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


        # @param loop [::Libuv::Loop] loop this signal handler will be associated
        # @param callback [Proc] callback to be called when the signal is triggered
        def initialize(loop)
            @loop = loop

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

            super(signal_ptr, error)
        end

        # Enables the signal handler.
        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
        end

        # Disables the signal handler.
        def stop
            return if @closed
            error = check_result ::Libuv::Ext.signal_stop(handle)
            reject(error) if error
        end


        private


        def on_sig(handle, signal)
            defer.notify(signal)   # notify of a call
        end
    end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
libuv-2.0.12 lib/libuv/signal.rb
libuv-2.0.11 lib/libuv/signal.rb
libuv-2.0.10 lib/libuv/signal.rb
libuv-2.0.9 lib/libuv/signal.rb
libuv-2.0.8 lib/libuv/signal.rb
libuv-2.0.6 lib/libuv/signal.rb
libuv-2.0.5 lib/libuv/signal.rb
libuv-2.0.4 lib/libuv/signal.rb
libuv-2.0.3 lib/libuv/signal.rb
libuv-2.0.2 lib/libuv/signal.rb
libuv-2.0.1 lib/libuv/signal.rb
libuv-2.0.0 lib/libuv/signal.rb
libuv-1.3.0 lib/libuv/signal.rb