Commit Graph

1075 Commits

Author SHA1 Message Date
Stephen Gallagher
e318b06a0e include: split off libev function prototypes
This patch creates a new header - ev-proto.h - which contains all of the
protoypes for libev functions. This allows us to create a shared object of
libuv without exposing libev internal functions.
2012-11-07 16:55:49 +01:00
Ben Noordhuis
a7cedbe220 darwin: fix uv_hrtime() thread safety issue 2012-11-07 16:20:18 +01:00
Bert Belder
0097280624 windows: map ERROR_GEN_FAILURE to UV_EIO 2012-11-07 11:11:23 +01:00
Ben Noordhuis
0ddf9d6b98 Revert "unix: use select() for specific fds on OS X"
This reverts commit 5da380a5ca.

Contains a bug that effectively makes the select() thread busy-loop. The file
descriptor is polled for both reading and writing, regardless of what events
the main thread wants to receive. Fixing that requires proper synchronization
between the two threads.

See #614.
2012-11-04 01:23:12 +01:00
Ben Noordhuis
20bb1bfd70 Revert "unix: reopen tty as /dev/tty"
This reverts commit 31f9fbce63.

The reverted commit depends on commit 5da380a ("use select() for specific fds
on OS X") which polls /dev/tty file descriptors in a separate thread to work
around deficiencies in the kqueue API on OS X.

Unfortunately, 5da380a has a bug that effectively makes the select() thread
busy-loop. Revert this commit for now.
2012-11-04 01:07:14 +01:00
Ben Noordhuis
914185d6fc unix: make some internal methods static 2012-11-03 02:06:42 +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
Ben Noordhuis
9c7ae2e7a3 darwin: don't use deprecated AbsoluteToNanoseconds 2012-11-02 14:23:26 +01:00
Ben Noordhuis
be597ba625 unix: set req type to UV_FS 2012-11-02 14:23:23 +01:00
Ben Noordhuis
b0bcbdfe81 unix: NULL pipe_fname in uv__pipe_close()
Pro-actively avoid use-after-free errors, set the pipe_fname field to NULL.
2012-11-01 15:51:06 +01:00
Leonard Hecker
97c527ac43 darwin: make it possible to compile for iOS
Relocate the include of TargetConditionals.h and fixe the use of
TARGET_OS_IPHONE. Furthermore, uv__fsevents_init() and uv__fsevents_close are
now empty functions for iOS, since the FSEvents API is not available there.
2012-10-29 23:45:52 +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
Ben Noordhuis
6150feda56 unix: fix ‘fd’ undeclared build error
Reapplies commit b5028c5b, failed to merge in 5cb4197.
2012-10-25 12:50:40 +02:00
Ben Noordhuis
5cb4197deb Merge branch 'v0.8' 2012-10-25 04:43:19 +02:00
Ben Noordhuis
31f9fbce63 unix: reopen tty as /dev/tty
Reopen the file descriptor when it refers to a tty. This lets us put the tty in
non-blocking mode without affecting other processes that share it with us.

Fixes #601.
2012-10-24 15:39:11 +02:00
Ben Noordhuis
b7f38b1e53 Revert "unix: avoid iterating over all async handles"
This reverts commit 209abbab27.

Fixes the following SIGSEGV:

  (gdb) f 1
  #1  0x00007fc084683aec in uv__async_io (loop=0x7fc0848e0b40,
  handle=0x7fc0848e0c78, events=1) at src/unix/async.c:175
  175             ASYNC_CB(h)
  (gdb) list
  170
  171         /* If we need to sweep all handles anyway - skip this loop */
  172         if (!loop->async_sweep_needed) {
  173           for (i = 0; i < end; i += sizeof(h)) {
  174             h = *((uv_async_t**) (buf + i));
  175             ASYNC_CB(h)
  176           }
  177         }
  178
  179         bytes -= end;
  (gdb) print *h
  $1 = {close_cb = 0x184e1b0, data = 0x18d9520, loop = 0x7fc0848e0b40,
  type = 49, handle_queue = {prev = 0x18dae10, next = 0x7860c0}, flags = 32,
  next_closing = 0x1863b40, pending = 0, async_cb = 0x31,
  queue = {prev = 0x18dae50, next = 0x7860c0}}
  (gdb)

It looks like the async handle gets closed or otherwise becomes invalid before
the sweep is executed.

Fixes #603.
2012-10-24 14:58:49 +02:00
saghul
61ecb3415d win: support compilation with Visual Studio 2008 2012-10-23 22:55:25 +02:00
Ben Noordhuis
c2478b2669 linux: update comm field in uv_set_process_title()
Makes the new process name visible in both `ps` and `ps a`, with the caveat
that `ps` will only print the first 16 characters.

Before this commit, `ps` kept reporting the old process name.
2012-10-22 13:44:56 +02:00
Ben Noordhuis
775064a3a5 linux: use /proc/cpuinfo for CPU frequency
Obtain the CPU frequency from /proc/cpuinfo because there may not be any
cpufreq info available in /sys. This also means that the reported CPU speed
from now on is the *maximum* speed, not the *actual* speed the CPU runs at.

This change only applies to x86 because ARM and MIPS don't report that
information in /proc/cpuinfo.

Fixes #588.
2012-10-21 00:08:21 +02:00
Ben Noordhuis
1bb1ba27dd unix: fix compiler warning in async.c
Include missing <string.h> header. Fixes the following compiler warning:

  src/unix/async.c:182:7: warning: implicit declaration of
  function ‘memmove’ [-Wimplicit-function-declaration]
2012-10-20 23:36:00 +02:00
Fedor Indutny
209abbab27 unix: avoid iterating over all async handles 2012-10-19 17:22:30 +02:00
Bert Belder
1e32cb01b5 unix: support signal handlers outside the main loop 2012-10-17 01:25:02 +02:00
Bert Belder
39d574dcff unix: make it possible to delay close callbacks 2012-10-17 01:25:00 +02:00
Ben Noordhuis
fd136da04a unix: remove always_inline attribute
Fixes the following gcc 4.7+ warning:

  ../src/unix/internal.h:105:13: warning: always_inline function might not be
  inlinable [-Wattributes]

gcc wants the always_inline function to be annotated with the 'inline' keyword
which we can't do because we compile in C89 mode.

Using __inline is not an option because that makes clang generate warnings when
-Wlanguage-extension-token is enabled.

Therefore, remove the always_inline attribute altogether and hope that the
compiler is smart enough to inline the functions.
2012-10-15 01:08:47 +02:00
saghul
9a6f496985 win: fix compilation with MSVCRT < 8.0 2012-10-11 00:59:43 +02:00
Bert Belder
b0c1a3803a windows: fix handle leak in uv_fs_utime 2012-10-10 17:15:25 +02:00
Ben Noordhuis
cb03e3bd26 darwin: work around concurrent write() kernel bug
Simultaneously writing from multiple threads to the same file descriptor is not
safe on OS X. We already serialized all pwrite() system calls, apply the same
workaround to the write() system call.

Fixes a node.js test, test/simple/test-fs-sir-writes-alot.js, that was failing
because parts of the output file got filled with nul bytes.
2012-10-10 02:15:54 +02:00
Ben Noordhuis
4affbe70b6 unix: remove unnecessary pthread_join ESRCH check
ESRCH means the thread never got started but we guard against that now.
2012-10-10 01:11:09 +02:00
Hiroaki Nakamura
acea3028c5 unix, windows: add thread barrier support 2012-10-09 17:30:52 +02:00
Ben Noordhuis
40134c3537 unix: don't reap threads if none were started
Fixes a segmentation fault on 32 bits linux with glibc 2.15.

Thanks to Johan Bergström (@jbergstroem) for reporting the issue and testing
out the patch.
2012-10-08 00:37:03 +02:00
Ben Noordhuis
b9ed1a6dbf unix: don't abort() on EINVAL in threadpool.c
The FreeBSD implementation of pthread_join() returns EINVAL when a thread has
already quit, not ESRCH.
2012-10-06 22:58:28 +02:00
Ben Noordhuis
b152b12772 unix: fix scandir filter prototype again
The only platforms where the dirent argument is non-const are OS X, OpenBSD
and older versions of FreeBSD (but not FreeBSD 9). Accommodate the first two.
2012-10-06 22:25:58 +02:00
Ben Noordhuis
7833df14ba freebsd, openbsd: don't use fdatasync()
The fdatasync() system call does not exist on either FreeBSD or OpenBSD, fall
back to fsync().
2012-10-06 17:19:12 +02:00
Hiroaki Nakamura
976c8a4387 Add support for condition variables on all platforms 2012-10-05 13:03:55 +02:00
Bert Belder
744dc3e77c windows: make uv_rwlock_init initialize libuv
Without this patch, the fallback implementation would be used if
uv_rwlock_init were to be called before a loop was created or
uv_default_loop() was called.
2012-10-04 01:21:30 +02:00
Artur Adib
fed718c6cb unix: move queue stuff from fs.c to threadpool.c 2012-10-03 23:56:01 +02:00
Ben Noordhuis
c666b6310d unix: fix uninitialized memory read in uv__read()
This commit fixes the following valgrind warning:

  ==26443== Conditional jump or move depends on uninitialised value(s)
  ==26443==    at 0x44AAFF: uv__read (stream.c:872)
  ==26443==    by 0x44ADD4: uv__stream_io (stream.c:1051)
  ==26443==    by 0x4377B8: uv__io_rw (core.c:539)
  ==26443==    by 0x43C761: ev_invoke_pending (ev.c:2145)
  ==26443==    by 0x43724D: uv__poll (core.c:260)
  ==26443==    by 0x437297: uv__run (core.c:269)
  ==26443==    by 0x4372F6: uv_run (core.c:277)
  ==26443==    by 0x42094B: run_test_pipe_ref4 (test-ref.c:334)
  ==26443==    by 0x406551: run_test_part (runner.c:302)
  ==26443==    by 0x405384: main (run-tests.c:57)
2012-10-03 00:03:01 +02:00
Ben Noordhuis
b37a0f5bb3 unix: fix small race in fs.c
Don't return req->result after posting the work request. It's possible (if
unlikely) for a worker thread to process the request before the main thread
reaches the return statement.
2012-10-02 23:06:08 +02:00
Ben Noordhuis
3977d1b36c unix: emulate sendfile if necessary
Some platforms don't support sendfile() (netbsd, openbsd), others don't support
arbitrary file descriptors (freebsd, darwin) and yet others have quirks in their
implementation (sunos).

Work around the quirks. If all else fails, fall back to sendfile() emulation.
2012-10-02 22:50:42 +02:00
Ben Noordhuis
2d3760a17c unix: fix scandir filter prototype
The dirent argument is const on systems that conform to POSIX.2008 (Linux and
Solaris) but non-const on others.
2012-10-02 14:40:27 +02:00
Ben Noordhuis
d36e2f21cf unix: fix buffer overrun in fs.c 2012-10-01 23:50:58 +02:00
Ben Noordhuis
6342658ad8 unix, windows: fix memory leak in fs-poll.c
The internal timer handle associated with the uv_fs_poll_t wasn't always closed
when the fs poll handle was closed, leaking about 650 bytes memory.
2012-10-01 23:43:32 +02:00
Ben Noordhuis
7320633c4b unix: remove uv_fs_stat windows compat hack
uv_fs_stat and uv_fs_lstat removed the trailing backslash (if any) from the path
in order to please a test case that was written for Windows. Remove the
compatibility hack and fix the test.
2012-10-01 22:53:59 +02:00
Ben Noordhuis
b60a24a206 unix: remove libeio 2012-10-01 22:53:59 +02:00
Ben Noordhuis
74999f8f99 unix: port fs and work api to new thread pool 2012-10-01 22:53:59 +02:00
Ben Noordhuis
36c91e3ba0 unix: port getaddrinfo to new thread pool 2012-10-01 22:53:59 +02:00
Ben Noordhuis
f35a4b628a unix: add custom thread pool 2012-10-01 22:53:59 +02:00
Ben Noordhuis
5e09e1b57e linux: please valgrind, free memory at exit
Free the memory that is used to store the new argv and envp. It's not strictly
necessary (the OS is going to reclaim the memory anyway) but it makes the output
from valgrind a lot less noisy.
2012-10-01 22:53:59 +02:00
Ben Noordhuis
7ac23ee0c6 unix: move getaddrinfo code to getaddrinfo.c 2012-09-28 08:05:53 +02:00
Ben Noordhuis
4f8e2a8e8e unix: close async pipe fds on loop delete 2012-09-28 07:44:40 +02:00