Backported thread affinity feature and related dependency commits
from master. It will add support for those APIs: uv_cpumask_size,
uv_thread_setaffinity, uv_thread_getaffinity.
The supported platforms are Linux, Freebsd, and Windows.
Empty implementations (returning UV_ENOTSUP) on non-supported platforms
(such as OS X and AIX).
Replacement for the usage pattern where people use uv_cpu_info() as an
imperfect heuristic for determining the amount of parallelism that is
available to their programs.
Fixes#3493.
- Add `Makefile` for example codes. (cherry-pick from old uvbook repo)
- Add a new example "Default loop" to "Basics of libuv"/"Default loop"
- Document review and update: `Introduction`, `Basics of libuv`, `Filesystem`
+ Update the referenced libuv code snippet
+ Link update: http->https
**Content Updates**:
- `filesystem.rst`#L291-L297: Add note for `uv_fs_event_start`
- `filesystem.rst`#L334: Add description of the callback function parameter `status`
The following examples have been tested manually in WSL2 (Ubuntu 20.04) with libuv 1.42.0:
- helloworld
- default-loop
- idle-basic
- uvcat
- uvtee
- onchange (test on macOS)
Co-authored-by: Nikhil Marathe <nsm.nikhil@gmail.com>
`uv_try_write2(stream, bufs, nbufs, send_handle)` acts like
`uv_try_write()` and extended write function for sending handles over a
pipe like `uv_write2`. It always returns `UV_EAGAIN` instead of
`UV_ENOSYS` on Windows so we can easily write cross-platform code
without special treatment.
PR-URL: https://github.com/libuv/libuv/pull/3183
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Implementation is based on RLIMIT_MEMLIMIT.
Co-authored-by: Igor Todorovski <itodorov@ca.ibm.com>
PR-URL: https://github.com/libuv/libuv/pull/3133
Reviewed-By: Richard Lau <rlau@redhat.com>
The Linux kernel suppresses some ICMP error messages by default for UDP
sockets. This commit sets IP_RECVERR/IPV6_RECVERR on the socket to
enable full ICMP error reporting, hopefully resulting in faster failover
to working name servers.
PR-URL: https://github.com/libuv/libuv/pull/2872
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
PR-URL: https://github.com/libuv/libuv/pull/3061
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Equivalents of `pipe` and `socketpair` for cross-platform use.
PR-URL: https://github.com/libuv/libuv/pull/2953
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
The behavior of `uv_read_start()` when the handle is closing or already
busy reading wasn't consistent across platforms. Now it is.
Fixes: https://github.com/libuv/help/issues/137
PR-URL: https://github.com/libuv/libuv/pull/2795
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Added notes to documentation of `uv_poll_t`:
- The callback will be called over-and-over again as long as the socket
remains readable/writable.
- uv_poll_stop() cancels pending callbacks of already happened events.
Fixes: https://github.com/libuv/libuv/issues/1078
PR-URL: https://github.com/libuv/libuv/pull/1100
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
It defers the error to uv_listen() or uv_tcp_connect().
PR-URL: https://github.com/libuv/libuv/pull/2218
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Store a copy of the original argv[0] to protect `uv_exepath()`
against `uv_set_process_title()` changing the value of argv[0].
Extract common code for finding a program on the current PATH.
Fixes: https://github.com/libuv/libuv/issues/2674
PR-URL: https://github.com/libuv/libuv/pull/2677
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
This commit updates uv_{get,set}_process_title() to return an
error when uv_setup_args() is needed, but has not been called.
Per-platform behavior after this commit:
- Windows: uv_setup_args() does nothing, get/set process title
works as before.
- Unix: get/set process title will return ENOBUFS if
uv_setup_args() wasn't called, if it failed, or if the process
title memory has been freed by uv__process_title_cleanup()
(via uv_library_shutdown()).
- AIX: set process title returns ENOBUFS if uv_setup_args()
wasn't called, if it failed to allocate memory for the argv
copy, or if the proctitle memory has been freed by
uv__process_title_cleanup() (via uv_library_shutdown).
Getting the process title will do the same except it can
still succeed if uv_setup_args() was called but failed to
allocate memory for the argv copy.
- BSD: uv_setup_args() is only needed for getting the initial
process title; if uv_setup_args() is not called then any
get_process_title calls() before a set_process_title() call
will return an empty string.
- Platforms that use no-proctitle.c: get will return an empty
string, set is a no-op (these are the same as before this commit)
Fixes: https://github.com/libuv/libuv/issues/2845
PR-URL: https://github.com/libuv/libuv/pull/2853
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
The API addition `uv_metrics_idle_time()` is a thread safe call that
allows the user to retrieve the amount of time the event loop has spent
in the kernel's event provider (i.e. poll). It was done this way to
allow retrieving this value without needing to interrupt the execution
of the event loop. This option can be enabled by passing
`UV_METRICS_IDLE_TIME` to `uv_loop_configure()`.
One important aspect of this change is, when enabled, to always first
call the event provider with a `timeout == 0`. This allows libuv to know
whether any events were waiting in the event queue when the event
provider was called. The importance of this is because libuv is tracking
the amount of "idle time", not "poll time". Thus the provider entry time
is not recorded when `timeout == 0` (the event provider never idles in
this case).
While this does add a small amount of overhead, when enabled, but the
overhead decreases when the event loop has a heavier load. This is
because poll events will be waiting when the event provider is called.
Thus never actually recording the provider entry time.
Checking if `uv_loop_t` is configured with `UV_METRICS_IDLE_TIME` always
happens in `uv__metrics_set_provider_entry_time()` and
`uv__metrics_update_idle_time()`. Making the conditional logic wrapping
each call simpler and allows for instrumentation to always hook into
those two function calls.
Rather than placing the fields directly on `uv__loop_internal_fields_t`
add the struct `uv__loop_metrics_t` as a location for future metrics API
additions.
Tests and additional documentation has been included.
PR-URL: https://github.com/libuv/libuv/pull/2725
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Allows for determining if a buffer large enough for multiple dgrams
should be allocated in alloc_cb of uv_udp_recvstart, for example.
Contributes towards #2822.
PR-URL: https://github.com/libuv/libuv/pull/2830
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Exposes the original system error of the filesystem syscalls. Adds a new
uv_fs_get_system_error which returns orignal errno on Linux or
GetLastError on Windows.
Ref: https://github.com/libuv/libuv/issues/2348
PR-URL: https://github.com/libuv/libuv/pull/2810
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Make the documentation reflect that the init/start/stop functions
for check/idle/prepare handles always succeed.
PR-URL: https://github.com/libuv/libuv/pull/2803
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This was causing a warning during the documentation build.
PR-URL: https://github.com/libuv/libuv/pull/2797
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This seems to be the case from reading the code of uv_cancel().
Also fixes a broken link due to a markup typo.
PR-URL: https://github.com/libuv/libuv/pull/2797
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Make it possible to explicitly tell libuv to release any resources
it's still holding onto (memory, threads, file descriptors, etc.)
Before this commit, cleanup was performed in various destructors.
This commit centralizes the cleanup logic, enabling the addition of
`uv_library_shutdown()`, but maintains the current observable behavior
of cleaning up when libuv is unloaded by means of `dlclose(3)`.
Fixes: https://github.com/libuv/libuv/issues/2763
PR-URL: https://github.com/libuv/libuv/pull/2764
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
On Linux, cpu_times have been calculated differently to all other
platforms for a while. Other platforms (FreeBSD, Mac, Windows) are all
in milliseconds, but Linux has been returning values ten times larger.
libuv has not previously documented what unit cpu_times uses, even
though NodeJS did - as milliseconds.
Here we're both documenting that the cpu_times are indeed in
milliseconds, and fixing the inconsistency on Linux.
Fixes: https://github.com/libuv/libuv/issues/2773
PR-URL: https://github.com/libuv/libuv/pull/2796
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
On IBMi PASE, the highest process priority is -10.
PR-URL: https://github.com/libuv/libuv/pull/2642
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
When recvmmsg support was added it returned the datagrams in reverse
received order, which may impact some applications.
To restore the previous behavior, we call recv_cb one last time with
nread == 0 and addr == NULL so applications can free the buffer.
PR-URL: https://github.com/libuv/libuv/pull/2736
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commits adds support for recvmmsg() and sendmmsg() extensions to
recvmsg() and sendmsg() that allows the caller to receive and send
multiple message from a socket using a single system call. This has
performance benefits for some applications.
Co-authored-by: Ondřej Surý <ondrej@sury.org>
Co-authored-by: Witold Kręcicki <wpk@culm.net>
PR-URL: https://github.com/libuv/libuv/pull/2532
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <s@saghul.net>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
PR-URL: https://github.com/libuv/libuv/pull/2668
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Current UNIX systems define various defaults for
TCP_KEEPINTVL and TCP_KEEPCNT, which makes the time
between TCP_KEEPIDLE delay is reached and timeout
effectively occurs unpredictable (Linux: /proc/sys
/net/ipv4/tcp_keepalive_intvl;tcp_keepalive_probes).
Do the following: set TCP_KEEPINTVL to 1 second (same
as Win32 default) and TCP_KEEPCNT to 10 times (same
as Win32 hardcoded value).
Fixes: https://github.com/libuv/libuv/issues/2664
PR-URL: https://github.com/libuv/libuv/pull/2669
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
The embedded color profiles are proprietary data. Considering that
embedding a color profile in a image is not necessary when color
accuracy is not important, it's better to strip them.
This was done with:
convert -strip docs/src/static/diagrams.key/Data/st0-311.jpg \
docs/src/static/diagrams.key/Data/st0-311.jpg
convert -strip docs/src/static/diagrams.key/Data/st1-475.jpg \
docs/src/static/diagrams.key/Data/st1-475.jpg
convert command comes from ImageMagick project.
Fixes: https://github.com/libuv/libuv/issues/2670
PR-URL: https://github.com/libuv/libuv/pull/2672
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Some people have misread this section to imply that libuv does not
support Unix `pipe` objects, while it only should be saying that the
UV_CREATE_PIPE makes a socketpair. Clarify the docs to say specifically
that `uv_pipe_t` represents any local file stream.
PR-URL: https://github.com/libuv/libuv/pull/2607
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Prefer https when available, follow permanent redirects, and find
alternate sources for dead links.
PR-URL: https://github.com/libuv/libuv/pull/2608
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit exposes the uv_sleep() function that previously
only existed in the test runner.
PR-URL: https://github.com/libuv/libuv/pull/2548
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This commit fixes uv_fs_copyfile() in cases where an unknown error
occurs when copy-on-write is requested by setting
UV_FS_COPYFILE_FICLONE. The original approach tried to catch some of
the errors raised by the ioctl() call, assuming that sendfile() would
also fail in those cases. This is not necessarily true, as some
variants of ioctl() also raise EINVAL (some maybe EBADF), but sendfile()
works just fine.
This patch reverses the logic, falling back to sendfile() in any
case where ioctl() returns an error. In other words, it tries much
harder to make uv_fs_copyfile() work.
Related to that, the original approach returned UV_ENOTSUP
unconditionally in cases where ioctl() failed and
UV_FS_COPYFILE_FICLONE_FORCE was set. However, ioctl() may have
failed for other reasons than being not supported. The function
now returns the actual error raised by ioctl(), leaving it to the
caller to deal with it.
Fixes: https://github.com/libuv/libuv/issues/2483
PR-URL: https://github.com/libuv/libuv/pull/2514
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
When cleaning up after uv_fs_readdir(), it is important to
call uv_fs_req_cleanup() on the readdir request prior to calling
uv_fs_closedir(), because the latter frees memory that the
former needs in order to do its job.
PR-URL: https://github.com/libuv/libuv/pull/2497
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Add an API for obtaining cryptographically strong random data from the
system PRNG.
Co-authored-by: Saúl Ibarra Corretgé <s@saghul.net>
Refs: https://github.com/libuv/libuv/pull/1055
PR-URL: https://github.com/libuv/libuv/pull/2347
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit contains a suggestion to hopefully improve the
documentation of uv_handle_t's member uv_loop_t.
PR-URL: https://github.com/libuv/libuv/pull/2446
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Continuing improvement of SIGWINCH from PR #2308.
Running SetWinEventHook without filtering for the specific PIDs has
significant impact on the performance of the entire system. This PR
changes the way SIGWINCH is handled.
The SetWinEventHook callback now signals a separate thread,
uv__tty_console_resize_watcher_thread. This thread calls
uv__tty_console_signal_resize() which checks if the console was actually
resized. The uv__tty_console_resize_watcher_thread makes sure to not to
call the uv__tty_console_signal_resize function more than 30 times per
second.
The SetWinEventHook will not be installed, if the PID of the
conhost.exe process that owns the console window cannot be
determinated. This can happen when a 32bit libuv app is running on a
64bit Windows.
For such cases PR #1408 is partially reverted - when tty reads
WINDOW_BUFFER_SIZE_EVENT, it will also trigger a call to
uv__tty_console_signal_resize(). This will also help when the app is
running under console emulators. Documentation was also updated to
reflect that.
Refs: https://github.com/microsoft/terminal/issues/1811
Refs: https://github.com/microsoft/terminal/issues/410
Refs: https://github.com/libuv/libuv/pull/2308
PR-URL: https://github.com/libuv/libuv/pull/2381
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Clarify the uv_buf_t isn't reused and the user is responsible for
freeing it in the recv/read callback.
Previously, this wasn't clear when reading only the docs for
uv_udp_recv_cb and uv_alloc_cb.
PR-URL: https://github.com/libuv/libuv/pull/2438
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
It resets a TCP connection by sending a RST packet. Due to some platform
inconsistencies, mixing of `uv_shutdown` and `uv_tcp_close_reset` calls
is not allowed.
Fixes: https://github.com/libuv/libuv/issues/1991
PR-URL: https://github.com/libuv/libuv/pull/2425
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reading and writing files using a memory file mapping can be
significantly faster on Windows.
PR-URL: https://github.com/libuv/libuv/pull/2295
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
app.info() was deprecated on Jan 4, 2017 (sphinx-doc/sphinx#3267),
and removed as of Sphinx 2.0.0. This commit removes the usage of
app.info().
PR-URL: https://github.com/libuv/libuv/pull/2265
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>