Commit Graph

395 Commits

Author SHA1 Message Date
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
Dylan Cali
756087e017 test: support flexibly setting custom task options
Add a single TEST_ENTRY_CUSTOM hook that can be used to override task
entry defaults. Different tests can have different timeouts depending on
what is appropriate for each test. A separate TEST_OUTPUT_ENTRY hook is
no longer necessary.

In order to support per-task timeouts, the timeout field has been moved
into the task_entry_t struct. The default (5000) is now set as part of
TEST_ENTRY.
2014-02-01 00:50:40 +04:00
Bert Belder
53effc3dd8 Merge branch 'v0.10'
Conflicts:
	ChangeLog
	src/unix/process.c
	src/version.c
2014-01-22 19:49:24 +01:00
Fedor Indutny
e403a2c486 process: close stdio after dup2'ing it
Thus allow passing the same file descriptor as the source of multiple
stdios.

Committed with the help and code parts from:

  * Sam Roberts <sam@strongloop.com>

fix #1074
2014-01-22 22:39:08 +04:00
Bert Belder
140c863ff0 Merge branch 'v0.10'
Conflicts:
	build.mk
	Makefile.am
	test/test-ipc.c
2013-12-21 02:42:48 -08:00
Bert Belder
c66340d59b test: add pipe-server-close test
Add a regression test for the pipe server close issue on Windows, which
was reported in joyent/node#6749 and fixed in 7b16a3f.
2013-12-20 19:40:02 -08:00
Sam Roberts
ed36b85d3b unix, windows: add uv_loop_alive() function
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).
2013-12-19 15:35:03 -08:00
Fedor Indutny
b5e7798a89 stream: introduce uv_try_write(...)
`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
2013-12-13 22:29:00 +04:00
Yorkie
4ed6496b9c unix, windows: detect errors in uv_ip4/6_addr 2013-12-13 09:27:28 +01:00
Saúl Ibarra Corretgé
15af49a7a0 unix, windows: always update loop time
Fixes #846
2013-12-10 09:13:34 +01:00
Ben Noordhuis
a43537eead test: back-port EMFILE test from master branch
Back-port the test from commit 27795cf from the master branch ("unix:
fix accept() EMFILE error handling").
2013-11-25 12:58:39 +01:00
Ben Noordhuis
27795cfc0f unix: fix accept() EMFILE error handling
Fix a bug that was introduced in commit 3ee4d3f ("unix, windows:
return error codes directly") and add a regression test for good
measure.

Hat tip to Fedor for pointing out the issue.

Fixes #1007.
2013-11-25 01:54:47 +01:00
Fedor Indutny
86b5c1ef1c test: test fsevents error reporting
Create a lot of `FSEventStream`s to make `FSEventStreamStart()` fail.
Fetch the error code and verify that it is correct.
2013-11-13 18:18:56 +04:00
Fedor Indutny
6149b66ccb Merge branch 'v0.10'
Conflicts:
	build.mk
	src/unix/core.c
	src/unix/darwin.c
2013-11-12 15:30:54 +04:00
Fedor Indutny
bbccafbe70 unix: fix reopened fd bug
When fd is closed and new one (with the same number) is opened inside
kqueue/epoll/port loop's callback - stale events might invoke callbacks
on wrong watchers.

Check if watcher was changed after invocation and invalidate all events
with the same fd.

fix #826
2013-11-12 15:02:59 +04:00
Ben Noordhuis
24bfef2ef4 linux: handle EPOLLHUP without EPOLLIN/EPOLLOUT
Work around an epoll quirk where it sometimes reports just the EPOLLERR
or EPOLLHUP event.  In order to force the event loop to move forward,
we merge in the read/write events that the watcher is interested in;
uv__read() and uv__write() will then deal with the error or hangup in
the usual fashion.

Fixes #982.
2013-11-08 05:16:55 +01:00
Ben Noordhuis
2bb3326c48 Merge remote-tracking branch 'origin/v0.10'
Drops commit 3780e12 ("fsevents: support japaneese characters in path")
for being quite inapplicable to the master branch.  Will be reworked
and applied in a follow-up commit.

Conflicts:
	README.md
	build.mk
	src/unix/fsevents.c
	src/unix/udp.c
2013-11-08 03:44:31 +01:00
Ben Noordhuis
7f44933c43 include: remove uv_strlcat() and uv_strlcpy()
It was pointed out that they don't quite work like their BSD namesakes
and they arguably shouldn't have been part of the API anyway.

Fixes #983.
2013-11-03 03:50:23 +01:00
Fedor Indutny
f9960184fd test: add regression test for 29fdb3471 2013-10-31 01:16:02 +04:00
Fedor Indutny
429bb804ed fsevents: fix clever rescheduling
There're could be a situation, where one fsevents handle gets created
and another one is destroyed simultaneously. In such cases
`fsevent_need_reschedule` will be set to 1 twice and reset only once,
leaving handle destructor hanging in uv_sem_wait().
2013-10-05 22:18:06 +04:00
Saúl Ibarra Corretgé
2b9c374c1c windows: run close callbacks after polling for i/o
Makes the uv-win behavior compatible with uv-unix.

Fixes #796.
2013-09-06 06:28:42 +02:00
Ben Noordhuis
5d2434bf71 unix, windows: add thread-local storage API
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.
2013-08-25 15:51:07 +02:00
Ben Noordhuis
1510ce81fd unix, windows: allow NULL async callback
Allow a NULL callback so the user doesn't have to provide a dummy when
the actual event is processed by e.g. a check handle callback.
2013-08-12 08:55:51 +02:00
Miroslav Bajtoš
fd45f876ff linux,darwin,win: link-local IPv6 addresses
Modified uv_ip6_addr() to fill sin6_scope_id for link-local addresses.

Fixes #271

Conflicts:
	build.mk
2013-07-04 15:43:20 +02:00
Ben Noordhuis
ce2458c053 Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	test/test-fs.c
	test/test-list.h
2013-06-26 10:35:41 +02:00
Ben Noordhuis
5841852703 test: add 'start timer from check handle' test
Check that a timer that is started from a check handle gets picked up
correctly, i.e. that it influences the timeout used in the next tick
of the event loop.
2013-06-26 13:56:32 +02:00
Ben Noordhuis
f6d8ba3c9a unix, windows: run expired timers in run-once mode
Before this commit, creating an event loop, starting a timer and
calling uv_run(UV_RUN_ONCE) blocked in uv_run() until the timer
expired - but didn't actually run the timer.
2013-05-30 00:33:23 +02:00
Ben Noordhuis
ebdeaed2e3 Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	ChangeLog
	src/version.c
2013-05-02 09:22:39 +02:00
Fedor Indutny
ac4e7e7ff2 stream: fix small nit in select hack, add test 2013-04-27 18:50:55 +02:00
Saúl Ibarra Corretgé
a92b66fe33 unix, windows: add uv_has_ref() function 2013-04-17 15:31:08 +02:00
Ben Noordhuis
76d831e4c8 unix: getaddrinfo_cb status arg should be 0 or -1
The documentation in uv.h states that the status argument to the
uv_getaddrinfo() callback is either 0 or -1 but uv-unix actually
passed it the addrinfo error code. Rectify that and add a regression
test.

Fixes #754.
2013-03-26 22:30:46 +01:00
Ben Noordhuis
9b619396d9 unix: make timers handle large timeouts
This commit fixes two closely related integer overflow bugs:

* Timers with a timeout > INT_MAX cause uv__next_timeout() to return
  a negative value.

* Timers with very large timeouts (close or equal to ULLONG_MAX) run on
  the next tick.

In both cases, clamp the values to prevent the overflow from happening.

Fixes joyent/node#5101.
2013-03-21 14:54:36 +01:00
Brian Mazza
77cb29a723 unix: make uv_timer_init() initialize repeat
uv_timer_get_repeat() should return 0 for timers that haven't been
started.
2013-03-19 23:15:30 +01:00
Saúl Ibarra Corretgé
bb3d1e24da unix, windows: add uv_stop, stop running event loop 2013-02-25 16:21:37 +01:00
Ben Noordhuis
da0b84d4e8 unix: auto-unref spawn handle on process exit
Consistent, for better or worse, with uv-win.

Fixes #718.
2013-02-22 14:39:40 +01:00
Shigeki Ohtsu
fadfeaf6ec unix,windows: fix timer order in case of same timeout
Compare start_id of timer handles when they have the same timeout.
start_id is allocated with loop->timer_counter in uv_timer_start.
2013-02-10 17:46:22 +01:00
Ben Noordhuis
4cbd5c7b32 test: remove bad tcp_write_error test
It makes the assumption that if you try to write to a localhost socket
often enough, eventually its send queue will fill up - which doesn't
happen if the machine it's running on is fast enough.
2013-01-16 00:31:21 +01:00
Ben Noordhuis
9aab5d4837 Revert "unix: improve uv_guess_handle() implementation"
This reverts commit 98bcddc8dd.

It's making a lot of tests in the node.js test suite fail.
2013-01-11 13:40:25 +01:00
Ben Leslie
98bcddc8dd unix: improve uv_guess_handle() implementation
uv_guess_handle is currently squelching both fifo and all
sockets on to the UV_NAMED_PIPE type. Rather than treating
all sockets as UV_NAMED_PIPE, use getsockopt() and
getsockaddr() to determine if the socket is an AF_UNIX
stream (in which case return UV_NAMED_PIPE), or an AF_INET
stream (in which case return UV_TCP), or an AF_INET datagram
socket (in which case return UV_UDP).

Additionally, currently all other file descriptor types are
squelched to the UV_FILE type. Instead, only file descriptors
that are marked as regular files are treated as UV_FILE. All
other types (such as directories, character and block devices)
are now treated as UV_UNKNOWN_HANDLE.
2013-01-08 05:26:58 +01:00
Ben Noordhuis
1f52fc1c5a test: remove consumer_producer test
It fails intermittently on Travis for no other reason than that Travis
is occasionally slow. Reduce the number of false positives, remove the
test.
2013-01-06 19:19:23 +01:00
Ben Noordhuis
92a19a19dd unix: ensure done_cb gets called after uv_cancel()
Wake up the event loop with uv_async_send() when a request is cancelled.
Ensures the done_cb is run on the next tick of the event loop.

Not sending a wakeup signal results in the done_cb not getting called until
another request completes, which may be a long time coming when it's the only
request in the queue or when other requests are executing long-running jobs.

Fixes #669.
2012-12-28 18:09:39 +01:00
Saúl Ibarra Corretgé
0820be7008 Implemented uv_run2
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
2012-12-18 16:11:23 +01:00
Ben Noordhuis
c6c5b7a901 Merge branch 'v0.8' 2012-12-14 12:07:31 +01:00
Andrew Shaffer
49977386e9 sunos: properly disarm PORT_LOADED fsevent watcher
Fixes a segmentation fault when the watched entity is changed after the watcher
has been closed.
2012-12-14 12:02:57 +01:00
Ben Noordhuis
e079a99abd unix: fix event loop stall
Fix a rather obscure bug where the event loop stalls when an I/O watcher is
stopped while an artificial event, generated with uv__io_feed(), is pending.
2012-12-13 20:17:12 +01:00
Ben Noordhuis
52c8a8617d unix: add uv_cancel() 2012-12-09 15:12:42 +01:00
Fedor Indutny
09a7f85b70 unix: add uv_backend_fd() and uv_backend_timeout()
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.
2012-11-28 16:30:50 +01:00
Shigeki Ohtsu
0cca5391ba unix, windows: disallow NULL worker in thread pool
See #629.
2012-11-24 01:09:49 +01:00
Charlie McConnell
fb64948746 unix: do not set environ unless one is provided
Currently, `uv_spawn` will set `environ` to the value of `options.env`, even if
`options.env` is `NULL`.  This results in child processes for whom `environ ==
NULL`, which can cause a variety of unexpected issues.

This is a back-port of commit 1d85815 from the master branch.
2012-11-03 01:41:10 +01:00
Charlie McConnell
1d858156b4 unix: do not set environ unless one is provided
Currently, `uv_spawn` will set `environ` to the value of `options.env`, even if
`options.env` is `NULL`.  This results in child processes for whom `environ ==
NULL`, which can cause a variety of unexpected issues.
2012-11-03 01:37:22 +01:00
Bert Belder
149b16f123 windows: closing handles should always keep the loop alive
This makes the tcp-ref2 and udp-ref2 tests pass again.
Also adds another reference count test.
2012-10-25 15:10:29 +02:00
Bert Belder
1e32cb01b5 unix: support signal handlers outside the main loop 2012-10-17 01:25:02 +02:00
Bert Belder
28eb619c65 windows: don't run signal tests
They are dummy tests on windows, running them is misleading.
Also remove duplicate 'test-signal.c' entry from uv.gyp.
2012-10-16 17:23:04 +02:00
Hiroaki Nakamura
acea3028c5 unix, windows: add thread barrier support 2012-10-09 17:30:52 +02:00
Shigeki Ohtsu
f7c991f1ce test: add consumer-producer test for condvar 2012-10-07 23:17:31 +02:00
Hiroaki Nakamura
976c8a4387 Add support for condition variables on all platforms 2012-10-05 13:03:55 +02:00
Ben Noordhuis
1923abda94 test: add uv_fs_readlink test 2012-10-01 22:53:59 +02:00
Saúl Ibarra Corretgé
cc1c1912ca unix, windows: add uv_tcp_open and uv_udp_open 2012-09-17 18:09:51 +02:00
Bert Belder
621a4e36f7 test: add test for uv_is_active and uv_is_closing 2012-08-27 23:57:48 +02:00
Ben Noordhuis
837edf4c0f unix, windows: remove handle init counters
Remove the handle init counters, no one uses them.
2012-08-10 02:00:11 +02:00
Ben Noordhuis
ee50db6e36 unix, windows: preliminary signal handler support
* a no-op on Windows for now
* only supports the main loop on UNIX (again, for now)
2012-08-10 02:00:07 +02:00
Ben Noordhuis
13467a40d4 unix: retrieve execve() errors in process.c
Make the forked child process send the errno to its parent process when it
fails to spawn a new process.
2012-08-08 23:19:50 +02:00
Bert Belder
35c4858231 Remove c-ares tests and benchmarks 2012-08-07 01:03:51 +02:00
Ben Noordhuis
b5b8ead808 test: add failing fs_event test
Watches the same file twice. Fails on Linux with a segmentation fault.
2012-07-28 14:40:03 +02:00
Ben Noordhuis
1d1dd9bb7d test: add 'unexpected read' tcp test
Regression test that verifies that the event loop doesn't busy loop when
the server sends a message and the client isn't reading.
2012-06-30 03:25:52 +02:00
Bert Belder
7628b6597e test: fix test-gethostbyname to not use a DNS server on localhost
Because, you know, not everybody has one.
2012-06-29 05:44:20 +02:00
Ben Noordhuis
cc7c8542a5 unix, windows: add stat() based file watcher
Monitors a file path for changes. Supersedes ev_stat.
2012-05-31 20:32:24 +02:00
Iñaki Baz Castillo
b47af98e00 test: add tcp 'close on failed connect' test
Demonstrates temporary event loop stall with uv-unix. The issue is that pending
requests aren't processed until the next event (I/O, timeout, etc.) happens.

See #446, #447 and #448.
2012-06-07 00:06:24 +02:00
Ben Noordhuis
7d2ea31618 unix: fix event loop stall
Stop libev from entering the epoll_wait/kevent/port_getn/etc. syscall when
there are no active handles left, that will block indefinitely.
2012-06-04 23:36:50 +02:00
Ben Noordhuis
d08070435d test: rename test tcp_dont_connect_after_write
Rename test tcp_dont_connect_after_write to tcp_connect_error_after_write,
teensy tad more descriptive.
2012-06-04 17:35:56 +02:00
Ben Noordhuis
b96ed68f46 test: add TCP connect error + write test
Original test contributed by Iñaki Baz Castillo. See #443.
2012-06-04 15:58:32 +02:00
Ben Noordhuis
c76c2066c6 unix, windows: add semaphore functions 2012-06-03 04:04:05 +02:00
Fedor Indutny
1cd9642cbb test: stdin/out/err should be set to /dev/null when ignored 2012-06-02 21:38:39 +02:00
Bert Belder
9759c20e90 test: verify that closing an active poll handle doesn't hang 2012-06-01 18:39:47 +02:00
Fedor Indutny
dc7a62d114 test: test for uv_spawn with stdio_count == 3 2012-06-01 17:32:34 +02:00
Charlie McConnell
69a923bf93 process: implement UV_PROCESS_DETACHED flag for uv_spawn 2012-06-01 02:24:05 +02:00
Ben Noordhuis
171ad8567d unix, windows: add uv_walk()
Lets the libuv user iterate over the open handles. Mostly intended as a
debugging tool or a post-hoc cleanup mechanism.
2012-05-30 02:33:39 +02:00
Igor Zinkovsky
5a34f19970 windows: allow specifying FDs to be inherited by a child process
Previously the only option was to create a pipe or an ipc channel. This
patch makes it possible to inherit a handle that is already open in the
parent process. There is also room for setting more than just stdin,
stdout and stderr, although this is not supported yet.
2012-05-28 23:59:58 +02:00
Ben Noordhuis
028fef84b8 unix: update timer if already active
uv_timer_start() no longer returns an error when the timer is already active,
now it just updates the timer. Consistent with the uv-win implementation.

Fixes #425.
2012-05-26 02:09:59 +02:00