The uv__get_osfhandle() function is a private functio of the
Windows subsystem, and its used to get a Windows HANDLE out
of a file descriptor number.
The motivation behind making this function public is to
allow Node.js programs to pass file descriptors created
using fs.open() to native Node.js C++ add-ons, and be able to
successfully convert them to Windows HANDLEs.
Refs: https://github.com/libuv/libuv/pull/1166
Refs: https://github.com/nodejs/node/issues/6369
Fixes: https://github.com/libuv/libuv/issues/1291
PR-URL: https://github.com/libuv/libuv/pull/1323
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Cygwin and MSYS2 are POSIX layers implemented on top of Windows.
Use our POSIX `poll(2)` implementation of our poll abstraction.
For most other components we already have dedicated sources
implementing them in terms of APIs available on Cygwin or
providing non-implementations of components not supported.
This leaves only three components that need Cygwin-specific
implementations:
* uv_uptime: implement using sysinfo
* uv_resident_set_memory: add a placeholder returning UV_ENOSYS
* uv_cpu_info: add a placeholder returning UV_ENOSYS
Update our test suite to account for features not available
due to Cygwin platform limitations or our placeholders.
PR-URL: https://github.com/libuv/libuv/pull/1312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
POSIX defines `poll()` as a portable way to wait on file descriptors.
Use it to provide an implementation of our poll abstraction for use
on platforms that do not provide a more specialized polling method.
PR-URL: https://github.com/libuv/libuv/pull/1312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Added the uv_loop_fork() API that must be called in a child process to
continue using an existing loop. Internally this calls a uv__io_fork
function for each supported platform, similar to the way
uv__platform_loop_init works.
After this call, existing and new IO, async and signal watchers will
contiue working as before on all platforms, as will the
threadpool (although any threads it was using are of course gone).
On Linux and BSDs that use kqueue, existing and new fsevent watchers
will also continue to work as expected. On OS X, though, directory
fsevents will not be able to use the optimized CoreFoundation path if
they had already been used in the parent process, instead falling back
to the kqueue path used on other BSDs.
Existing fsevent watchers will not function on AIX or SunOS. This
could be relatively easily fixed by someone with AIX knowledge in the
future, but SunOS will require some additional work to keep track if
the watchers.
A new test file, test/test-fork.c, was added to contain fork-related
tests to verify functionality in the child process.
PR-URL: https://github.com/libuv/libuv/pull/846
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Remove the unused `nevents` parameter from `uv__async_event()`
and remove the indirection of having a separate `uv__async`
type. There is only one instance per event loop these days.
This incidentally removes the `assert(n == sizeof(val))` in a
Linux-specific code path that some users seem to hit from time
to time. The cause is not well-understood and I've never been
able to reproduce it myself. Presumably libuv gets an EAGAIN
when trying to read from the eventfd but when and why that
happens is unclear.
Since the byte count is unused, removing the assert seems safe.
Worst case, libuv sometimes iterates over the async watcher list
when it doesn't have to.
Fixes: https://github.com/libuv/libuv/issues/1171
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Supersedes: https://github.com/libuv/libuv/pull/1214
It behaves as `uv_signal_start` but it resets the signal handler as soon
as the signal is received.
Fixes: https://github.com/libuv/libuv/issues/1104
PR-URL: https://github.com/libuv/libuv/pull/1106
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Fix all functional test cases:
* use PLO compare,swap,store for atomic instruction
* do not use semaphore.h
* use xplink flag when linking
* scandir implementation
* nanosleep implementation
* add proctitle
* uv_loadavg
* uv_fs_event_init/start
* uv_fs_event_stop
* uv_exepath using __getthent syscall
* read free/total memory from mvs data areas
* uv_resident_set_memory implementation
* network interfaces implementation
* cpu_info implementation
* implement uv__hrtime
* make uv__fs_mkdtemp implementation
* epoll implementation for asyncio
* uv__fs_event_close implementation
* set process title
* read ancillary data that remains on queue
* ancillary data
* implement uv__fs_access
* use /dev/urandom for temporary directory name
* disable proctitle on zos completely
PR-URL: https://github.com/libuv/libuv/pull/1037
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Changes since version 1.10.1:
* Now working on version 1.10.2 (cjihrig)
* darwin: fix fsync and fdatasync (Joran Dirk Greef)
* Revert "Revert "win,tty: add support for ANSI codes in win10 v1511""
(Santiago Gimeno)
* win,tty: fix MultiByteToWideChar output buffer (Santiago Gimeno)
* win: remove dead code related to BACKUP_SEMANTICS (Sam Roberts)
* win: fix comment in quote_cmd_arg (Eric Sciple)
* darwin: use clock_gettime in macOS 10.12 (Saúl Ibarra Corretgé)
* win, tty: fix crash on restarting with pending data (Nicholas Vavilov)
* fs: fix uv__to_stat on BSD platforms (Santiago Gimeno)
* win: map ERROR_ELEVATION_REQUIRED to UV_EACCES (Richard Lau)
* win: fix free() on bad input in uv_getaddrinfo() (Ben Noordhuis)
Changes since version 1.10.0:
* Now working on version 1.10.1 (cjihrig)
* win: fix anonymous union syntax (Brad King)
* unix: use uv__is_closing everywhere (Santiago Gimeno)
* win: add missing break statement (cjihrig)
* doc: fix wrong man page link for uv_fs_lstat() (Michele Caini)
* win, tty: handle empty buffer in uv_tty_write_bufs (Hitesh
Kanwathirtha)
* doc: add cjihrig alternative GPG ID (cjihrig)
* Revert "win,tty: add support for ANSI codes in win10 v1511" (Ben
Noordhuis)
uv_translate_sys_error() was a private function for Windows.
This commit adds an equivalent function on other platforms, and
exposes it as public API.
Exposing this is useful in scenarios where the application uses
both libuv functions and platform-specific system calls and wants
to report errors uniformly as libuv errors.
Fixes: https://github.com/libuv/libuv/issues/79
PR-URL: https://github.com/libuv/libuv/pull/1060
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Move the `PASCAL` calling convention marker from:
typedef void PASCAL (*f)(...);
to the proper place for a calling convention in a function pointer type:
typedef void (PASCAL *f)(...);
This is where the MS-provided winapi headers place it too.
PR-URL: https://github.com/libuv/libuv/pull/1075
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
autotools support only, gvp does not support kfreebsd detection.
PR-URL: https://github.com/libuv/libuv/pull/960
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
- zos: disable test cases not applicable
- zos: build options
- zos: semaphore implementation
- zos: use compare and swap builtins
- zos: struct rusage not the same as other platforms
- zos: backlog<=0 produces undefined behaviour
Will redefine backlog in the following way
* if backlog == 0, set it to 1
* if backlog < 0, set it to SOMAXCONN
- zos: define IMAXBEL as empty flag and implement uv__tty_make_raw
- zos: use udp multicast operations from aix
- zos: ESC in ebcdic
- zos: use LIBPATH for dynamic linker path
- zos: uv_udp_set_ttl only works for ipv6
- zos: increase pthread stack size by factor of 4
- zos: return ENODEV instead of ENXIO errors for setsockopt
- zos: use uv_cond_init the same way as aix
- test: enable oob test for zos
- zos: return EINVAL for zos error code EOPNOTSUPP
PR-URL: https://github.com/libuv/libuv/pull/937
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Since we cancel ReadConsole by sending a newline, the duplicate
handle is no longer necessary.
PR-URL: https://github.com/libuv/libuv/pull/866
Reviewed-by: Bert Belder <bertbelder@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
There was a memory corruption issue with the pthread barrier
implementation on android, where a barrier could still be in use by one
thread when being freed by another.
This fixes that issue and adds lots of missing error handling.
This implementation is now also used for the OSX fallback.
Fixes: https://github.com/libuv/libuv/issues/615
PR-URL: https://github.com/libuv/libuv/pull/790
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Equivalent to realpath(3), returns the full resolved absolute path of a
file or directory.
PR-URL: https://github.com/libuv/libuv/pull/531
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Fixes a compilation problem in some platforms (notably OSX) after
6490c50.
PR-URL: https://github.com/libuv/libuv/pull/618
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremy Whitlock <jwhitlock@apache.org>
Previously, on Windows Vista and later, we'd use the Windows native
SRWLock APIs. However they turned out to be semantically incompatible
with pthread read-write locks and/or plain buggy. This patch makes sure
that the custom implementation that was previously only used on old
Windows versions is now used everywhere.
This patch fixes a number of issues with the old fallback
implementation. Specifically:
* The reader count would not be incremented when a thread successfully
acquired a read lock while another thread *also* held a read lock.
* `uv_rwlock_tryrdlock()` and `uv_rwlock_trywrlock()` now
consistently return UV_EBUSY when a lock couldn't be acquired.
* Any unexpected errors now cause libuv to abort, with the exception of
`uv_rwlock_init()`.
See also https://github.com/libuv/libuv/issues/515.
PR-URL: https://github.com/libuv/libuv/pull/525
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Before this patch an uv_mutex_t (backed by a critical section) could be
released by a tread different from the thread that acquired it, which is
not allowed. This is fixed by using a semaphore instead.
Note that the affected code paths were used on Windows XP and Windows
Server 2003 only.
Fixes: https://github.com/libuv/libuv/issues/515
PR-URL: https://github.com/libuv/libuv/pull/516
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Introduce two new APIs:
int uv_tcp_init_ex(uv_loop_t*, uv_tcp_t* handle, int flags)
int uv_udp_init_ex(uv_loop_t*, uv_udp_t* handle, int flags)
The lower 8 bits of the flags field are used for the socket domain.
AF_INET, AF_INET6 and AF_UNSPEC are supported. If AF_UNSPEC is specified
the socket is created lazily, just like uv_{tcp,udp}_init.
Some Windows notes:
getsockname fails with WSAEINVAL if the socket is not bound. This could
potentially be improved by detecting the socket family and filling
the sockaddr_in/6 struct manually.
bind returns WSAEFAULT if we try to bind a socket to the wrong family.
Unix returns EINVAL.
PR-URL: https://github.com/libuv/libuv/pull/400
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Certain types of streams may be opened from a CRT file descriptor (as
opposed to a Windows HANDLE). In order to close the file descriptor
later, libuv must store the file descriptor used to open the stream.
PR-URL: https://github.com/libuv/libuv/pull/396
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
With uv_replace_allocator, it's possible to override the default
memory allocator's malloc and free calls with functions of the user's
choosing. This allows libuv to interoperate with projects requiring a
custom memory allocator.
Internally, all calls to malloc and free have been replaced with
uv__malloc and uv__free, respectively. The uv__malloc and uv__free
functions call malloc and free unless they have been overridden by a
previous call to uv_replace_allocator.
As part of this change, the special aligned memory allocations
performed in src/win/fs-event.c have been replaced with standard
allocations. The 4-byte alignment being requested in this file was
unnecessary, since standard allocators already guarantee at least an
8-byte alignment.
PR-URL: https://github.com/libuv/libuv/pull/231
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
All the public structs and unions in the private fields in uv-win.h have
been named and all code accessing them updated, to comply to the C89
spec (which were previously causing warnings with the -pedantic flag).
PR-URL: https://github.com/libuv/libuv/pull/239
Reviewed-By: Andrius Bentkus <andrius.bentkus@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Also make the tests more strict.
PR-URL: https://github.com/libuv/libuv/pull/201
Reviewed-By: Tim Caswell <tim@creationix.com>
Reviewed-By: Bert Belder <bertbelder@gmail.com>
Changes since version 1.3.0:
* unix: check Android support for pthread_cond_timedwait_monotonic_np
(Leith Bade)
* test: use modified path in test (cjihrig)
* unix: implement uv_stream_set_blocking() (Ben Noordhuis)
Changes since version 1.2.0:
* unix: remove unused dtrace file (Saúl Ibarra Corretgé)
* test: skip TTY select test if /dev/tty can't be opened (Saúl Ibarra
Corretgé)
* doc: clarify the behavior of uv_tty_init (Saúl Ibarra Corretgé)
* doc: clarify how uv_async_send behaves (Saúl Ibarra Corretgé)
* build: make dist now generates a full tarball (Johan Bergström)
* freebsd: make uv_exepath more resilient (Saúl Ibarra Corretgé)
* unix: make setting the tty mode to the same value a no-op (Saúl Ibarra
Corretgé)
* win,tcp: support uv_try_write (Bert Belder)
* test: enable test-tcp-try-write on windows (Bert Belder)
* win,tty: support uv_try_write (Bert Belder)
* unix: set non-block mode in uv_{pipe,tcp,udp}_open (Ben Noordhuis)
Introduce a uv_tty_mode_t enum for uv_tty_set_mode(), with backward
compatible values. Add a new mode UV_TTY_MODE_IO, which uses
cfmakeraw() internally.
PR-URL: https://github.com/libuv/libuv/pull/86
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Changes since version 1.0.2:
* test: test that closing a poll handle doesn't corrupt the stack (Bert
Belder)
* win: fix compilation of tests (Marc Schlaich)
* Revert "win: keep a reference to AFD_POLL_INFO in cancel poll" (Bert
Belder)
* win: avoid stack corruption when closing a poll handle (Bert Belder)
* test: fix test-fs-file-loop on Windows (Bert Belder)
* test: fix test-cwd-and-chdir (Bert Belder)
* doc: indicate what version uv_loop_configure was added on (Saúl Ibarra
Corretgé)
* doc: fix sphinx warning (Saúl Ibarra Corretgé)
* test: skip spawn_setuid_setgid if we get EACCES (Saúl Ibarra Corretgé)
* test: silence some Clang warnings (Saúl Ibarra Corretgé)
* test: relax osx_select_many_fds (Saúl Ibarra Corretgé)
* test: fix compilation warnings when building with Clang (Saúl Ibarra
Corretgé)
* win: fix autotools build of tests (Luis Lavena)
* gitignore: ignore Visual Studio files (Marc Schlaich)
* win: set fallback message if FormatMessage fails (Marc Schlaich)
* win: fall back to default language in uv_dlerror (Marc Schlaich)
* test: improve compatibility for dlerror test (Marc Schlaich)
* test: check dlerror is "no error" in no error case (Marc Schlaich)
* unix: change uv_cwd not to return a trailing slash (Saúl Ibarra
Corretgé)
* test: fix cwd_and_chdir test on Unix (Saúl Ibarra Corretgé)
* test: add uv_cwd output to platform_output test (Saúl Ibarra Corretgé)
* build: fix dragonflybsd autotools build (John Marino)
* win: scandir use 'ls' for formatting long strings (Kenneth Perry)
* build: remove clang and gcc_version gyp defines (Ben Noordhuis)
* unix, windows: don't treat uv_run_mode as a bitmask (Saúl Ibarra
Corretgé)
* unix, windows: fix UV_RUN_ONCE mode if progress was made (Saúl Ibarra
Corretgé)
The offending patch doesn't completely fix the issue, it just trades
stack corruption for heap corruption which is less likely.
In addition there is a much simpler solution for this problem.
This reverts commit cd894521dd.
PR-URL: https://github.com/libuv/libuv/pull/49
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Marc Schlaich <marc.schlaich@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Changes since version 1.0.1:
* linux: fix sigmask size arg in epoll_pwait() call (Ben Noordhuis)
* linux: handle O_NONBLOCK != SOCK_NONBLOCK case (Helge Deller)
* doc: fix spelling (Joey Geralnik)
* unix, windows: fix typos in comments (Joey Geralnik)
* test: canonicalize test runner path (Ben Noordhuis)
* test: fix compilation warnings (Saúl Ibarra Corretgé)
* test: skip tty test if detected width and height are 0 (Saúl Ibarra
Corretgé)
* doc: update README with IRC channel (Saúl Ibarra Corretgé)
* Revert "unix: use cfmakeraw() for setting raw TTY mode" (Ben
Noordhuis)
* doc: document how to get result of uv_fs_mkdtemp (Tim Caswell)
* unix: add flag for blocking SIGPROF during poll (Ben Noordhuis)
* unix, windows: add uv_loop_configure() function (Ben Noordhuis)
* win: keep a reference to AFD_POLL_INFO in cancel poll (Marc Schlaich)
* test: raise fd limit for OSX select test (Saúl Ibarra Corretgé)
* unix: remove overzealous assert in uv_read_stop (Saúl Ibarra Corretgé)
* unix: reset the reading flag when a stream gets EOF (Saúl Ibarra
Corretgé)
* unix: stop reading if an error is produced (Saúl Ibarra Corretgé)
* cleanup: remove all dead assignments (Maciej Małecki)
* linux: return early if we have no interfaces (Maciej Małecki)
* cleanup: remove a dead increment (Maciej Małecki)
Returns the platform specific file descriptor for handles that are
backed by one. The datatype is abstracted as uv_os_fd_t, which maps to
int on Unices and HANDLE on Windows.
Users can use this function to set specific socket options, for example,
in a non portable way.
This function is essentially a shotgun, you better be careful with
whatever you do with it, don't blame me if you used it to get the fd of
a stream, close it yourself and expect things to Just Work.
Support all possible types on Unix, and files, directories and links on
Windows. Some systems (hello SunOS!) don't have the d_type field on struct
dirent, so mark them as UV_DIRENT_UNKNOWN.
Introduce:
int uv_fs_readdir_next(uv_fs_t* req, uv_dirent_t* ent);
`uv_fs_readdir()` is not returning a file names list in `req->ptr`
anymore, the proper way to gather them is to call `uv_fs_readdir_next()`
in a callback.
This implements locking around the blocking call to ReadFile to get
around a Windows kernel bug where a blocking ReadFile operation on a
stream can deadlock the thread. This allows uv_read_stop to immediately
cancel a pending IO operation, and allows uv_pipe_getsockname to
"pause" any pending read (from libuv) while it retrieves the
sockname information.
If unsupported by the OS (pre-Vista), this reverts to the old
(e.g. deadlock-prone) behavior
Closes#1313
This is the libuv side of the fix for Node's cluster module on Windows.
https://github.com/joyent/node/issues/7691
Windows and Unix return certain socket errors (i.e. EADDRINUSE) at
different times: bind on Windows, and listen on Unix.
In an effort to hide this difference, libuv on Windows stores such
errors in the bind_error field of uv_tcp_t, to defer raising it at
listen time.
This worked fine except for the case in which a socket is shared in
a Node cluster and a bind error occurs.
A previous attempt to fix this (
d1e6be14603da36fe00e
) was flawed becaused in an attempt to relay the error at the JS level
it caused the master to start accepting connections.
With this new approach, libuv itself is relaying the bind errors,
providing for a uniform behavior of uv_tcp_listen.
This functionality is present in stream and uv_udp_t has a queue
as well so it makes sense for udp to have a send_write_size.
Since udp sends entire messages atomically, the send_queue_count field
lets the user determine how many messages are there left to send.
We add a function called uv_loop_size which returns the size of
the loop. It is an additional function which complements
`uv_handle_size` and` uv_req_size` in order to provide full FFI
support.
Signed-off-by: Fedor Indutny <fedor@indutny.com>
Add some basic doc comments to the uv_barrier_*() functions and document
the "serializer" return value from the previous commit.
Signed-off-by: Fedor Indutny <fedor@indutny.com>
Make uv_barrier_wait() return a boolean value indicating whether this
thread was the "serializer".
From `man pthread_barrier_wait`:
Upon successful completion, the pthread_barrier_wait() function
shall return PTHREAD_BARRIER_SERIAL_THREAD for a single (arbitrary)
thread synchronized at the barrier and zero for each of the other
threads.
Exposing that information from libuv is useful because it can make
cleanup significantly easier:
if (uv_barrier_wait(&barrier) > 0)
uv_barrier_destroy(&barrier);
Signed-off-by: Fedor Indutny <fedor@indutny.com>
The fields for UV_HANDLE_PRIVATE_FIELDS in uv-win.h and uv-unix.h are
the same, but in different order. Simply swap them so uv_handle_t are
the same on both platforms.
Signed-off-by: Fedor Indutny <fedor@indutny.com>
Changes since version 0.11.22:
* fs: avoid using readv/writev where possible (Fedor Indutny)
* mingw: fix build with autotools (Saúl Ibarra Corretgé)
* bsd: support IPv6 qualified link-local addresses (Saúl Ibarra Corretgé)
* unix: add UV_HANDLE_IPV6 flag to tcp and udp handles (Saúl Ibarra Corretgé)
* unix, windows: do not set SO_REUSEADDR by default on udp (Saúl Ibarra
Corretgé)
* windows: fix check in uv_tty_endgame() (Maks Naumov)
* unix, windows: add IPv6 support for uv_udp_multicast_interface (Saúl Ibarra
Corretgé)
* unix: fallback to blocking writes if reopening a tty fails (Saúl Ibarra
Corretgé)
* unix: fix handling uv__open_cloexec failure (Saúl Ibarra Corretgé)
* unix, windows: add IPv6 support to uv_udp_set_membership (Saúl Ibarra
Corretgé)
* unix, windows: removed unused status parameter (Saúl Ibarra Corretgé)
* android: add support of ifaddrs in android (Javier Hernández)
* build: fix SunOS and AIX build with autotools (Saúl Ibarra Corretgé)
* build: freebsd link with libelf if dtrace enabled (Saúl Ibarra Corretgé)
* stream: do not leak `alloc_cb` buffers on error (Fedor Indutny)
* unix: fix setting written size on uv_wd (Saúl Ibarra Corretgé)
Signed-off-by: Fedor Indutny <fedor@indutny.com>
Add UV_UDP_REUSEADDR flag instead, which can be passed to uv_udp_bind.
If the udp handle is unbound when uv_udp_set_memberhsip or
uv_udp_set_multicast_interface is called, the handle will be bound with
UV_UDP_REUSEADDR set.
Introduce `int uv_pipe_pending_count(uv_pipe_t*)` and
`uv_handle_type uv_pipe_pending_type(uv_pipe_t*)`. They should be
used in IPC pipe's read cb to accept incoming handles:
int count = uv_pipe_pending_count(pipe);
int i;
for (i = 0; i < count; i++) {
uv_handle_type type = uv_pipe_pending_type(pipe);
/* ... */
uv_accept(...);
}
Changes since version 0.11.20:
* unix: fix uv_fs_write when using an empty buffer (Saúl Ibarra
Corretgé)
* unix, windows: add assertion in uv_loop_delete (Saúl Ibarra Corretgé)
When the supplied buffer is not big enough and UV_ENOBUFS is
returned, hint the user about the required size by setting
the len paramemeter to the required value.
Applies to:
- uv_pipe_getsockname
- uv_fs_event_getpath
- uv_fs_poll_getpath
This improves API consistency with uv_read and uv_write and may
improve efficiency for some uses. Vectored IO is emulated when the
requisite system calls are unavailable.
These functions supersede uv_loop_new and uv_loop_delete.
uv_loop_init initialized a user allocated loop and uv_loop_close
removes all associated resources a loop uses after it has finished
execution.
uv_loop_new and uv_loop_delete are now deprecated.
Replace the red-black tree with a heap. The most common operation that
libuv performs on timers is looking up the first timer to expire. With
a red-black tree, that operation is O(log n). With a heap, it's O(1).
This improves API consistency with uv_read and uv_write and may
improve efficiency for some uses. Vectored IO is emulated when the
requisite system calls are unavailable.
Signals don't exist on Windows, but libuv emulates the behaviour of
several Unix signals. This wasn't documented, and the existing
documentation for signal reception emulation on Windows was worded as if
it applied to signal sending, which it does not.
Every file descriptor opened using libuv should be automatically marked
as CLOEXEC to prevent it from leaking to a child process. Note that
since we are opening fds in a thread pool, there is a possible race
condition between `uv_spawn()` and the `open()` + `uv__cloexec()`. The
rwlock was added to avoid it.
see https://github.com/joyent/node/issues/6905
If multiple handles arrive to the IPC pipe at the same time (happens on
some platforms), libuv will queue them internally, and call `read2_cb`
multiple times with a null-buffer and proper `handle_type`.
Useful to know when the the event loop is empty, this can't be done with
uv_run() without possibly blocking, or running some events (which might
empty the event loop as a side-effect).
`uv_try_write(stream, buf, size)` acts like `uv_write()`,
but without queueing actual write until UV_POLLOUT (or IOCP completion).
This is useful for doing writes using on-stack `uv_write_t` requests.
fix#1025
If spawning a process fails due to an exec() failure (but it succeeded
in forking), then this should be considered a spawn failure instead of
an asynchronous termination of the process. This allows to check for
common exec() failure conditions such as a bad path quickly instead of
having to rely on keeping track of the async callback.
Additionally, the meaning of the two fields returned in the callback are
now exactly what they advertise to be. The process exit argument is not
one of two values depending on what happened to the child.
Fixes#978.
Document the fact that the maximum path length for UNIX domain socket
paths is much less than _POSIX_PATH_MAX.
For most file systems, _POSIX_PATH_MAX is 1024 or 4096 bytes while
`sizeof(sockaddr_un.sun_path)` is typically between 92 and 108 bytes.
Make it possible to call uv_tty_reset_mode() from inside a signal
handler. The primary motivation is to make it possible to restore
the TTY from inside a SIGINT or SIGTERM signal handler.
Fixes#954.
Before this commit, multiple event loops raced with each other when a
SIGCHLD signal was received. More concretely, it was possible for
event loop A to consume waitpid() events that should have been
delivered to event loop B.
This commit addresses that by doing a linear scan over the list of
child processes. An O(n) scan is not terribly efficient but the
actual performance impact is not measurable in a benchmark that spawns
rounds of several thousands instances of /bin/false. For the time
being, this patch will suffice; we can always revisit it later.
Fixes#887.
This commit reverts the following commits:
983fa68 darwin: fix 10.6 build error in fsevents.c
684e212 fsevents: use shared FSEventStream
ea4cb77 fsevents: FSEvents is most likely not thread-safe
9bae606 darwin: create fsevents thread on demand
Several people have reported stability issues on OS X 10.8 and bus
errors on the 10.9 developer preview.
See also joyent/node#6296 and joyent/node#6251.
Seems to have been overlooked in the reference counting refactor back
in May 2012 in commit 9efa8b3. Clarify what "active" means for
different kinds of handles.
On BSD-like platforms, EADDRINUSE is returned by the bind() system call.
On other platforms, it's returned by the listen() system call.
In other words, some platforms are 'first to bind wins', others are
'first to listen wins' - but only with TCP sockets: UNIX domain sockets
always return EADDRINUSE from the bind() system call, UDP sockets don't
call listen() in the first place.
Fixes#769.
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.
Fixes#684.
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.
Fixes#684.
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.
Fixes#684.
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.
Fixes#684.
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.
Fixes#684.
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.
Fixes#684.
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.
Fixes#684.
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.
Fixes#684.
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.
Fixes#684.
Uses the pthread_key_{create,delete} and pthread_{get,set}specific
functions on UNIX platforms, Tls{Alloc,Free} and Tls{Get,Set}Value
on Windows.
Fixes#904.
Mention that:
* these functions set the SO_REUSEADDR and SO_REUSEPORT socket flags,
* what the effect of those flags is, and
* that we may remove it someday
This means we no longer have to strip the high bit from the process exit
code on Windows, which is problematic because an unhandled SEH exception
can make a process exit with a status code that has the high bit set.
It seems that number of simultaneously opened FSEventStreams is
limited on OSX (i.e. you can have only fixed number of them on
one running system), getting past through this limit will cause
`FSEventStreamCreate` to return false and write following message
to stderr:
(CarbonCore.framework) FSEventStreamStart: register_with_server:
ERROR: f2d_register_rpc() => (null) (-21)
To prevent this, we must use only one shared FSEventStream with a
paths for all uv_fsevent_t handles, and then filter out events for
each handle using this paths again.
See https://github.com/joyent/node/issues/5463
Conflicts:
include/uv-private/uv-darwin.h
src/unix/fsevents.c
It seems that number of simultaneously opened FSEventStreams is
limited on OSX (i.e. you can have only fixed number of them on
one running system), getting past through this limit will cause
`FSEventStreamCreate` to return false and write following message
to stderr:
(CarbonCore.framework) FSEventStreamStart: register_with_server:
ERROR: f2d_register_rpc() => (null) (-21)
To prevent this, we must use only one shared FSEventStream with a
paths for all uv_fsevent_t handles, and then filter out events for
each handle using this paths again.
See https://github.com/joyent/node/issues/5463
Change the uv_fs_write() prototype so the 'buf' argument is now
`const void*` rather than `void*`.
The argument is stored in a non-const field in the uv_fs_t but that's
inconsequential because the memory it points to is not touched.
Make it possible for the libuv user to handle out of memory conditions
gracefully. When alloc_cb() returns a buffer with len==0, call the read
or recv callback with nread=UV_ENOBUFS. It's up to the user to stop or
close the handle.
Fixes#752.
Before this commit, uv_fs_chown() and uv_fs_fchown() took the uid and
gid as signed integers which is wrong because uid_t and gid_t are
unsigned on most all platforms and IDs that don't fit in a signed
integer do exist.
This is not an ABI change because the size of the uid and gid arguments
do not change, only their sign.
On Windows, uv_uid_t and uv_gid_t are typedef'd as unsigned char for
reasons that are unclear. It doesn't matter: they get cast to ints when
used as function arguments. The arguments themselves are unused.
Partial fix for joyent/node#5890.
This commit changes the libuv API to return error codes directly rather
than storing them in a loop-global field.
A code snippet like this one:
if (uv_foo(loop) < 0) {
uv_err_t err = uv_last_error(loop);
fprintf(stderr, "%s\n", uv_strerror(err));
}
Should be rewritten like this:
int err = uv_foo(loop);
if (err < 0)
fprintf(stderr, "%s\n", uv_strerror(err));
The rationale for this change is that it should make creating bindings
for other languages a lot easier: dealing with struct return values is
painful with most FFIs and often downright buggy.
Switch to the build tool everyone loves to hate. The Makefile has
served us well over the years but it's been acquiring more and more
features that autotools gives us for free, like easy static+shared
library building, sane install targets, and so on.
This commit drops MinGW support. If there is demand for it, we'll
re-add it.
This patch adds the `uv_stream_set_blocking` API which makes all
uv_write calls to that stream blocking. It currently only works for
pipes, on windows.
Tested most of my compilation in the previous patch on NodeJS
and extracted the patches from there. This patch ensures libuv
will be capable of building standalone as well, both with gyp
and Makefiles.
Build documentation was added to the README.md file.
Some tests are failing, and I have not heavily investigated
the reasons. The failures are generally on errors, and are
likely related to differences between fully POSIX-compatible
systems and android.
We use GetQueuedCompletionStatus(Ex) to sleep the thread until the next
timer expires (provided that no other events happen before that).
However after waking up from a sleep the GetTickCount() return value may
not immediately reflect that some time has passed. This happens because
gqcs can sometimes sleep for periods shorter than the GetTickCount clock
resulution. This patch changes time tracking so the amount of time
waited by gqcs is taken into account.
This has the following advantages:
* Excessive loop iterations are avoided.
* Small timeouts are fired more precisely.
* The `loop-stop` test that used to be flaky on Windows now passes
consistently.
Include the netmask when returning information about the OS network
interfaces.
This commit provides implementations for windows and those unix
platforms using getifaddrs().
AIX was not implemented because it requires the use of ioctls and I do
not have an AIX development/test environment. The windows code was
developed using mingw on winxp as I do not have access to visual studio.
Tested on darwin (ipv4/ipv6) and winxp (ipv4 only). Needs testing on
newer windows using ipv6 and other unix platforms.
On Unix, uv_udp_open can be used with any socket as long as the socket
follows the datagram contract (works in unconnected mode, supports
sendmsg()/recvmsg(), etc.). This means that any datagram-socket, like
for example netlink or raw sockets, can be used with libuv. Added this
information to the documentation.
Fixes the following warning:
include/uv.h:236:30: warning: type qualifiers ignored on function
return type [-Wignored-qualifiers]
UV_EXTERN const unsigned int uv_version(void);
Generate the members of the uv_any_handle and uv_any_req unions with
the UV_HANDLE_TYPE_MAP and UV_REQ_TYPE_MAP macros. Eases maintenance
when new handle or request types are added.
Inverts the meaning of the 'enable' argument. Before, it actually set
the UV_TCP_SINGLE_ACCEPT flag when enable=1. Now it clears it, which is
what uv-win does and what you would expect it to do.
Make the statbuf field public. This means you no longer have to use
req->ptr - though that still works and will continue to work for the
foreseeable future.
Fixes#704.
This changes the prototype of uv_run() from:
int uv_run(uv_loop_t* loop);
To:
int uv_run(uv_loop_t* loop, uv_run_mode mode);
Where `mode` is UV_RUN_DEFAULT, UV_RUN_ONCE or UV_RUN_NOWAIT.
Fixes#683.
Allows for running the event loop in 3 modes:
* default: loop runs until the refcount drops to zero
* once: poll for events only once and block until one is handled
* nowait: poll for events only once but don't block if there are
no pending events
Bert Belder informs me the current approach where a request is immediately
cancelled, is impossible to implement on Windows.
Rework the API to always invoke the "done" callback with an UV_ECANCELED error
code.
kqueue(2) on osx doesn't work (emits EINVAL error) with specific fds
(i.e. /dev/tty, /dev/null, etc). When given such descriptors - start
select(2) watcher thread that will emit io events.
This can be used in conjuction with uv_run_once() to poll in one thread and run
the event loop's event callbacks in another.
Useful for embedding libuv's event loop in another event loop.