Commit Graph

1177 Commits

Author SHA1 Message Date
Saúl Ibarra Corretgé
9a8db3c0cb unix: reduce line count, return uv__set_sys_error 2013-02-21 10:26:12 +01:00
Saúl Ibarra Corretgé
3f47a2da5c unix: fail early on bad send_handle in uv_write2
Return UV_EBADF if send_handle doesn't have a valid fd.
2013-02-21 10:25:20 +01:00
Ben Noordhuis
26fa6f8031 linux: fix abort() on epoll_ctl() race condition
Don't check the return value of epoll_ctl(EPOLL_CTL_DEL). When the
file descriptor is closed, we're potentially racing with another
thread and that means the errno is not a reliable indicator of
the actual error.

The other event mechanisms (kqueue, event ports) are not affected
because:

* kqueue returns either EBADF or ENOENT. Both are handled by libuv.
* event ports rearms all file descriptors on each call to port_getn().

Fixes joyent/node#4558.
2013-02-20 21:28:39 +01:00
Ben Noordhuis
30f6288347 unix, windows: make uv_timer_get_repeat() const correct 2013-02-20 17:01:00 +01:00
Ben Noordhuis
0cb9fbfe18 unix, windows: change timer intervals to uint64_t 2013-02-20 16:59:33 +01:00
Ben Noordhuis
d6bfedb862 unix, windows: make uv_now() return uint64_t
Using int64_t doesn't make sense here because the return value is never
negative.
2013-02-20 16:58:45 +01:00
Andrius Bentkus
6bf1a56e9d Return the errorcode provided by uv_set_artificial_error.
This reduces the line count.
2013-02-20 16:36:22 +01:00
Ben Noordhuis
b6f72e54c4 linux: fix O_CLOEXEC/O_NONBLOCK defines 2013-02-12 16:18:38 +01:00
Ben Noordhuis
da71649991 unix, windows: make uv_fs_t.statbuf public
Make the statbuf field public. This means you no longer have to use
req->ptr - though that still works and will continue to work for the
foreseeable future.

Fixes #704.
2013-02-10 17:50:03 +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
Fedor Indutny
c15d4a7c62 stream: use kevent() information before accept()
Limit number of syscalls by using backlog length information provided by
kevent().
2013-02-09 00:54:08 +04:00
Ben Noordhuis
da33bba7c0 darwin: make uv_cond_timedwait() clock skew safe
Use pthread_cond_timedwait_relative_np() so we're not prone to spurious
bugs caused by clock skew.
2013-02-06 23:28:09 +01:00
Ben Noordhuis
d5dd7d0758 darwin: merge uv_cond_timedwait implementation
This is a revised version of commit 8311390.
2013-02-06 20:38:21 +01:00
Ben Noordhuis
8d746ff72d unix: remove scandir prototype workaround in fs.c
It's not necessary for newer OS X releases and I don't care enough
about OpenBSD to squelch the warning.
2013-02-06 16:32:05 +01:00
Ben Noordhuis
60dd395a5b Revert "darwin: merge uv_cond_timedwait implementation"
Using mach_absolute_time() for the pthread_cond_timedwait() timeout
breaks a number of tests on OS X 10.8.2.

This reverts commit 8311390f13.
2013-02-06 16:09:07 +01:00
Ben Noordhuis
8311390f13 darwin: merge uv_cond_timedwait implementation
Merge the OS X specific implementation of uv_cond_timedwait() with the
generic one. The only difference is that it now uses mach_absolute_time
instead of gettimeofday.
2013-02-04 20:24:21 +01:00
Ben Noordhuis
7f3c783583 unix: don't clobber errno in signal handler 2013-01-31 15:28:16 +01:00
Bert Belder
3759d71269 win: get rid of early ipv6 support detection
No longer explictly check wheter an IPv6 stack is present when the user
tries to use IPV6 sockets. Instead realy on the operating system
to report the lack of protocol support via appropriate error messages.
2013-01-30 18:27:45 +01:00
Bert Belder
f21d94125e win/udp: DRY up setting SO_REUSEADDR
This patch makes sure that only uv_udp_set_socket sets the SO_REUSEADDR
bit for UDP sockets.
2013-01-30 18:27:44 +01:00
Bert Belder
3d779000b1 win/udp: fix bug in getsockopt() return value check 2013-01-30 18:27:44 +01:00
Bert Belder
4f54053517 win/udp: make uv_udp_set_socket set UV_HANDLE_IPV6
This patch makes uv_udp_set_socket responsible for setting the
UV_HANDLE_IPV6 flag. It also fixes the problem that uv_udp_open would
never set this flag at all.

In addition, this patch fixes some minor style issues.
2013-01-30 18:27:43 +01:00
Bert Belder
40c60cfc54 win/tcp: make uv_tcp_set_socket set UV_HANDLE_IPV6
This makes uv_tcp_set_socket responsible for setting the UV_HANDLE_IPV6
flag. This fixes a couple of situations where the the fact that a socket
is an IPv6 socket is not taken into account when deciding whether a call
to SetFileCompletionNotificationModes is appropriate.

It also fixes the issue that uv_tcp_open would never set this flag at
all.
2013-01-30 18:27:43 +01:00
Bert Belder
cfe14452ae win: fix uv_winsock_init crash when no IPv4 stack present
uv_winsock_init() tries to create an IPv4 socket in order to detect
if the system has any layered service providers (LSPs) installed.
When creating this socket failed it would call uv_fatal_error and exit
with the following message:

  socket: (10047) An address incompatible with the requested protocol was used.

This patch fixes that. It also includes some minor style tweaks.
2013-01-30 18:27:42 +01:00
Bert Belder
00503d6067 win: add error mappings related to unsupported protocols 2013-01-30 18:27:42 +01:00
Bert Belder
98c79f3e0d win: sort error code mappings 2013-01-30 18:27:41 +01:00
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