Commit Graph

473 Commits

Author SHA1 Message Date
Bartosz Sosnowski
b9a0840307
tty, win: fix read stop for raw mode
New Windows version requires `EventType` to be set to something
meaningful, otherwise WriteConsoleInputW() will fail with
`ERROR_INVALID_PARAMETER`. This sets it to `FOCUS_EVENT` which
is ignored by `uv_process_tty_read_raw_req()`.

Fixes: https://github.com/nodejs/node/issues/21773
PR-URL: https://github.com/libuv/libuv/pull/1989
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2018-09-26 13:46:25 -04:00
cjihrig
e57e07172e
unix,win: add uv_os_{get,set}priority()
Refs: https://github.com/nodejs/node/pull/21675
PR-URL: https://github.com/libuv/libuv/pull/1945
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
2018-08-15 09:17:55 -04:00
John Barboza
27e7a8b107
unix: loop starvation on successful write complete
A file descriptor that can do multiple successful write completion
requests in a row will starve the loop because it will keep feeding
the write_completed_queue. This fix will only process items on the
write_completed_queue once per event loop (in uv__run_pending).
Any new items on the queue will be processed in the next loop.

PR-URL: https://github.com/libuv/libuv/pull/1787
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-08-11 18:24:38 -04:00
Bartosz Sosnowski
8f96a5b07b fs: add uv_open_osfhandle
Adds uv_open_osfhandle to complete uv_get_osfhandle

Ref: https://github.com/nodejs/node/issues/15433
Ref: https://github.com/nodejs/node-addon-api/issues/304
PR-URL: https://github.com/libuv/libuv/pull/1927
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2018-08-09 11:19:15 +02:00
Jamie Davis
f401e67b60
test: make test-condvar call uv_cond_wait
Problem:
The condvar tests could pass without uv_cond_wait
(or uv_cond_timedwait) ever being invoked.

Solution:
Introduce semaphores to enforce ordering.
Now there will always be a thread waiting on the condition
when a signal() occurs.

Gotchas:
1. On Windows, waiting for a timeout may return earlier
than requested, depending on the granularity of timer ticks.
2. Timeout bounds are tuned based on our CI machines.

Bonuses:
1. I added additional test cases to complete the test matrix.

2. It seemed to me that several of the condvar tests were redundant,
because they used timing to probabilistically explore cases where there
would be "missed connections" (signal without a waiter).
Because it was not clear to me what the purpose of such tests were,
I have removed them.

Fixes: https://github.com/libuv/libuv/issues/1714
PR-URL: https://github.com/libuv/libuv/pull/1718
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2018-07-06 23:02:46 +02:00
cjihrig
06fdc2bd0e
src,test: s/olny/only
PR-URL: https://github.com/libuv/libuv/pull/1848
Reviewed-By: Bert Belder <bertbelder@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2018-05-30 13:29:15 -07:00
Ben Noordhuis
585dc821f3 test: use custom timeout for getaddrinfo_fail_sync
We don't control the running time of the test and as a result it
frequently times out on some of the CI buildbots.

We are already using a custom timeout for getaddrinfo_fail so it only
makes sense to do the same for its synchronous counterpart.

PR-URL: https://github.com/libuv/libuv/pull/1856
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2018-05-30 14:41:23 +02:00
Bert Belder
421d7571a3
test: add test for IPC deadlock on Windows (#1099)
PR-URL: https://github.com/libuv/libuv/pull/1843
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2018-05-29 13:01:59 -07:00
Bert Belder
b36c0945d1
test: add vectored uv_write() ping-pong tests
PR-URL: https://github.com/libuv/libuv/pull/1843
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2018-05-29 13:01:23 -07:00
Bartosz Sosnowski
b59fc58326 win, fs: uv_fs_fchmod support for -A files
Adds uv_fs_chmod support for files with the Archive attribute cleared

Ref: https://github.com/libuv/libuv/pull/1777
Ref: https://github.com/nodejs/node/issues/12803
PR-URL: https://github.com/libuv/libuv/pull/1819
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-05-17 09:27:09 +02:00
Bartosz Sosnowski
edf05b97f0 win, fs: fix uv_fs_unlink for +R -A files
uv_fs_unlink would fail for read-only files with Archive attribute
cleared. This fixes this issue.

PR-URL: https://github.com/libuv/libuv/pull/1774
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2018-03-21 14:03:00 +01:00
Nikolai Vavilov
7e865b680a win: use long directory name for handle->dirw
`uv_relative_path` assumes `dir` is a prefix of `filename`, which is not
the case when `handle->dirw` is a short path.

Refs: https://github.com/nodejs/node/issues/19170
PR-URL: https://github.com/libuv/libuv/pull/1769
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
2018-03-19 10:20:56 +01:00
Jameson Nash
8f9ba2a597
Revert "Revert "unix,tcp: avoid marking server sockets connected""
This reverts commit 2098773243.

PR-URL: https://github.com/libuv/libuv/pull/1741
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2018-02-25 18:45:05 +01:00
Jamie Davis
693c217f80 test: check uv_cond_timedwait more carefully
Problem:
The "timeout" functionality of uv_cond_timedwait was not being tested.
The test (condvar_3) would use a worker that signaled the condition.

Solution:
Introduce a new condvar test case to ensure that the timeout also works.

PR-URL: https://github.com/libuv/libuv/pull/1713
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: John Barboza <jbarboza@ca.ibm.com>
2018-02-01 23:26:08 +01:00
Ben Noordhuis
b0f3310bb1 Revert "unix,fs: fix for potential partial reads/writes"
This commit has been reported as introducing a backwards-incompatible
change in reading from stdin and is independently suspected of breaking
the Node.js test suite on MacOS and maybe other platforms, possibly in
combination with commit fd049399 ("unix,tcp: avoid marking server
sockets connected".)

This reverts commit 14bfc27e64.

Fixes: https://github.com/libuv/libuv/issues/1716
Fixes: https://github.com/libuv/libuv/issues/1720
Fixes: https://github.com/nodejs/node/issues/18225
PR-URL: https://github.com/libuv/libuv/pull/1717
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2018-01-19 17:51:08 +01:00
Ben Noordhuis
2098773243 Revert "unix,tcp: avoid marking server sockets connected"
Reverted for breaking Node.js in rather spectacular fashion.

The bug is arguably on the Node.js side.  It looks like Node.js starts
reading before the socket is actually connected to something.
Until that is fixed downstream, let's revert the change.

This reverts commit fd049399aa.

Fixes: https://github.com/libuv/libuv/issues/1716
Fixes: https://github.com/nodejs/node/issues/18225
PR-URL: https://github.com/libuv/libuv/pull/1717
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2018-01-19 17:51:04 +01:00
Bert Belder
dcd9b3cb27 win: allow directory symlinks to be created in a non-elevated context
PR-URL: https://github.com/libuv/libuv/pull/1706
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-01-16 09:52:15 -08:00
Ben Wijen
14bfc27e64
unix,fs: fix for potential partial reads/writes
Added a check in uv__fs_buf_iter to detect partial reads and writes.
Partial reads and writes are looped until all data has been processed.

PR-URL: https://github.com/libuv/libuv/pull/640
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2018-01-10 17:14:53 +01:00
Ben Noordhuis
6ecd79eb6e test: remove custom timeout for thread test on ppc
The two minute timeout should not be necessary anymore after commit
aeaff5f0 ("test: lower number of tasks in threadpool test".)

PR-URL: https://github.com/libuv/libuv/pull/1681
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2018-01-09 14:28:56 +01:00
Bartosz Sosnowski
2b32e77bb6 win: map 0.0.0.0 and :: addresses to localhost
On Linux when connecting IP addresses 0.0.0.0 and :: are automatically
converted to localhost. This adds same functionality to Windows.

PR-URL: https://github.com/libuv/libuv/pull/1515
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-12-28 10:42:11 +01:00
Jameson Nash
fd049399aa
unix,tcp: avoid marking server sockets connected
It shouldn't be setting READABLE and WRITABLE on the socket server,
since they aren't, and this could confuse the client.

PR-URL: https://github.com/libuv/libuv/pull/1655
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-12-20 22:17:52 +01:00
Bartosz Sosnowski
890eedaf59 win, process: uv_kill improvements
Maps pid 0 to the current process, simulating Linux kill sending signal
to the process group.

Adds detection of invalid signals. If the signum is invalid - below 0
or NSIG or above – UV_EINVAL will be returned instead of UV_ENOSYS.

PR-URL: https://github.com/libuv/libuv/pull/1642
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-12-07 14:00:05 +01:00
Bartosz Sosnowski
c73e73c874 test: add threadpool init/teardown test
Verify that quick setup and teardown of the threadpool doesn't cause
crashes or hangs.

PR-URL: https://github.com/libuv/libuv/pull/1639
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-12-06 23:47:38 +01:00
Matt Harrison
8a6d1b32c5 unix: make get(set)_process_title MT-safe
Used a shared uv_mutex_t in unix implementations of these functions
to prevent simultaneous execution.

Fixes: https://github.com/libuv/libuv/issues/271
PR-URL: https://github.com/libuv/libuv/pull/1640
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-12-02 12:06:34 +01:00
Anna Henningsen
0d6525acae core: add getter/setter functions for easier ABI compat
Add getter/setter functions for the fields of public structs that
might be relevant to e.g. Node.js addons.

Through these methods, ABI compatibility for a subset of the ABI
is easier to achieve, since using them makes code independent
of the exact offsets of these fields.

The intended use case that prompted this are N-API addons for
Node.js, which look for more long-term ABI compatibility guarantees
than typical Node code. With these helper functions, using libuv
directly should no longer be an obstacle for such addons.

PR-URL: https://github.com/libuv/libuv/pull/1657
Refs: https://github.com/nodejs/node/issues/13512
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-12-02 09:51:25 +01:00
Ben Noordhuis
49616e4e17 Revert "unix,win: wait for threads to start"
Reverted for suspected regressions in the Node.js test suite on Windows.

Also revert e99ac4c1f4 ("test: add threadpool init/teardown test") since
it depends on 5486f6bd51.

This reverts commit 5486f6bd51.
This reverts commit e99ac4c1f4.

PR-URL: https://github.com/libuv/libuv/pull/1656
Refs: https://github.com/libuv/libuv/pull/1639
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-11-30 02:24:22 +01:00
Bartosz Sosnowski
e99ac4c1f4 test: add threadpool init/teardown test
Verify that quick setup and teardown of the threadpool doesn't cause
crashes or hangs.

PR-URL: https://github.com/libuv/libuv/pull/1639
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-11-20 20:35:23 +01:00
John Barboza
c5dd2d4218
unix: keep track of bound sockets sent via spawn
We use the UV_HANDLE_BOUND flag to mark a socket as bound to a
port. We need to do this for sockets that are sent from another
process as well as sockets that created by the process itself.
First check if the port number is non-zero. If yes then mark
it as bound.

PR-URL: https://github.com/libuv/libuv/pull/1348
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-11-20 18:36:26 +01:00
Joran Dirk Greef
1c4de1916e win: map UV_FS_O_EXLOCK to a share mode of 0
This is necessary to enable writing past the MBR of a raw block device.

Fixes: https://github.com/libuv/libuv/issues/1605
PR-URL: https://github.com/libuv/libuv/pull/1613
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
2017-11-16 15:14:52 +01:00
Bartosz Sosnowski
fd02ab681b pipe: allow access from other users
Adds new uv_pipe_chmod function which can be used to make the pipe
writable or readable by all users.

PR-URL: https://github.com/libuv/libuv/pull/1386
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-11-06 15:45:00 +01:00
John Barboza
f2214561f3
zos: skip fork_threadpool_queue_work_simple
z/OS does not allow a child process to create threads if it was
forked from a multi-threaded parent.

PR-URL: https://github.com/libuv/libuv/pull/1596
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-10-17 22:34:07 +02:00
Wade Brainerd
1d9c13f1f7 win, fs: fix non-symlink reparse points
Fixes uv_fs_stat and uv_fs_lstat returning EINVAL when invoked on a
non-symlink reparse point.

1. Only tries to read symlinks when invoked via lstat (do_lstat == 1).

Rationale is that only lstat can set S_IFLNK because when a file is
tested by stat, symlinks are resolved by the OS and the returned file
must be real. Note that broken symlinks fail at CreateFile.

FILE_ATTRIBUTE_REPARSE_POINT is used by filesystem drivers for purposes
besides symlinks, and uv_fs_stat fails when invoked on these files
because fs__readlink_handle returns ERROR_SYMLINK_NOT_SUPPORTED. By
ignoring the attribute in uv_fs_stat, these files are now handled
correctly.

2. Modifies the logic added to fs__stat_handle to fix #995 as follows:

A failed fs__readlink_handle on a file with a reparse point indicates
that the file is not a symlink. The fix for #995 added code to fall
through and behave as with a normal file in this case. However, this is
not correct because lstat had opened the file with
FILE_FLAG_OPEN_REPARSE_POINT, preventing the filesystem from acting
based on the reparse point contents.

The fix makes fs__stat_handle fail back to the higher level
fs__stat_impl, which sets do_lstat to 0 and re-opens the file without
FILE_FLAG_OPEN_REPARSE_POINT, allowing normal filesystem processing to
take place.

This is also a slightly cleaner solution as symlink fallback is only
handled in one place (fs__stat_impl) instead of two (fs__stat_impl and
fs__stat_handle).

Note that the error tested in the fix for #995,
ERROR_NOT_A_REPARSE_POINT, is not actually returned by Windows in the
case of a non-symlink reparse point. I attempted to reproduce the error
by repeating the test steps in the issue but failed. However, the the
fix logic is preserved out of caution.

3. Adds tests to fs-test.c for the above two changes.

Thorough testing requires some non-trivial setup - like an OSX computer
on the LAN or a custom filesystem driver - so these tests are left
commented out for manual invocation.

PR-URL: https://github.com/libuv/libuv/pull/1522
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
2017-10-03 16:36:32 +02:00
Scott Parker
ec96b55438
unix,win: add uv_mutex_init_recursive()
Support the creation of recursive mutexes on Unix. A matching
API is added on Windows, however mutexes on Windows are always
recursive.

Refs: https://github.com/libuv/libuv/issues/1022
PR-URL: https://github.com/libuv/libuv/pull/1555
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-10-02 10:01:09 -04:00
cjihrig
e539fc412f
unix,windows: return UV_EINVAL on NULL fs reqs
This commit introduces an INIT macro to file system functions on
Windows, similar to the one used on Unix platforms. The macro
checks for NULL requests, and returns UV_EINVAL in such
scenarios. This commit also adds support for passing NULL to
uv_fs_req_cleanup(). In this scenario, the function is a
no-op.

Fixes: https://github.com/libuv/libuv/issues/1508
PR-URL: https://github.com/libuv/libuv/pull/1509
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-09-02 19:04:01 -04:00
cjihrig
766d7e9c0b
unix, windows: add basic uv_fs_copyfile()
Fixes: https://github.com/libuv/libuv/issues/925
PR-URL: https://github.com/libuv/libuv/pull/1465
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-08-15 10:43:49 -04:00
Maciej Szeptuch (Neverous)
6827fa3451 win: allow bound/connected socket in uv_tcp_open()
On Unix you can pass bound and even connected socket to uv_tcp_open
and it will work as expected: you can run uv_listen or other io
functions (uv_read, uv_write) on it without problems.
On windows on the other hand the function always assumes to have clean
socket and for example uv_listen will try to bind it again, and
uv_read/write will return with errors about unreadable streams
(basically invalid internal flags).

To check if socket is already bound uv_tcp_getsockname is called which
on windows returns error when socket is unbound. To further
differentiate connected one from just bound, uv_tcp_getpeername also
returns error but when target socket is not connected.

PR-URL: https://github.com/libuv/libuv/pull/1447
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-08-08 17:19:20 +02:00
Bartosz Sosnowski
cbcf13af6a win, process: support semicolons in PATH variable
Fixes a bug that would cause libuv to crash when PATH environment
variable contained paths with semicolon in it

Refs: https://github.com/nodejs/help/issues/728
Fixes: https://github.com/libuv/libuv/issues/1422
PR-URL: https://github.com/libuv/libuv/pull/1438
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-07-27 12:34:31 +02:00
CurlyMoo
d731fd1bd9 poll: add support for OOB TCP and GPIO interrupts
Out-of-band TCP messages are used for TCP data
transmission outside (outband) the inbound TCP
data. These packets are sent with an
"urgent pointer", but previously discarded.

Additionally, when using (e)poll a POLLPRI is
triggered when an interrupt signal is received
on GPIO capable systems such as the Raspberry Pi.

PR-URL: https://github.com/libuv/libuv/pull/1040
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-07-12 23:04:34 +02:00
Santiago Gimeno
404ee42706
unix,stream: return error on closed handle passing
Return `EBADF` when trying to send a handle which, while enqueued, was
closed.

Fixes: https://github.com/libuv/libuv/issues/806
PR-URL: https://github.com/libuv/libuv/pull/1352
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-06-23 09:38:15 +02:00
Bartosz Sosnowski
0bd8f5bf36 win: restore file pos after positional read/write
File read or write from specified position will move file pointer on
Windows but not on POSIX. This makes Windows behave as other
supported platforms.

Ref: https://github.com/nodejs/node/issues/9671

PR-URL: https://github.com/libuv/libuv/pull/1357
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-06-21 12:47:00 +02:00
Juan Cruz Viotti
e133923e93 win: make uv__get_osfhandle() public
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>
2017-05-30 11:53:31 -04:00
John Barboza
573e7fe8fc
zos: increase timeout for tcp_writealot
A small timeout resulted in flaky behaviour on the z/OS test
machine.

PR-URL: https://github.com/libuv/libuv/pull/1353
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-19 12:05:29 +02:00
cjihrig
d8cd08bd98 unix,win: add uv_os_gethostname()
Fixes: https://github.com/libuv/libuv/issues/1315
PR-URL: https://github.com/libuv/libuv/pull/1342
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
2017-05-18 10:27:47 -04:00
Trevor Norris
d898a1f6f8 test: add test for uv_udp_send() fix
Test that the fast path will continue writing. On failure, this test
will timeout.

PR-URL: https://github.com/libuv/libuv/pull/1308
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-04-20 18:10:43 -04:00
cjihrig
463800ffc1 win,sunos: stop handle on uv_fs_event_start() err
This commit stops the handle in uv_fs_event_start() when an
error occurs.

Fixes: https://github.com/libuv/libuv/issues/1253
PR-URL: https://github.com/libuv/libuv/pull/1257
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-03-21 10:35:53 -04:00
Jason Madden
fd7ce57f2b unix: make loops and watchers usable after fork()
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>
2017-03-21 12:23:44 +01:00
cjihrig
ee02f60c90 unix,win: add uv_os_{get,set,unset}env()
These functions are used to create, retrieve, update, and delete
environment variables.

Fixes: https://github.com/libuv/libuv/issues/1198
PR-URL: https://github.com/libuv/libuv/pull/1234
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-03-08 20:39:33 -05:00
Santiago Gimeno
45616f542d
signal: add uv_signal_start_oneshot method
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>
2017-02-28 14:16:54 +01:00
Bartosz Sosnowski
c66f265b5d win,signal: fix potential deadlock
Trying to remove the controller from the controller handle itself
leads to deadlock. Fix it by always having the global signal handler
engaged.

Ref: https://github.com/nodejs/node/issues/10165
PR-URL: https://github.com/libuv/libuv/pull/1168
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-01-17 21:22:56 -06:00
muflub
c8ab24bb92 fs: fix crash in uv_fs_scandir_next
Handle the case when it's called after the request has ended, or in case
it ended with an error.

PR-URL: https://github.com/libuv/libuv/pull/1181
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-01-17 21:15:43 -06:00
Santiago Gimeno
c2f0e4f64e
win,tty: fix MultiByteToWideChar output buffer
Make sure there's enough room in the output buffer by dynamically
allocating memory in case the size of the buffer needs to be greater
than 8192 characters.

PR-URL: https://github.com/libuv/libuv/pull/1143
Refs: https://github.com/libuv/libuv/pull/1138
Refs: https://github.com/libuv/libuv/pull/889
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Imran Iqbal <imran@imraniqbal.org>
2016-11-29 10:36:44 +01:00
Santiago Gimeno
445e3a1f06
Revert "Revert "win,tty: add support for ANSI codes in win10 v1511""
To bring back support for ANSI codes in win10 v1511.

This reverts commit 8cbabaa817.

PR-URL: https://github.com/libuv/libuv/pull/1143
Refs: https://github.com/libuv/libuv/pull/1138
Refs: https://github.com/libuv/libuv/pull/889
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Imran Iqbal <imran@imraniqbal.org>
2016-11-29 10:35:59 +01:00
Ben Noordhuis
8cbabaa817 Revert "win,tty: add support for ANSI codes in win10 v1511"
Causes regressions on Windows 10 in applications that use ANSI codes.

Also reverts commit 0895ccf ("win: fix typo in type name") and
commit d0c2641 ("win, tty: handle empty buffer in uv_tty_write_bufs".)

This reverts commit d0c26414b4.
This reverts commit 0895ccfc8c.
This reverts commit 58ccfd4c21.

PR-URL: https://github.com/libuv/libuv/pull/1138
Refs: https://github.com/libuv/libuv/issues/1135
Refs: https://github.com/libuv/libuv/pull/889
Refs: https://github.com/nodejs/node/issues/9542
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Imran Iqbal <imran@imraniqbal.org>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2016-11-15 16:52:42 +01:00
Hitesh Kanwathirtha
d0c26414b4 win, tty: handle empty buffer in uv_tty_write_bufs
In uv_tty_write_bufs, if the console supports Virtual Terminal sequences,
we try to convert the passed in utf8 buffer to utf16. However, we need
to check if the buffer is of non-zero length- otherwise,
MultiByteToWideChar returns an error.

Fixes: https://github.com/libuv/libuv/issues/1135
Fixes: https://github.com/nodejs/node/issues/9542
PR-URL: https://github.com/libuv/libuv/pull/1139
Refs: https://github.com/libuv/libuv/pull/889
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Imran Iqbal <imran@imraniqbal.org>
2016-11-15 09:54:25 +01:00
Philippe Laferriere
f1863dae6b unix,win: add uv_translate_sys_error() public API
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>
2016-10-16 17:47:42 -04:00
Saúl Ibarra Corretgé
d796bedf5b unix,win: make on_alloc_cb failures more resilient
Treat both the base being NULL or the length being 0 as ENOBUFS.

PR-URL: https://github.com/libuv/libuv/pull/997
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-08-17 09:57:55 +02:00
cjihrig
77c8abae33 win: compare entire filename in watch events
This commit causes Window file watching events to compare the
entire file path when filtering events. This fixes a bug where
incomplete path comparisons would cause invalid events to be
raised.

Refs: https://github.com/libuv/libuv/pull/682
PR-URL: https://github.com/libuv/libuv/pull/924
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-06-24 10:36:04 -04:00
Kári Tristan Helgason
89f01a41ab test: silence build warnings
PR-URL: https://github.com/libuv/libuv/pull/893
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-06-03 01:18:17 +02:00
Ben Noordhuis
c5c419f7c8 unix: allow nesting of kqueue fds in uv_poll_start
kqueue file descriptors don't support ioctl(FIONBIO) (or any other ioctl
for that matter) so retry using fcntl(F_GETFL) + fcntl(F_SETFL) when we
receive a ENOTTY error.

Fixes: https://github.com/libuv/libuv/issues/883
PR-URL: https://github.com/libuv/libuv/pull/885
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-05-24 17:12:31 +02:00
João Reis
e51442bbc9 win,tty: fix read stop in line mode
Closing the handle does not make ReadConsoleW exit reliably on
Windows 7 and above. Thus, after switching from line to raw mode,
keypresses were held until enter was pressed. This makes ReadConsoleW
exit by writing a return keypress to its input buffer, similar to
what was already done for raw mode.

Fixes: https://github.com/libuv/libuv/issues/852
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>
2016-05-16 23:05:35 +02:00
Enno Boland
387102b247 unix: open ttyname instead of /dev/tty
Find the real name of the tty using ttyname_r(3) instead of
opening "/dev/tty" which causes trouble if the fd doesn't point to the
controlling terminal.

PR-URL: https://github.com/libuv/libuv/pull/779
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-04-01 11:13:22 +02:00
cjihrig
217f81b6a1 unix,win: add uv_get_passwd()
This commit adds the uv_get_passwd() function, which returns a
subset of the current effective user's password file entry.

Refs: https://github.com/libuv/libuv/issues/11
Fixes: https://github.com/libuv/libuv/issues/731
PR-URL: https://github.com/libuv/libuv/pull/742
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-03-29 08:13:59 -04:00
Imran Iqbal
b015b4d0ee test: fix threadpool_multiple_event_loops on PPC
On PPC (linux and AIX) uv_thread_join (which is just a call to
pthread_join) takes quite a while. Increased the timeout of this
specific test on PPC so that there is ample time for all threads to join
back. The fs_do and getaddrinfo_do calls do not take up much time.

Also removing the ifdef for AIX around fs_do since it did nothing.

Fixes: https://github.com/libuv/libuv/issues/687
PR-URL: https://github.com/libuv/libuv/pull/737
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-02-27 18:06:17 +01:00
Nikolai Vavilov
3c59ad6d95 win: fix watching root files
When passing "\\?\C:" to CreateFile, it opens the drive rather than the root
directory. So include the trailing backslash in the directory name.

Fixes: https://github.com/nodejs/node/issues/4643
PR-URL: https://github.com/libuv/libuv/pull/689
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-01-26 09:58:49 +01:00
Ben Noordhuis
a0b56059cf unix: report errors for unpollable fds
Libuv would abort() when trying to watch a file descriptor that is
not compatible with epoll-style polling; file descriptors referring
to on-disk files fall into this category.

File descriptors that libuv creates itself are not an issue but
external ones that come in through the uv_poll_init() API are.

Make uv_poll_init() check whether the file descriptor is accepted by
the underlying system call and return an error when it's not.

Fixes: https://github.com/libuv/libuv/issues/658
PR-URL: https://github.com/libuv/libuv/pull/659
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-01-21 17:57:00 +01:00
cjihrig
c0fa2e7518 unix,win: add uv_os_tmpdir()
PR-URL: https://github.com/libuv/libuv/pull/672
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-01-21 09:11:56 +01:00
Saúl Ibarra Corretgé
3db07cc379 osx: set the default thread stack size to RLIMIT_STACK
Fixes: https://github.com/libuv/libuv/issues/669
PR-URL: https://github.com/libuv/libuv/pull/671
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-01-05 09:06:15 +01:00
Dave
a564ef09dc fs: don't nullify req->bufs on EINTR
uv__fs_buf_iter currently sets req->bufs to NULL after it is done, but
if the operation fails with EINTR then it will be retried, at which
point it expects the bufs to not be NULL, causing a seg fault as in
https://github.com/nodejs/node/issues/4291.

uv__fs_buf_iter should not set req->bufs to NULL if the operation
fails with EINTR.

Also, when it sets req->bufs to NULL, it should set req->nbufs to 0 as
well, so we don't have the messy situation of a positive nbufs with no
actual bufs.

PR-URL: https://github.com/libuv/libuv/pull/661
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2016-01-04 14:07:50 -05:00
João Reis
427e4c9d48 win: wait for full timeout duration
uv_poll should wait for at least the full timeout duration when there
is nothing else to do. This was not happening because
GetQueuedCompletionStatus can occasionally return up to 15ms early.

The added test reproduces d13d7f74d7/test/simple/test-timers-first-fire.js
on libuv, being flaky before this fix.

Fixes: https://github.com/joyent/node/issues/8960
PR-URL: https://github.com/libuv/libuv/pull/385
Reviewed-By: Alexis Campailla <alexis@janeasystems.com>
Reviewed-by: Bert Belder <bertbelder@gmail.com>
2015-12-16 12:08:46 +01:00
Andrey Mazo
6060841edc test: test that uv_close() doesn't corrupt QUEUE
The test adds all types of handles, that were known to be affected by
QUEUE_REMOVE()-within-QUEUE_FOREACH() bug, to a loop.
It then calls uv_close() to trigger QUEUE_REMOVE()-within-QUEUE_FOREACH() case
and checks whether a particular QUEUE is corrupted or not.

Restrict the test to Linux only for now as it fails on other platforms
for various reasons.

PR-URL: https://github.com/libuv/libuv/pull/621
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-12-08 10:02:25 +01:00
Yuval Brik
e76b8838e5 fs: add uv_fs_realpath()
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>
2015-12-05 11:32:58 +01:00
Louis DeJardin
dfdecf0006 pipe: enable inprocess uv_write2 on Windows
When duplicating the socket handle being sent the target process
id is defaulted to the current process id. This enables uv_write2
to be used for thread-clustering in addition to process-clustering on
multi-threaded programming languages.

The ipc tests are updated to run in two modes. In the _inproc mode
the echo work is done on a second thread instead of in a second
process.

An internal function int uv_current_pid() is added to the windows
specific code which caches the value of GetCurrentProcessId(). This
means uv_write2 does not call GetCurrentProcessId() every inprocess
send.

Refs: https://github.com/joyent/libuv/issues/926
PR-URL: https://github.com/libuv/libuv/pull/540
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-11-06 09:33:15 +01:00
Bert Belder
1ad6ad7ada test: add tests for the uv_rwlock implementation
PR-URL: https://github.com/libuv/libuv/pull/525
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-09-22 11:17:49 -04:00
Saúl Ibarra Corretgé
4f4e956497 win: fix setting pipe pending instances after bind
It's an error to do so, so just ignore it. The test would cause an
invalid memory access if the fix is undone.

PR-URL: https://github.com/libuv/libuv/pull/488
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-08-24 23:20:35 +02:00
Saúl Ibarra Corretgé
34768a76f5 win: fix replacing pipe handle for pipe servers
On Windows we create multiple pipe handles (system handles) which are
attached to pending accept requests. Each of these will take turns in
replacing the reference in handle->handle, so make sure we allow for
that **only** for pipe servers.

PR-URL: https://github.com/libuv/libuv/pull/488
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-08-24 23:20:35 +02:00
Karl Skomski
939ea06f45 unix,win: return EINVAL on nullptr args in uv_fs_{read,write}
PR-URL: https://github.com/libuv/libuv/pull/470
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-08-11 13:35:54 +02:00
Saúl Ibarra Corretgé
01544d861b Revert "stream: squelch ECONNRESET error if already closed"
This reverts commit 05a003a3f7.

This commit triggerd "test-tls-hello-parser-failure" failure in io.js.
See the reference below for a more thorough explanation.

Refs: https://github.com/nodejs/io.js/pull/2310
PR-URL: https://github.com/libuv/libuv/pull/475
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-08-07 14:19:08 +02:00
ronkorving
2bf782777f unix: allow nbufs > IOV_MAX in uv_fs_{read,write}
This allows writing and reading any amount of buffers,
regardless of what IOV_MAX may be defined as.

It also moves the IOV_MAX test from stream to core.

This is based on the excellent work of @bwijen in #269.

Refs: https://github.com/libuv/libuv/pull/269
PR-URL: https://github.com/libuv/libuv/pull/448
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-08-04 11:31:04 +02:00
Saúl Ibarra Corretgé
01bbf6fb1c win,test: fix shared library build
Ifdef out the tests that rely on internal symbols when making a shared build.

PR-URL: https://github.com/libuv/libuv/pull/444
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-07-21 23:38:17 +02:00
Santiago Gimeno
05a003a3f7 stream: squelch ECONNRESET error if already closed
Add new UV__POLLRDHUP event to be emitted when EPOLLRDHUP(in Linux) or
EV_EOF(in BSD / OSX) is detected and only if UV_READABLE is set.

When a read returns ECONNRESET after a UV__POLLRDHUP event, emit EOF instead
of the error.

Add tcp-squelch-connreset test. Not to be run on Windows as it returns
ECONNRESET error.

Fixes in test-poll and test-tcp-open so they pass after these changes.

PR-URL: https://github.com/libuv/libuv/pull/403
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-07-10 09:25:01 +02:00
Saúl Ibarra Corretgé
188e0e94ac win: add support for recursive file watching
Original patch by @ghostoy, modified by @bpasero and yours truly.

Refs: https://github.com/joyent/libuv/pull/1473
Refs: https://github.com/libuv/libuv/pull/198
PR-URL: https://github.com/libuv/libuv/pull/421
Reviewed-By: Bert Belder <bertbelder@gmail.com>
2015-07-08 23:40:47 +02:00
A. Hauptmann
15e4dedace win: remove UV_HANDLE_CONNECTED
UV_HANDLE_CONNECTED was defined, but never used anywhere - outside this if
condition inside uv__stdio_create. So this test can't be true.
UV_HANDLE_CONNECTION was meant.

A test was also added verifying the behaviour.

PR-URL: https://github.com/libuv/libuv/pull/404
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-07-07 09:45:48 +02:00
Saúl Ibarra Corretgé
f8f59824c4 unix, win: add ability to create tcp/udp sockets early
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>
2015-06-19 09:37:19 +02:00
Saúl Ibarra Corretgé
fb5df542ac unix, win: prevent replacing fd in uv_{udp,tcp,pipe}_t
PR-URL: https://github.com/libuv/libuv/pull/400
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-06-19 09:36:41 +02:00
cjihrig
a62c2d5928 unix,win: add uv_os_homedir()
PR-URL: https://github.com/libuv/libuv/pull/350
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-05-21 17:31:35 +02:00
Saúl Ibarra Corretgé
a6fa3ca99a unix: don't block for io if any io handle is primed
PR-URL: https://github.com/libuv/libuv/pull/347
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-05-12 07:37:26 +02:00
Saúl Ibarra Corretgé
e6e8124b95 test: add test for deferred TCP write failure
The test exhibits that write failures are deferred to the callback.

Refs: https://github.com/libuv/libuv/issues/339
PR_URL: https://github.com/libuv/libuv/pull/344
2015-05-05 23:25:49 +02:00
João Reis
0db81a98ff win: fix unlink of readonly files
Unix unlinks files even if they are not writable, windows version should behave similarly.

Fixes: https://github.com/joyent/node/issues/3006
PR-URL: https://github.com/libuv/libuv/pull/327
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-05-01 01:18:57 +02:00
Saúl Ibarra Corretgé
009bbad4e7 unix: fix swapping fds order in uv_spawn
Alternative implementation (and test) to
https://github.com/libuv/libuv/pull/226

Fixes: https://github.com/joyent/libuv/issues/1084
PR-URL: https://github.com/libuv/libuv/pull/309
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-04-10 15:27:04 +02:00
Saúl Ibarra Corretgé
edcf04d5b1 test: spawn child replacing std{out,err} to stderr
Refs: https://github.com/libuv/libuv/pull/224

PR-URL: https://github.com/libuv/libuv/pull/309
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-04-10 15:11:14 +02:00
Ryan Phillips
3616e61439 unix: reap child on execvp() failure
Reap the forked process when execvp() fails.  Fixes leaking zombie child
processes.

PR-URL: https://github.com/libuv/libuv/pull/274
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-03-18 17:11:39 +01:00
Ben Noordhuis
fc9e66e555 unix: reject non-tty fds in uv_tty_init()
Reject file descriptors that correspond to regular files or char/block
devices.  Such file descriptors are incompatible with epoll and trigger
a run-time assert.

Fixes: https://github.com/libuv/libuv/issues/255
PR-URL: https://github.com/libuv/libuv/pull/259
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-03-11 16:45:51 +01:00
Fedor Indutny
e19089f7b1 stream: use SO_OOBINLINE on OS X
In the collaboration with Ben Noordhuis <info@bnoordhuis.nl> and
Saúl Ibarra Corretgé <saghul@gmail.com>.

Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-02-24 22:34:01 +03:00
Ben Noordhuis
b36d4ff930 unix: implement uv_stream_set_blocking()
Commit 393c1c5 ("unix: set non-block mode in uv_{pipe,tcp,udp}_open")
causes a regression in the io.js cluster module.

The io.js documentation states that `worker.send()` and `process.send()`
are synchronous but they no longer were after upgrading to libuv v1.2.1.

The reason they are synchronous is because of backpressure - or rather,
lack of backpressure: a slow consumer eventually causes a fast producer
to run out of memory because the backlog of pending messages in the
producer can grow unchecked.

Ergo, implement uv_stream_set_blocking() on UNIX platforms to let io.js
enable the old blocking behavior for pipes again.

Refs: https://github.com/iojs/io.js/issues/760
PR-URL: https://github.com/libuv/libuv/pull/187
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-02-09 13:28:52 +01:00
Saúl Ibarra Corretgé
f2bb8d394c unix, win: add synchronous uv_get{addr,name}info
PR-URL: https://github.com/libuv/libuv/pull/156
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Bert Belder <bertbelder@gmail.com>
2015-01-23 01:12:05 +01:00
Saúl Ibarra Corretgé
2daee9fbeb unix: fix ttl, multicast ttl and loop options on IPv6
Fixes #93

PR-URL: https://github.com/libuv/libuv/pull/99
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-02 17:34:13 +01:00
Ben Noordhuis
751ac48baa linux: fix epoll_pwait() sigmask size calculation
Revisit the fix from commit b705b53.  The problem with using sigset_t
and _NSIG is that the size of sigset_t and the value of _NSIG depend
on what headers libuv picks up first, <signal.h> or <asm/signal.h>.
With the former, sizeof(sigset_t) = 128; with the latter, it's 8.

Simply sidestep the issue by calculating the signal mask as a 64 bits
integer, without using sigset_t or _NSIG.

PR-URL: https://github.com/libuv/libuv/pull/83
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-25 14:37:02 +01:00
Bert Belder
f9aa3b3d60 test: test that closing a poll handle doesn't corrupt the stack
This is a regression test for an issue that was originally reported
in https://github.com/libuv/libuv/pull/36, and fixed in cd89452.

PR-URL: https://github.com/libuv/libuv/pull/48
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-09 22:01:16 +01:00
Unknown W. Brackets
6760d51b52 windows: fix fs_write with nbufs > 1 and offset
When multiple bufs are specified, overlapped needs to be advanced
manually between each write.  Without this, each buf will be written
to the same position (if offset is specified.)

ReadFile() automatically advances, but WriteFile() does not.
2014-10-20 22:44:46 +02:00
Tomasz Kołodziejski
59658a8de7 unix, windows: add uv_thread_equal 2014-10-20 09:51:49 +02:00
cjihrig
c18205a1c5 unix, windows: add uv_fs_access() 2014-10-13 10:23:53 +02:00
Saúl Ibarra Corretgé
03e53f1cf7 fs: rename uv_fs_readdir to uv_fs_scandir
Closes #1431
2014-09-25 10:09:58 +02:00
Saúl Ibarra Corretgé
5ccdfc568d test: add test for closing and recreating default loop 2014-09-15 21:34:09 +02:00
Fedor Indutny
145b76b894 darwin: allocate enough space for select() hack
`fd_set`s are way too small for `select()` hack when stream's fd is
bigger than 1023. Make `fd_set`s a part of `uv__stream_select_t`
structure.

fix #1461
2014-09-08 08:37:36 +01:00
Saúl Ibarra Corretgé
7ff52b836d unix, windows: don't allow a NULL callback on timers 2014-09-05 16:59:18 +02:00
Bert Belder
6941cab549 windows: fix buffer leak after failed udp send
Fixes #1426

Signed-off-by: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-08-28 08:41:43 +02:00
Saúl Ibarra Corretgé
4ca9a36389 unix, windows: add uv_fileno
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.
2014-08-27 10:53:40 +02:00
Andrius Bentkus
d5e6f4372f unix: fix tcp write after bad connect freezing
If the connect wouldn't go off (no such tcp remote or any other failure),
the subsequent writes made would not be called. Now we call the writes
in the queue with ECANCELED if the connect fails.

Fix #1432
2014-08-21 16:23:43 +02:00
Julien Gilli
1552184238 unix: read on stream even when UV__POLLHUP set.
This fixes a SmartOS specific issue that happens when reading from
a stream that is the reading end of a pipe that has been closed by
the parent process.

In this case, a UV__POLLHUP event would be set on the stream and would
prevent the event loop from closing it. As a result, the event loop
would think there are stil handles open, and leave the process
hanging.

Fixes #1419.
2014-08-18 09:06:27 -07:00
Andrius Bentkus
0ecee213ea unix, windows: add uv_recv_buffer_size and uv_send_buffer_size 2014-08-09 11:36:35 +02:00
Jameson Nash
837c62c71b windows: make uv_read_stop immediately stop reading
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
2014-08-09 11:10:57 +02:00
Alex Crichton
c7e4b31444 windows: read the PATH env var of the child
The unix and windows process implementations diverge in their behavior
when dealing with subprocesses that are spawned with a relative path.
With unix the *child's* PATH environment variable is read, whereas
with windows the *parent's* environment variable is read.

This commit brings the two implementation in line with respect to
their behavior of reading PATH by having both read the *child's* PATH
environment variable. This involves looking into the user-provided
environment on windows and extracting the PATH variable specifically
so it can be inspected later on.
2014-08-06 02:12:44 +02:00
Saúl Ibarra Corretgé
d802486232 test: disable tcp_close_accept on Windows
It always was a Unix only test
2014-08-05 00:14:26 +02:00
Jameson Nash
2e9d86e105 windows: add uv_backend_timeout 2014-08-04 23:18:38 +02:00
Alexis Campailla
6d3a051eb4 windows: relay TCP bind errors via ipc
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 (
d1e6be1460
3da36fe00e
) 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.
2014-07-31 17:24:40 +02:00
Pavel Platto
e99b89f2ad unix, windows: add uv_fs_mkdtemp 2014-07-31 09:43:55 +02:00
Andrius Bentkus
960eefb319 unix: guarantee write queue cb execution order in streams
The problem was that the canceled write callbacks
were being called before the already written callbacks, even
though they were queued after them.
2014-07-18 13:16:10 +02:00
Saúl Ibarra Corretgé
817c09257d unix: remove incorrect assert
After 41891222bc landed it's possible that uv__udp_sendmsg is called
even if there are no pending write nor write completed requests:

1. User calls uv_udp_send and the request is sent immediately. The
   request is the added to the completed queue and we 'feed' the uv__io
   handle so that we process the completed request in the next
   iteration.
2. User calls uv_udp_send again but the request is not completed
   immediately, so it's queued in the write_queue.
3. The uv__io handle gets a UV__POLLOUT event and uv__udp_sendmsg is
   run, which completes the send request and puts it in the
   write_completed_queue. Afterwards, uv__udp_run_completed is executed
   and the write_completed queue is drained.
4. At this point, the uv__io handle was made pending in step 3, in
   uv__udp_sendmsg, but we no longer have requests to write or to complete,
   so we skip processing.
2014-07-11 22:53:59 +02:00
Andrius Bentkus
0d43992c3b unix, win: add uv_udp_try_send
The function returns UV_EAGAIN if the queue is not empty and
the message couldn't be sent immediately.
2014-07-04 18:30:33 +02:00
Saúl Ibarra Corretgé
570caf04db Merge branch 'v0.10'
Conflicts:
	ChangeLog
	build.mk
	src/unix/darwin.c
	src/unix/getaddrinfo.c
	src/version.c
	test/test-list.h
2014-06-25 10:31:21 +02:00
Saúl Ibarra Corretgé
133b9d1cc1 unix: allow uv_getnameinfo to be cancelled 2014-06-18 02:00:07 +02:00
Saúl Ibarra Corretgé
12bb46c095 windows: fix handling closed socket while poll handle is closing
fixes #1278

(backport from master for v0.10 branch)
2014-06-17 20:16:43 +02:00
Saúl Ibarra Corretgé
eee4776549 windows: fix handling closed socket while poll handle is closing
fixes #1278
2014-05-30 19:19:36 +02:00
Rasmus Christian Pedersen
70c42563c1 unix, windows: getnameinfo implementation
Closes #852
2014-05-20 17:33:52 +02:00
Saúl Ibarra Corretgé
386d2141e4 unix, windows: be consistent when binding implictly in UDP
Only these functions will trigger an implicit binding of a UDP handle:
- uv_udp_send
- uv_udp_recv_start
- uv_udp_set_membership

All other functions will return UV_EBADF in case the socket was not
bound.

Note: currently the socket is created and bound at the same time. This
may change in the future.
2014-05-08 15:12:09 +02:00
Saúl Ibarra Corretgé
9b4f2b84f1 unix, windows: validate flags on uv_udp|tcp_bind
fixes #1247
2014-04-22 22:57:01 +02:00
Fedor Indutny
2b21419242 inet: allow scopeid in uv_inet_pton
We already support it in `uv_ip6_addr` anyway.

See https://github.com/joyent/node/issues/7395
2014-04-14 15:47:50 +04:00
Fedor Indutny
23d130b209 Revert "inet: allow scope in uv_inet_pton ip6 check"
This reverts commit d30e3ab65a, because it
is a new feature!
2014-04-14 15:13:20 +04:00
Fedor Indutny
d30e3ab65a inet: allow scope in uv_inet_pton ip6 check
Note that isn't actually parsing it, since the output value is a
`struct in6_addr`.

see https://github.com/joyent/node/issues/7395
2014-04-14 12:45:42 +04:00
Alex Crichton
621c4a3929 windows: Fix an infinite loop in uv_spawn
The PATH-parsing code for windows erroneously contained an infinite
loop when the PATH started with a leading semicolon. Each iteration of
the loop usually bumped over the separator, but if the first character
was a semicolon then it would never skip it, causing the infinite
loop.

Closes #909
2014-04-10 07:29:24 -07:00
Saúl Ibarra Corretgé
3558d65d2f unix, windows: do not set SO_REUSEADDR by default on udp
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.
2014-04-02 01:21:35 +02:00
Saúl Ibarra Corretgé
08327a7cbd unix, windows: add IPv6 support for uv_udp_multicast_interface 2014-03-28 00:39:09 +01:00
Fedor Indutny
c84796ecc2 Merge branch 'v0.10'
Conflicts:
	src/unix/process.c
2014-03-26 20:45:13 +04:00
Tonis Tiigi
fd77a5d6c6 process: don't close stdio fds during spawn
This is needed when closed stdio fd is reused for uv_spawn pipe.
Fixes #1211
2014-03-26 20:35:08 +04:00
Saúl Ibarra Corretgé
7c5ab1a73e unix, windows: add IPv6 support to uv_udp_set_membership
Reworked from initial version by @snoj
2014-03-17 22:11:28 +01:00
Geoffry Song
84f305915f linux: always deregister closing fds from epoll
If the same file description is open in two different processes, then
closing the file descriptor is not sufficient to deregister it from the
epoll instance (as described in epoll(7)), resulting in spurious events
that cause the event loop to spin repeatedly. So always explicitly
deregister it.

Fixes #1099.

Conflicts:
	test/test-spawn.c
2014-03-10 17:27:36 +04:00
Fedor Indutny
b05a3ee4d1 pipe: allow queueing pending handles
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(...);
    }
2014-03-04 00:34:29 +04:00
Saúl Ibarra Corretgé
3a8767e35e unix: fix uv_fs_write when using an empty buffer 2014-02-26 23:59:29 +01:00
Saúl Ibarra Corretgé
8c9d5dce57 unix, windows: add uv_fs_poll_getpath 2014-02-24 23:21:13 +01:00
Saúl Ibarra Corretgé
a7ac2c462a unix, windows: add uv_fs_event_getpath 2014-02-24 22:08:23 +01:00
Saúl Ibarra Corretgé
5ac214c712 unix, windows: add uv_pipe_getsockname 2014-02-23 20:25:20 +01:00
Saúl Ibarra Corretgé
787f5fff92 unix, windows: add uv_loop_init and uv_loop_close
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.
2014-02-21 09:56:13 +01:00
Geoffry Song
780d8ad8e5 linux: always deregister closing fds from epoll
If the same file description is open in two different processes, then
closing the file descriptor is not sufficient to deregister it from the
epoll instance (as described in epoll(7)), resulting in spurious events
that cause the event loop to spin repeatedly. So always explicitly
deregister it.

Fixes #1099.
2014-02-19 17:13:49 +04:00
Saúl Ibarra Corretgé
6e2021ca11 unix: correct error when calling uv_shutdown twice
This is a backport of a284b90 for v0.10 branch
2014-02-15 16:55:06 +01:00
Keno Fischer
a284b90c03 unix: correct error when calling uv_shutdown twice
Before this one of the requests was left as a ghost in the system.
See https://github.com/JuliaLang/julia/issues/5793
2014-02-15 16:37:58 +01:00
Austin Foxley
451de61b72 unix, win: add uv_udp_set_multicast_interface() 2014-02-07 09:07:11 +01:00
Fedor Indutny
280469f4fe test: build spawn_fs_open only on unixes 2014-02-05 13:35:37 +04:00
Fedor Indutny
cb1cc25430 test: fix build on windows
disable spawn_fs_open
2014-02-01 04:57:16 +04:00
Fedor Indutny
6abe1e4b95 fs: uv__cloexec() opened fd
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
2014-02-01 01:02:37 +04:00
Dylan Cali
6c525df76d test: set getaddrinfo_fail timeout to 10000
getaddrinfo_fail can sometimes take slightly longer than the default
timeout of 5000. Set its timeout to 10000 to compensate, but leave the
timeout of all other tests at the default.
2014-02-01 00:50:40 +04:00