Commit Graph

1152 Commits

Author SHA1 Message Date
Ben Noordhuis
b607a7fed7 linux: move files out of src/unix/linux
Flattens the source tree and simplifies the Makefile.
2013-01-29 17:07:41 +01:00
Ben Noordhuis
93f61b7c3f unix: fix style issues in udp.c 2013-01-27 14:50:09 +01:00
Bert Belder
e4d8cbac78 unix: support sending uv_udp_t handles over ipc pipes 2013-01-22 23:58:13 +01:00
Andrius Bentkus
bdb498f8b1 unix, windows: return UV_EINVAL, not UV_EFAULT
A wrong multicast membership should return EINVAL.
2013-01-22 15:41:55 +01:00
Andrius Bentkus
017e2d5fde unix, windows: make uv_*_bind() error codes consistent
Just like uv_tcp_connect() it should return an EINVAL when the handle
is of an invalid type or when the network address is faulty.
2013-01-18 12:18:23 +01:00
Ben Noordhuis
372ac34d5f linux: translate futimes() fallback error codes
The fallback added in 9d4a16e uses the /proc filesystem to emulate
utimensat().

Translate error codes that indicate no procfs is mounted to ENOSYS.
Letting those error codes through unchecked will only confuse callers.
2013-01-17 18:43:07 +01:00
Ben Noordhuis
9d4a16eefe linux: add futimes() fallback
The utimensat() syscall was added in 2.6.22. Add a fallback mode for
older kernels that uses utimes("/proc/self/fd/<fd>").

Fixes #687.
2013-01-17 14:22:55 +01:00
Ben Noordhuis
629a59b35b linux: use stdint types in structs
Use the typedefs from stdint.h to avoid build breakage on systems
where __u64 and friends are hidden when --std=c89 is in effect.

Fixes #685.
2013-01-17 01:29:47 +01:00
Ben Noordhuis
4ba03ddd56 unix, windows: rename uv_run2 to uv_run
This changes the prototype of uv_run() from:

  int uv_run(uv_loop_t* loop);

To:

  int uv_run(uv_loop_t* loop, uv_run_mode mode);

Where `mode` is UV_RUN_DEFAULT, UV_RUN_ONCE or UV_RUN_NOWAIT.

Fixes #683.
2013-01-16 23:35:29 +01:00
Ben Noordhuis
768b524639 unix: make stream.c more DRY 2013-01-14 16:53:35 +01:00
Ben Noordhuis
c931e31746 unix: make assertion message more descriptive 2013-01-14 11:32:55 +01:00
Ben Noordhuis
8e3e60ffbf linux: only pack struct uv__epoll_event on x86_64
On i386, it does not need packing; it's 12 bytes packed or unpacked.

On ARM, it's actively harmful: the struct is 12 bytes when packed and
16 bytes when unpacked.
2013-01-13 00:58:05 +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 Noordhuis
fc42885d0e unix: set closed fd to -1, avoid double close bugs
* abort() if close() fails
* set fd to -1 after close() to prevent double close bugs
2013-01-11 13:39:39 +01:00
Ben Noordhuis
2ec2a5194f unix: clean up code in process.c 2013-01-11 13:38:01 +01:00
Ben Noordhuis
6f679a4ff7 unix: don't swap stdin file descriptors
Bug introduced in 47f496a. It turns out the file descriptors of the
stdin pipe don't have to be swapped around.
2013-01-11 13:32:00 +01:00
Ben Noordhuis
80f6a9c643 unix: omit second fcntl() call if possible
Omit the fcntl() syscall when the O_NONBLOCK or FD_CLOEXEC is already
set/clear because it's a no-op in that case.
2013-01-10 01:25:40 +01:00
Tim Bradshaw
bc0c61cd7f linux: ensure that all CPUs have model information 2013-01-08 05:29:21 +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
cb3c448d8f unix: fix GNU-ism introduced in edd1007
Don't use features.h, it's only available on GNU/glibc systems.
2013-01-07 15:43:58 +01:00
Ben Noordhuis
fa9c577e55 linux: fix race in uv_resident_set_memory()
uv_resident_set_memory() used a global buffer to read data into, which
is a decidedly unsafe thing to do in a multi-threaded environment.
2013-01-06 22:31:48 +01:00
Ben Noordhuis
5b63285805 unix, windows: ANSI-fy uv_tty_reset_mode() prototype 2013-01-06 22:31:47 +01:00
Ben Noordhuis
edd10071eb unix: fix up #if defined checks
`#if FOO` (where FOO is undefined) is a legal construct in C89 and C99
but gcc, clang and sparse complain loudly about it at higher warning
levels.

Squelch those warnings. Makes the code more consistent as well.
2013-01-06 22:31:47 +01:00
Ben Noordhuis
e62dd3caa0 unix: fix include in cygwin.c 2013-01-06 21:25:58 +01:00
Ben Noordhuis
a2bedc0a7e unix: make uv__read_start_common() static 2013-01-06 21:25:58 +01:00
Ben Noordhuis
35b159a83e unix: make uv__work_cancel() static 2013-01-06 21:25:58 +01:00
Ben Noordhuis
0a06c2f3b2 unix: fix up function prototypes in signal.c 2013-01-06 21:25:58 +01:00
Ben Noordhuis
87cbf8d0c2 unix: remove unused function uv__strlcpy() 2013-01-06 21:25:58 +01:00
Ben Noordhuis
2f55353490 unix: update loop->time after poll
Fixes a bug where timers expire prematurely when the following
conditions hold:

  a) libuv first spends some time blocked in the platform poll function
  b) a callback then calls uv_timer_start()

Cause: uv_timer_start() uses an out-of-date loop->time in its
'when should the timer callback run?' calculations.

Solution: Update loop->time before invoking any callbacks.

Fixes #678.
2013-01-06 18:30:03 +01:00
Ben Noordhuis
339033afc0 unix: use uv__hrtime() internally
This commit renames the various uv_hrtime() implementations to uv__hrtime().

Libuv uses the high-res timer internally in performance-critical code paths.
Calling the non-public version avoids going through the PLT when libuv is
compiled as a shared object.

The exported uv_hrtime() now has a single definition in src/unix/core.c that
calls uv__hrtime().

A future optimization is to lift the uv__hrtime() declarations into header
files so they can be inlined at the call sites. Then again, linking with -flto
should accomplish the same thing.
2013-01-06 17:35:34 +01:00
Fedor Indutny
ba83510fc0 stream: fix infinite select() polling on osx
Interruption FD buffer should be emptied after write, otherwise select()
loop will poll indefinitely.
2013-01-04 21:10:33 +04:00
Ben Noordhuis
775f2c1f53 unix: remove stale closing check in uv__write()
Introduced in 0db3274f but no longer necessary; uv__write() no longer
runs when the handle has been closed. Write callbacks receive a special
status code that informs them that the handle has been closed.
2013-01-02 18:05:32 +01:00
Ben Noordhuis
a657e7f576 unix: remove uv_write_queue_head() 2013-01-02 17:45:37 +01:00
Ben Noordhuis
0b3ab72579 unix: remove bogus uv__write() comment 2013-01-02 17:15:54 +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é
9614d51135 unix: reset errno when using sendfile emulation
A common way to check if a uv_fs_t request failed is to check that
req->errorno != 0.

With uv_fs_sendfile(), when the sendfile() syscall fails, req->errorno is set
to (for example) ENOTSOCK, even when the emulation code path succeeds.

Zero errno before the call to uv__fs_sendfile_emul() to prevent that from
happening.
2012-12-28 16:00:49 +01:00
Ben Noordhuis
69ab328d9f sunos: fix !defined(PORT_SOURCE_FILE) build 2012-12-28 12:45:47 +01:00
Saúl Ibarra Corretgé
4650a5971b unix: don't run loop when all handles are unref'd 2012-12-24 17:05:52 +01:00
Saúl Ibarra Corretgé
33d5c497a6 prepare/idle/check: don't allow NULL callback 2012-12-24 17:05:01 +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
dc559a5ce6 unix: disable relaxed accept() by default
Don't use the relaxed accept() algorithm introduced in be2a217 unless
explicitly requested. It causes a 50+% performance drop on some node.js
benchmarks:

  $ alias bench='out/Release/node benchmark/http_simple_auto.js \
    -c 10 -n 50000 bytes/1 2>&1 | grep Req'

  $ UV_TCP_SINGLE_ACCEPT=0 bench
  Requests per second:    12331.84 [#/sec] (mean)

  $ UV_TCP_SINGLE_ACCEPT=1 bench
  Requests per second:    3944.63 [#/sec] (mean)
2012-12-18 15:44:21 +01:00
Fedor Indutny
b86ed94940 kqueue: ignore ENOENT error
File descriptor might be closed during callback, all events that was reported
before the callback are not valid and trying to remove them will result
in ENOENT. This error can be safely ignored.
2012-12-18 13:48:46 +04:00
Ben Noordhuis
273cecc56f unix: don't memset(0) in uv_udp_init()
It's inconsistent with other init functions. In particular, it clobbers the
data field.

Fixes #655.
2012-12-15 21:14:39 +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
92fb84b751 unix: rework uv_cancel() api
Bert Belder informs me the current approach where a request is immediately
cancelled, is impossible to implement on Windows.

Rework the API to always invoke the "done" callback with an UV_ECANCELED error
code.
2012-12-13 13:46:38 +01:00
Fedor Indutny
731adacad2 unix: use select() for specific fds on OS X
kqueue(2) on osx doesn't work (emits EINVAL error) with specific fds
(i.e. /dev/tty, /dev/null, etc). When given such descriptors - start
select(2) watcher thread that will emit io events.
2012-12-09 15:43:08 +01:00
Ben Noordhuis
52c8a8617d unix: add uv_cancel() 2012-12-09 15:12:42 +01:00
Ben Noordhuis
a385ae4f59 unix: only set SO_REUSEADDR on tcp listen sockets
Avoid the extra syscall, it's a no-op for non-listening sockets.

At least, it should be - it remains to be investigated if a FreeBSD kernel bug
affects ephemeral port allocation inside connect(). See [1] for details.

[1] http://www.freebsd.org/cgi/query-pr.cgi?pr=174087
2012-12-09 14:34:33 +01:00