Commit Graph

2306 Commits

Author SHA1 Message Date
Henry Rawas
92040eb712 stream: add an API to make streams do blocking writes
This patch adds the `uv_stream_set_blocking` API which makes all
uv_write calls to that stream blocking. It currently only works for
pipes, on windows.
2013-06-20 19:27:39 +02:00
Ben Noordhuis
b1d390eb79 windows: don't use uppercase in include filename
Change <Winsock2.h> to <winsock2.h>. The former breaks
cross-compilation with mingw.
2013-06-14 00:45:03 +02:00
Linus Mårtensson
ff3ee84442 build: set OS=="android" for android builds
Work around the build name issues by instead manually adding the build
target for android builds using '-DOS=android'

This additionally resolves problems caused by the OS variable being
rewritten from "android" to "linux" in gyp. This causes errors, as
real-time support (-lrt) and pthread support (-lpthread) is not
available in the android NDK toolchain as libraries.

The functions present in these libraries are included automatically
during the build instead during the android compilation process.
2013-06-13 21:04:03 +02:00
Bert Belder
7d8504cf69 queue: fix pointer truncation on LLP64 platforms
QUEUE_DATA used to cast a pointer to long and back to pointer. This can
corrupt pointers on systems where the long type isn't large enough to
store pointer, like Windows x64. This commit fixes that.

Fixes #835
2013-06-15 14:08:36 +02:00
Ben Noordhuis
7e8d0e6d9c Merge remote-tracking branch 'origin/v0.10' 2013-06-13 09:05:12 +02:00
Andrei Sedoi
5096f1e096 linux: add support for MIPS 2013-06-13 09:04:15 +02:00
Ben Noordhuis
0c3b061aac Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	src/unix/stream.c
	src/version.c
2013-06-13 02:28:44 +02:00
Ben Noordhuis
72e440d7e1 Now working on v0.10.12 2013-06-12 21:52:05 +02:00
Ben Noordhuis
c3b75406a6 2013.06.13, Version 0.10.11 (Stable)
Changes since version 0.10.10:

* unix: unconditionally stop handle on close (Ben Noordhuis)

* freebsd: don't enable dtrace if it's not available (Brian White)

* build: make HAVE_DTRACE=0 should disable dtrace (Timothy J. Fontaine)

* unix: remove overzealous assert (Ben Noordhuis)

* unix: clear UV_STREAM_SHUTTING after shutdown() (Ben Noordhuis)

* unix: fix busy loop, write if POLLERR or POLLHUP (Ben Noordhuis)
2013-06-12 21:52:01 +02:00
Ben Noordhuis
12210fe578 unix: fix busy loop, write if POLLERR or POLLHUP
This fixes a busy loop by working around a quirk with Linux kernels
<= 2.6.32 where an EPIPE or ECONNRESET error on a file descriptor that
is polled for EPOLLOUT but not EPOLLIN gets reported by epoll_wait() as
just EPOLLERR|EPOLLHUP, like this:

  epoll_wait(5, {{EPOLLERR|EPOLLHUP, {u32=12, u64=12}}}, 1024, 433) = 1

Before this commit, libuv called uv__read() which attempts to read from
the file descriptor.  With newer kernels and on other operating systems
that fails like this:

  read(12, "", 65536)         = -1 EPIPE (Broken pipe)

Which tells libuv there is a connection error and it should notify the
user of that.  On the affected Linux kernels however, the read succeeds
with an EOF:

  read(12, "", 65536)         = 0

Which is subsequently passed on to the user. In most cases, the user
will close the handle and everything is fine.

Node.js however sometimes keeps the handle open in an attempt to flush
pending write requests.  While libuv doesn't officially support this,
unofficially it works...

...except on those older kernels.  Because the kernel keeps waking up
the event loop without setting POLLOUT and because the read calls EOF
but don't error, libuv's I/O state machine doesn't progress.

That's why this commit changes uv__stream_io() to also write pending
data.  While the read() system call doesn't error, the write() system
call will.

Fixes joyent/node#5504.
2013-06-08 04:09:42 +02:00
Ben Noordhuis
536c5f8661 unix: clear UV_STREAM_SHUTTING after shutdown()
Fix a state machine buglet where the UV_STREAM_SHUTTING flag didn't get
cleared.
2013-06-08 03:14:33 +02:00
Ben Noordhuis
3ab354367b unix: remove overzealous assert
Several node.js users are hitting this assert under what appear to be
mostly benign conditions. In other words, it's unclear whether it's
catching real bugs or just has wrong expectations.

An aborting process is rather disruptive so I'm removing the assert
from the stable branch and relanding it in the master branch.
2013-06-07 11:28:32 +02:00
Timothy J Fontaine
f84becc64e build: make HAVE_DTRACE=0 should disable dtrace 2013-06-06 20:32:52 +02:00
Ben Noordhuis
897463326b unix, windows: clean up uv_thread_create()
Make uv_thread_create() and its helper function a little more DRY and
a little less impenetrable.
2013-06-06 11:27:07 +02:00
Ben Noordhuis
43205ed553 unix: remove unused function uv_fatal_error() 2013-06-06 08:54:36 +02:00
Ben Noordhuis
c16ed503b0 Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	AUTHORS
	ChangeLog
	src/unix/stream.c
	src/version.c
2013-06-07 11:41:41 +02:00
Brian White
c8ffee3460 freebsd: don't enable dtrace if it's not available 2013-06-05 22:50:08 +02:00
Ben Noordhuis
8e4b248ca6 unix: unconditionally stop handle on close
Make sure the handle is fully stopped by the time uv__stream_close()
calls uv_read_stop(). Fixes the following assertion:

    Assertion failed: (!uv__io_active(&stream->io_watcher, UV__POLLOUT)
    || !ngx_queue_empty(&stream->write_completed_queue)
    || !ngx_queue_empty(&stream->write_queue)
    || stream->shutdown_req != NULL
    || stream->connect_req != NULL), function uv_read_stop,
    file ../deps/uv/src/unix/stream.c, line 1329.

Fixes joyent/node#5622.
2013-06-05 15:17:01 +02:00
isaacs
e9ae62d13a Now working on v0.10.11 2013-06-04 12:00:31 -07:00
isaacs
0d95a88bd3 2013.06.05, Version 0.10.10 (Stable)
Changes since version 0.10.9:

* include: document uv_update_time() and uv_now() (Ben Noordhuis)

* linux: fix cpu model parsing on newer arm kernels (Ben Noordhuis)

* linux: fix memory leak in uv_cpu_info() error path (Ben Noordhuis)

* linux: don't ignore OOM errors in uv_cpu_info() (Ben Noordhuis)

* unix, windows: move uv_now() to uv-common.c (Ben Noordhuis)

* darwin: make uv_fs_sendfile() respect length param (Wynn Wilkes)
2013-06-04 12:00:29 -07:00
Ben Noordhuis
5b1422ba2b unix: s/ngx-queue.h/queue.h/ in checksparse.sh 2013-06-04 12:25:19 +02:00
Ben Noordhuis
c766dfe815 src: make queue.h c++ compatible
Squelch a warning about a cast from void* to another pointer type.
It's legal C but not legal C++. Makes queue.h usable in node.js.
2013-06-04 12:20:40 +02:00
Ben Noordhuis
eb1f60c022 build: fix build breakage from 3fdd2a1
Make sure the android_build variable is defined.
2013-05-31 17:18:22 +02:00
Linus Mårtensson
3fdd2a1128 uv: support android libuv standalone build
Tested most of my compilation in the previous patch on NodeJS
and extracted the patches from there. This patch ensures libuv
will be capable of building standalone as well, both with gyp
and Makefiles.

Build documentation was added to the README.md file.

Some tests are failing, and I have not heavily investigated
the reasons. The failures are generally on errors, and are
likely related to differences between fully POSIX-compatible
systems and android.
2013-05-31 13:25:17 +02:00
Ben Noordhuis
ede83188f3 test: don't use S_IREAD and S_IWRITE
They're BSD-isms and obsolete ones at that. Replace with S_IRUSR and
S_IWUSR. Alias as _S_IREAD and _S_IWRITE on Windows because the '90s
never ended in Redmond, WA.
2013-05-31 12:50:19 +02:00
Bert Belder
b9eb402fb0 include: remove lame comment from uv.h 2013-05-30 22:54:44 +02:00
Ben Noordhuis
442d11d618 unix: avoid extra read, short-circuit on POLLHUP
Avoid going through an extra alloc_cb -> read() -> read_cb cycle when
the POLLHUP flag is set because we know the next read() will hit EOF.

Fixes #803.
2013-05-30 22:34:03 +02:00
Wynn Wilkes
b4c658c3c0 darwin: make uv_fs_sendfile() respect length param
The darwin sendfile implementation uses the &len parameter as input
and output. The code was sending 0 (not using the value of req->len)
so the behavior wasn't what the caller was expecting.

This makes sure to initialize len with req->len to ensure that the
caller can send portions of a file (not always everything to the
end of the file).
2013-05-29 22:25:43 +02:00
Bert Belder
081f7018ec test: use c-style comments
Fixes a compilation problem on OS X caused by the use of c++-style
comments in test-osx-select.c.
2013-05-29 18:32:25 +03:00
Ben Noordhuis
e0bdb3dbc9 unix, windows: move uv_now() to uv-common.c 2013-05-29 16:13:34 +02:00
Ben Noordhuis
b93cf8b594 linux: don't ignore OOM errors in uv_cpu_info() 2013-05-29 01:43:05 +02:00
Ben Noordhuis
31282a97e7 linux: fix memory leak in uv_cpu_info() error path
Any memory allocated to hold CPU model strings wasn't freed on error.
2013-05-29 01:43:05 +02:00
Ben Noordhuis
92c72f58bf linux: fix cpu model parsing on newer arm kernels
The format of /proc/cpuinfo on ARM kernels >= 3.8 has changed. Scan for
the string "model name" (like x86) first, "Processor" second.

Fixes #812.
2013-05-29 01:40:09 +02:00
Ben Noordhuis
dfff2e9e23 include: document uv_update_time() and uv_now() 2013-05-28 23:49:09 +02:00
isaacs
21c12b824a Now working on v0.10.10 2013-05-28 12:08:49 -07:00
isaacs
a195f9ace2 2013.05.29, Version 0.10.9 (Stable)
Changes since version 0.10.8:

* unix: fix stream refcounting buglet (Ben Noordhuis)

* unix: remove erroneous asserts (Ben Noordhuis)

* unix: add uv__is_closing() macro (Ben Noordhuis)

* unix: stop stream POLLOUT watcher on write error (Ben Noordhuis)
2013-05-28 12:08:46 -07:00
Ben Noordhuis
b329d51ef4 unix: stop stream POLLOUT watcher on write error
The node.js test suite sometimes hits the assert that was added in
commit 4146805 that checks if there are connect, write or shutdown
requests pending when the user calls uv_read_stop() while the stream
is primed for writing.

The libuv user (i.e. node.js) is supposed to close the stream on error.
Because uv__stream_close() calls uv_read_stop(), it's possible that the
POLLOUT watcher is still active.
2013-05-27 00:28:37 +02:00
Ben Noordhuis
8e16f8e056 unix: add uv__is_closing() macro 2013-05-26 23:02:17 +02:00
Linus Mårtensson
fc6a2ad24f unix: support for android builds
Adds targets and fixes to ensure building for android works.

To build on android, refer to the android standalone toolchain.
2013-05-25 21:16:52 +02:00
Ben Noordhuis
a8da229f84 build: remove CSTDFLAG, use only CFLAGS 2013-05-30 16:14:26 +02:00
Ben Noordhuis
2c2327be39 doc: explain how to build a .so 2013-05-30 02:28:06 +02:00
Bert Belder
bec8f3cb24 Now working on v0.11.5 2013-05-30 01:01:23 +02:00
Bert Belder
e43e5b3d95 2013.05.30, Version 0.11.4 (Unstable)
Changes since version 0.11.3:

* windows: make uv_spawn not fail when the libuv embedding application
  is run under external job control (Bert Belder)

* darwin: assume CFRunLoopStop() isn't thread-safe, fixing a race
  condition when stopping the 'stdin select hack' thread (Fedor Indutny)

* win: fix UV_EALREADY not being reported correctly to the libuv user in
  some cases (Bert Belder)

* darwin: make the uv__cf_loop_runner and uv__cf_loop_cb functions
  static (Ben Noordhuis)

* darwin: task_info() cannot fail (Ben Noordhuis)

* unix: add error mapping for ENETDOWN (Ben Noordhuis)

* unix: implicitly signal write errors to the libuv user (Ben Noordhuis)

* unix: fix assertion error on signal pipe overflow (Bert Belder)

* unix: turn off POLLOUT after stream connect (Ben Noordhuis)

* unix: fix stream refcounting buglet (Ben Noordhuis)

* unix: remove assert statements that are no longer correct (Ben
  Noordhuis)

* unix: appease warning about non-standard `inline` (Sean Silva)

* unix: add uv__is_closing() macro (Ben Noordhuis)

* unix: stop stream POLLOUT watcher on write error (Ben Noordhuis)

* include: document uv_update_time() and uv_now() (Ben Noordhuis)

* linux: fix cpu model parsing on newer arm kernels (Ben Noordhuis)

* linux: fix a memory leak in uv_cpu_info() error path (Ben Noordhuis)

* linux: don't ignore out-of-memory errors in uv_cpu_info() (Ben
  Noordhuis)

* unix, windows: move uv_now() to uv-common.c (Ben Noordhuis)

* test: fix a compilation problem in test-osx-select.c that was caused
  by the use of c-style comments (Bert Belder)

* darwin: use uv_fs_sendfile() use the sendfile api correctly (Wynn
  Wilkes)

* windows: call idle handles on every loop iteration, something the unix
  implementation already did (Bert Belder)

* test: update the idle-starvation test to verify that idle handles are
  called in every loop iteration (Bert Belder)

* unix, windows: ensure that uv_run() in RUN_ONCE mode calls timers that
  expire after blocking (Ben Noordhuis)
2013-05-30 01:00:55 +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
8ef9592a95 Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	ChangeLog
	src/unix/stream.c
	src/version.c
2013-05-29 23:32:07 +02:00
Bert Belder
b5cd78ea05 test: reflect new idle semantics in test
Update the `idle_starvation` test to verify not only that idle callbacks
are called, but also that they are called once per loop iteration.
2013-05-29 22:52:06 +02:00
Bert Belder
bc56a4e05c windows: call idle handles on every loop iteration
This mimicks what the unix implementation does: call idle handles on
every loop iteration. The guarantee that it runs on every loop iteration
makes it easier to predict and opens up more use cases.

Note that the name uv_idle is now a bit of a misnomer. There is
actually no guarantee that libuv completely processed all i/o
when an iteration ends. The windows implementation at least limits
the amount of callbacks processed in a single iteration to avoid some
handles getting a disproportionate amount of cpu attention.
2013-05-29 22:50:59 +02:00
Sean Silva
c39648674c unix: appease warning about non-standard inline
Clang warns about using `inline`, which is not technically allowed in
C89 mode (libuv compiles with `-std=c89`). It's probably best to leave
it to the compiler to do the inlining anyway.
2013-05-25 13:08:05 +02:00
Ben Noordhuis
b38c9c1004 unix: remove erroneous asserts
As of commit c53fe81, it's legal for write_queue_size > 0 when the
write_queue itself is empty. Sounds illogical but it means there are
error-state write requests in the write_completed_queue that will touch
up the write_queue_size on the next tick of the event loop.

Remove a few stray asserts that still checked for the old situation.
2013-05-25 02:36:58 +02:00
Ben Noordhuis
636a13b8c4 unix: fix stream refcounting buglet
Fix a buglet where uv_read_stop() would mark the handle as stopped even
when there are in-progress write requests.

This bug is unlikely to have affected anyone, the only case where it
has a user-visible effect is when:

  a) the handle has been stopped for reading but not writing, and
  b) it's the last active handle in the event loop's pollset

If both conditions are met, it's possible for the event loop to
terminate prematurely.

This reapplies commit 80f2f82 which was temporarily reverted in fe7b154
because it was making a lot of node.js tests fail on OS X with the
following assertion:

    Assertion failed: (!uv__is_active(handle)), function
    uv__finish_close, file ../../deps/uv/src/unix/core.c, line 165.

Expecting that the handle is inactive when the state is UV_CLOSING
turns out to be a bad assumption: it's possible that the handle is
executing (for example) a shutdown request when uv__finish_close()
is called. That's okay, uv__stream_destroy() takes care of that.

The issue wasn't specific to OS X, it was just more visible on that
platform. (Slow) debug builds on Linux exhibited the same behavior.
2013-05-25 01:30:05 +02:00