Commit Graph

196 Commits

Author SHA1 Message Date
Ben Noordhuis
b3a97f8981 unix: make uv__cloexec() EINTR resilient
It's somewhat underspecified if and when fcntl() can return EINTR. It never
does on Linux for F_GETFD or F_SETFD but let's not make any assumptions.
2012-06-14 01:19:34 +02:00
Ben Noordhuis
95e89c6a0e unix, windows: share uv__handle_init() 2012-06-13 01:28:58 +02:00
Ben Noordhuis
dea45940cd unix: fix req cb / close cb invoke delay
Finalization of closed handles and associated requests was sometimes delayed
until an external event (network I/O, timeout, etc.) happened. This commit
addresses that.
2012-06-08 01:37:39 +02:00
Ben Noordhuis
649ad50c32 unix: fix event loop stall
Undoes most of the changes made to libev in 7d2ea31 and c9396dd.
2012-06-06 05:12:28 +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
c9396dd57e unix: implement timers in libuv
* replace libev backed timers with a pure libuv implementation
* gut ev_run() and make it take a timeout instead of flags

Incidentally speeds up the loop_count_timed benchmark by about 100%.
2012-05-31 03:08:34 +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
Ben Noordhuis
9d26f49725 unix, windows: rename flags UV__ACTIVE, UV__REF
Rename UV__ACTIVE and UV__REF to UV__HANDLE_ACTIVE and UV__HANDLE_REF to make
it clear that they apply to handles, not requests or loops.
2012-05-30 01:30:24 +02:00
Ben Noordhuis
58a272e556 unix: rework pending handle/req logic 2012-05-30 00:08:22 +02:00
Ben Noordhuis
4690204682 unix: fix getaddrinfo bad pointer deref 2012-05-29 00:06:11 +02:00
Bert Belder
e4f23aacec Get rid of UV_LEAN_AND_MEAN 2012-05-28 01:53:22 +02:00
isaacs
604802ad47 Fix sunos build: undeclared variable 'handle' 2012-05-24 23:00:31 +02:00
Ben Noordhuis
752ac30ec8 unix: don't pass sockaddr to accept()
Shaves a few nanoseconds off the accept() syscall.
2012-05-24 14:31:53 +02:00
Ben Noordhuis
5fd2c406f1 unix: fix up asserts in core.c and stream.c 2012-05-23 22:19:12 +02:00
Ben Noordhuis
7c8313bd0f unix, windows: make uv_run_once() return a bool
The return value of uv_run_once() now signals if it needs to be called again.

Fixes #427.
2012-05-23 20:49:03 +02:00
Ben Noordhuis
5b9c45120a unix: fold uv__io_cb into ev_io struct
Makes the uv__io code a little more obscure but has the advantage that
sizeof(uv__io_t) == sizeof(ev_io), i.e. the sizes of embedding handles
don't change.
2012-05-23 03:57:08 +02:00
Ben Noordhuis
3bc9707054 unix: replace ev_io with uv__io_t
Replace ev_io usage with wrapper constructs.

This is preliminary work for the transition to a libev-less linux backend.
2012-05-23 03:42:32 +02:00
Ben Noordhuis
80b554129b unix: reactive new idle watcher implementation
The new idle watcher was temporarily disabled in 073a48d due to some semantic
incompatibilities with the previous implementation. This commit resolves those
issues and reactivates the new implementation.

One outstanding bug is that idle watchers can run in a different order
(relative to other handle types) than the old implementation, e.g. (timer, idle)
instead of the expected (idle, timer). This will be fixed in an upcoming commit.
2012-05-22 15:13:52 +02:00
Ben Noordhuis
6fd9bfb7b0 unix: fix event loop block, prepare/check invoke
Don't block in epoll_wait() / kevent() / etc. syscall unless there are active
handles. If there are only active requests, do a non-blocking poll.

Likewise, don't run the prepare and check watchers unless there are active
handles *or* requests.
2012-05-21 17:41:52 +02:00
Ben Noordhuis
073a48d6bf unix: back out new idle watcher for now
Its semantics don't quite match what node.js expects. This breaks the
stdio_over_pipes and shutdown_close_pipe tests but that can't be helped.
2012-05-18 01:19:56 +02:00
Ben Noordhuis
9efa8b3571 unix, windows: rework reference counting scheme
This commit changes how the event loop determines if it needs to stay alive.

Previously, an internal counter was increased whenever a handle got created
and decreased again when the handle was closed.

While conceptually simple, it turned out hard to work with: you often want
to keep the event loop alive only if the handle is actually doing something.
Stopped or inactive handles were a frequent source of hanging event loops.

That's why this commit changes the reference counting scheme to a model where
a handle only references the event loop when it's active. 'Active' means
different things for different handle types, e.g.:

 * timers: ticking
 * sockets: reading, writing or listening
 * processes: always active (for now, subject to change)
 * idle, check, prepare: only active when started

This commit also changes how the uv_ref() and uv_unref() functions work: they
now operate on the level of individual handles, not the whole event loop.

The Windows implementation was done by Bert Belder.
2012-05-17 07:07:53 +02:00
Frank Denis
07622e767d unix: change #if FIONBIO to #ifdef FIONBIO
Fixes compilation on Debian/ppc 6.0.4.
2012-05-16 16:59:42 +02:00
Bert Belder
d60d94e0c3 Unix: implement uv_poll 2012-05-03 15:52:56 +02:00
Ben Noordhuis
ab3b307df3 unix: clean up uv__req_init() 2012-04-18 22:30:20 +02:00
Ben Noordhuis
edb39b2499 const-ify handle argument to uv_is_closing() 2012-04-18 03:11:25 +02:00
Ben Noordhuis
fb6c9eef2a const-ify handle argument to uv_is_active() 2012-04-18 03:09:53 +02:00
Ben Noordhuis
68bed698fc unix: move loop init logic out of core.c 2012-04-04 05:54:39 -07:00
Ben Noordhuis
5a8446c309 unix: move handle specific close logic out of core.c 2012-04-04 05:30:15 -07:00
Ben Noordhuis
ed395e0619 unix: replace handle->next_watcher
Remove the next_watcher and replace it with a linked list. Said list is named
endgame_handles (because the uv-win calls it that) and contains all the handles
that are in the UV_CLOSING state.

The goal of this commit is two-fold:

a) remove a dependency on libev, and
b) share more code with uv-win in the future

A nice side effect is that it shaves a few bytes off a uv_handle_t.
2012-04-04 05:22:20 -07:00
Ben Noordhuis
5fbe0aab33 unix: move active checks out of core.c
Move active checks out of core.c and into their respective compilation units:
check, idle, prepare, timer.
2012-04-04 06:52:29 +02:00
Ben Noordhuis
5a59e4924a unix: move idle code from core.c to idle.c 2012-04-04 05:25:34 +02:00
Ben Noordhuis
dd31265751 unix: move check code from core.c to check.c 2012-04-04 05:25:34 +02:00
Ben Noordhuis
f1a19e6d34 unix: move prepare code from core.c to prepare.c 2012-04-04 05:25:34 +02:00
Ben Noordhuis
f7359a335c unix: move async code from core.c to async.c 2012-04-04 05:25:34 +02:00
Ben Noordhuis
fd987a26fe unix: move timer code from core.c to timer.c 2012-04-04 05:25:27 +02:00
Vladimir Dronnikov
b309f2e2e6 Add uv_is_closing()
Closes #367.
2012-04-01 21:05:50 +02:00
Ben Noordhuis
685b36ba66 linux: tidy up syscall code 2012-03-31 00:19:01 +00:00
Ben Noordhuis
4ff0898c5f unix: replace uv__close() with close()
uv__close() was deprecated a while ago. It's been an alias for close() ever
since. Remove it.
2012-03-21 02:11:18 +01:00
Ben Noordhuis
dfda5009c2 unix, win: store ares handles in a binary tree
Store the uv_ares_task_t handles in a red-black tree, not a linked list.

Fixes #72.
2012-03-16 00:49:29 +01:00
Ben Noordhuis
2f886c892e unix: don't rely on libev to track timer state
An obscure libev bug sometimes makes it miss state changes. Keep track of the
state ourselves.

Fixes joyent/node#2515.
2012-02-28 17:24:50 +01:00
Ben Noordhuis
ec0eff955e Revert b3e0ad4, 149d32c, e99fdf0 and ea9baef.
Detaching doesn't work yet, the setsid() call fails and leaves the child process
attached to the parent's session.

Revert "test: Add test case for spawning detached child processes."
Revert "win: Implement options.detached for uv_spawn() for Windows."
Revert "unix: Implement options.detached for uv_spawn() for unix."
Revert "Add "detached" member to uv_process_options_t to denote whether a child
        process should spawn detached from its parent."

This reverts commit ea9baef95c.
This reverts commit e99fdf0df6.
This reverts commit 149d32cb96.
This reverts commit b3e0ad4db8.
2012-02-28 15:29:05 +01:00
Charlie McConnell
149d32cb96 unix: Implement options.detached for uv_spawn() for unix. 2012-02-24 15:15:00 +01:00
Ben Noordhuis
d3efefb043 linux: share inotify fd across event loop
Previously, a new inotify fd was created for each watcher, making it quite easy
to run into the system-wide fs.inotify.max_user_instances limit (usually 128).

Fixes #300.
2012-02-23 09:21:30 -08:00
Ben Noordhuis
abdc3efffe unix: add uv__dup() 2012-01-30 21:44:27 +01:00
Ben Noordhuis
28b0867f03 unix: clean up udp shutdown sequence 2012-01-18 20:18:57 +01:00
Ben Noordhuis
ee10cb77bd unix: use container_of() instead of w->data 2012-01-18 19:34:22 +01:00
Ben Noordhuis
dee86dd5b0 unix: don't retry close() on EINTR
Linux 2.6 always closes the file descriptor, even on EINTR. Retrying the close()
call isn't merely useless, it's actively harmful - the file descriptor may have
been acquired by another thread.
2012-01-18 15:06:30 +01:00
Ben Noordhuis
71f6c0edb8 Merge remote-tracking branch 'origin/v0.6'
Conflicts:
	src/win/util.c
2012-01-16 18:07:49 +01:00
Ben Noordhuis
6d9c9a533f Add uv_loop_refcount() function, debug tool. 2012-01-14 00:33:08 +01:00
Ben Noordhuis
a13584bec7 unix: remove unused #define 2012-01-13 15:59:53 +01:00
Daisuke Murase
e8494dddc0 unix: use EVRUN_ONCE in uv_run_once()
EVRUN_NOWAIT means "poll and don't block". Use EVRUN_ONCE instead, "wait for
single event".
2012-01-11 10:15:25 +01:00
Paddy Byers
abf9654a55 unix: create separate eio result queue per loop
Makes the eio "done" callback run in the thread that submitted it. Makes it safe
to use libeio from multiple event loops.
2011-12-20 20:47:33 +01:00
Ben Noordhuis
10de090b9e unix: centralize loop init logic
Also fixes a bug where loops other than the main loop didn't pick the kqueue
backend, which broke the fs event watcher on Darwin and the BSDs.
2011-12-20 20:47:33 +01:00
Ben Noordhuis
6b3075cd73 linux: improve kernel feature detection
Do not check for minimum kernel and glibc versions, just check that the kernel
headers export the syscall number and invoke the syscall directly. Effectively
bypasses glibc.
2011-12-16 15:16:31 +01:00
mattn
e53cecb8c0 add uv_run_once() 2011-12-14 14:28:35 +01:00
Ben Noordhuis
4c6008f488 Merge branch 'v0.6'
Conflicts:
	test/test-list.h
2011-12-12 18:04:17 +01:00
Shigeki Ohtsu
ba52023ef3 Fix missing increments of loop->counters 2011-12-12 18:01:26 +01:00
Ben Noordhuis
0d8cb08f83 Merge branch 'v0.6' 2011-12-08 16:31:52 +01:00
Ben Noordhuis
34e95d1a4c unix: make it safe to delete the default loop
Fixes a potential free() of non-malloc'ed memory.
2011-12-04 13:20:23 +01:00
Ben Noordhuis
f5c2a4a1ae Merge branch 'v0.6'
Conflicts:
	src/unix/core.c
	src/win/winapi.h
2011-12-02 18:15:04 +01:00
Igor Zinkovsky
dceb3e65ca uv_cwd + uv_chdir 2011-12-01 12:27:12 -08:00
Ben Noordhuis
b52b8c7128 util: add uv_strlcpy() and uv_strlcat() functions 2011-11-23 17:29:02 +01:00
Ben Noordhuis
d5b26154f7 linux: improve kernel feature detection
Do not check for minimum kernel and glibc versions, just check that the kernel
headers export the syscall number and invoke the syscall directly. Effectively
bypasses glibc.
2011-11-17 18:05:53 +01:00
Ben Noordhuis
26806e2b1c sunos: add getaddrinfo() compatibility hack
getaddrinfo() returns EAI_MEMORY if strlen(hostname) >= MAXHOSTNAMELEN
2011-11-10 16:39:03 +00:00
Ben Noordhuis
4794c12f58 linux: fall back to traditional syscalls if necessary
libuv uses feature checks to determine if newer syscalls like pipe2() are
available. This works fine until someone compiles libuv against kernel headers
that are newer than the actual kernel our software runs on.

Fall back to traditional (but race-y!) syscalls when the kernel reports ENOSYS
or EINVAL.
2011-11-09 15:38:51 +01:00
Ben Noordhuis
7b973eb4ad Fix uv_loop_new() and uv_default_loop() function prototypes. 2011-11-06 04:04:32 +01:00
Ben Noordhuis
77a2477c3f unix: add EAI_NODATA #ifdef guard, freebsd doesn't have it 2011-11-03 02:38:31 +01:00
Ben Noordhuis
70381cef9b unix: add getaddrinfo compatibility hack
Revisit in the future. This is not a good hack.
2011-10-30 02:55:12 +01:00
Ben Noordhuis
84bc18684e linux: omit superfluous fcntl(F_GETFD) syscall 2011-10-29 05:32:34 +02:00
Ben Noordhuis
ed2b5e60cb linux: use ioctl(FIONBIO) to set O_NONBLOCK, saves a syscall 2011-10-29 01:31:11 +02:00
Ben Noordhuis
f2c6b4106d unix: have uv_strerror() handle getaddrinfo() errors 2011-10-28 01:31:55 +02:00
Ben Noordhuis
9da53df457 unix: fix uv_freeaddrinfo() segfault on sunos
The system freeaddrinfo() on SunOS does not handle NULL values graciously.
2011-10-21 14:20:36 -07:00
Igor Zinkovsky
81c4043c83 ipc on windows 2011-10-06 10:17:42 -07:00
Ben Noordhuis
8e9a3384c9 unix: implement kqueue file watcher API
kqueue fds are not embeddable into other pollsets (select, poll, kqueue).
Hack the libev event loop to receive kqueue events with filter flags intact.
2011-10-04 23:28:36 +02:00
saghul
b594dba248 unix: fix memcpy when copying hints on uv_getaddrinfo 2011-09-29 15:32:26 +02:00
Erick Tryzelaar
23796d208c Fixes #76. Unify OS error reporting
As a nice fringe benefit, this also shaves a word
off of a windows TCP handle by replacing "uv_err_t
bind_error" with "int bind_error".
2011-09-27 19:05:33 -07:00
Erick Tryzelaar
7e8645d101 unix,win: Make uv_freeaddrinfo to clean up addrinfo
Fixes #196
2011-09-23 09:31:01 -07:00
Ben Noordhuis
2a1c32a60c linux: implement file watcher API 2011-09-21 13:23:49 -07:00
Ryan Dahl
2ef8f359ee tty fixes for unix 2011-09-20 13:14:16 -07:00
Ben Noordhuis
37e8bf2556 unix: fix dangling pointer free() bug 2011-09-19 17:23:23 +02:00
Erick Tryzelaar
70e1032094 unix: Fix uv_getaddrinfo from deleting invalid data
If the uv_getaddrinfo_t handle is owned by its
data pointer, deleting the data in the callback
could cause uv_getaddrinfo_done to call freeaddrinfo
on an invalid pointer.
2011-09-19 17:11:34 +02:00
Ben Noordhuis
3c96410902 unix: bring back uv__stream_destroy()
This is the revised version of reverted commit 431195c.
2011-09-14 04:48:56 +02:00
Ryan Dahl
828b6eb11d unix: remove uv_init 2011-09-12 11:32:41 -07:00
Erick Tryzelaar
efa1b54076 Subclass uv_getaddrinfo_t from uv_req_t.
This patch also fixes #155. Since we no longer
memset clear the uv_getaddrinfo_t, the user can
now set the `uv_getaddrinfo_t->data` field without
problems.
2011-09-10 01:46:26 -07:00
Ben Noordhuis
ca5346f9ce unix: revert 98b9f58 and 431195c for now, corrupts memory 2011-09-09 23:40:10 +02:00
Ben Noordhuis
431195c944 unix: run callbacks of pending writes when handle is closed 2011-09-08 19:15:22 +02:00
Ben Noordhuis
cc91989cc2 unix: fix buffer overrun in uv__strlcpy()
Reported by Thomas Shinnick.
2011-09-06 15:44:47 +02:00
Ben Noordhuis
bb0c6e6d53 unix: move linux feature detection macros to internal.h 2011-09-05 16:05:28 +02:00
Ryan Dahl
142a70292b unix: fix fs_chmod 2011-09-04 16:09:45 -07:00
Bert Belder
12b01e95f9 Specialize uv_xxx_getsockname, add uv_tcp_getpeername 2011-09-04 04:49:13 +02:00
Ryan Dahl
836cc204b6 unix: Fix test-gethostbyname 2011-08-31 15:37:16 -07:00
Ryan Dahl
6fd340b8ca unix: split out stream into its own file 2011-08-31 13:41:22 -07:00
Ryan Dahl
38ce213b6a unix: split out pipe 2011-08-31 13:29:17 -07:00
Ryan Dahl
510407c03d unix: split out tcp module 2011-08-31 13:11:38 -07:00
Ryan Dahl
e553f96f94 unix: split out uv_spawn into src/unix/process.c 2011-08-31 11:50:08 -07:00
Ryan Dahl
490c83dd35 move src/uv-unix.c to src/unix/core.c 2011-08-31 11:26:43 -07:00