Home Explore Blog CI



neovim

16th chunk of `runtime/doc/luvref.txt`
e93d26eb1510079efdd0d3b5780ab00d6f77a2ed837ff78e0000000100000fa2
 the events field.

                The user should not close the socket while the handle is
                active. If the user does that anyway, the callback may be
                called reporting an error status, but this is not guaranteed.

                Returns: `0` or `fail`

                Note Calling `uv.poll_start()` on a handle that is already
                active is fine. Doing so will update the events mask that is
                being watched for.

uv.poll_stop({poll})                                            *uv.poll_stop()*

                > method form `poll:stop()`

                Parameters:
                - `poll`: `uv_poll_t userdata`

                Stop polling the file descriptor, the callback will no longer
                be called.

                Returns: `0` or `fail`

==============================================================================
`uv_signal_t` — Signal handle                      *luv-signal-handle* *uv_signal_t*

> |uv_handle_t| functions also apply.

Signal handles implement Unix style signal handling on a per-event loop bases.

Windows Notes:

Reception of some signals is emulated on Windows:
  - SIGINT is normally delivered when the user presses CTRL+C. However, like
    on Unix, it is not generated when terminal raw mode is enabled.
  - SIGBREAK is delivered when the user pressed CTRL + BREAK.
  - SIGHUP is generated when the user closes the console window. On SIGHUP the
    program is given approximately 10 seconds to perform cleanup. After that
    Windows will unconditionally terminate it.
  - SIGWINCH is raised whenever libuv detects that the console has been
    resized. SIGWINCH is emulated by libuv when the program uses a uv_tty_t
    handle to write to the console. SIGWINCH may not always be delivered in a
    timely manner; libuv will only detect size changes when the cursor is
    being moved. When a readable |uv_tty_t| handle is used in raw mode,
    resizing the console buffer will also trigger a SIGWINCH signal.
  - Watchers for other signals can be successfully created, but these signals
    are never received. These signals are: SIGILL, SIGABRT, SIGFPE, SIGSEGV,
    SIGTERM and SIGKILL.
  - Calls to raise() or abort() to programmatically raise a signal are not
    detected by libuv; these will not trigger a signal watcher.

Unix Notes:

  - SIGKILL and SIGSTOP are impossible to catch.
  - Handling SIGBUS, SIGFPE, SIGILL or SIGSEGV via libuv results into
    undefined behavior.
  - SIGABRT will not be caught by libuv if generated by abort(), e.g. through
    assert().
  - On Linux SIGRT0 and SIGRT1 (signals 32 and 33) are used by the NPTL
    pthreads library to manage threads. Installing watchers for those signals
    will lead to unpredictable behavior and is strongly discouraged. Future
    versions of libuv may simply reject them.

    >lua
    -- Create a new signal handler
    local signal = uv.new_signal()
    -- Define a handler function
    uv.signal_start(signal, "sigint", function(signame)
      print("got " .. signame .. ", shutting down")
      os.exit(1)
    end)
<

uv.new_signal()                                                *uv.new_signal()*

                Creates and initializes a new |uv_signal_t|. Returns the Lua
                userdata wrapping it.

                Returns: `uv_signal_t userdata` or `fail`

uv.signal_start({signal}, {signame}, {callback})             *uv.signal_start()*

                > method form `signal:start(signame, callback)`

                Parameters:
                - `signal`: `uv_signal_t userdata`
                - `signame`: `string` or `integer`
                - `callback`: `callable`
                  - `signame`: `string`

                Start the handle with the given callback, watching for the
                given signal.

                See |luv-constants| for supported `signame` input and output
                values.

                Returns: `0` or `fail`
                       

Title: Libuv: Signal Handles (`uv_signal_t`)
Summary
This section covers libuv's signal handling capabilities via `uv_signal_t`. It describes the behavior of signal handling on both Windows and Unix-like systems, noting limitations and caveats for specific signals (SIGINT, SIGBREAK, SIGHUP, SIGWINCH, SIGKILL, SIGSTOP, etc.). It also warns against using libuv to handle certain signals like SIGBUS, SIGFPE, SIGILL, and SIGSEGV, as well as SIGRT0 and SIGRT1 on Linux. The section then provides examples of creating and starting signal handlers using `uv.new_signal()` and `uv.signal_start()`, explaining the parameters and return values.