Commit Graph

1189 Commits

Author SHA1 Message Date
Ben Noordhuis
492efb95ff unix: make uv_stop work when embedded
* Make uv_stop() work when libuv is embedded in another event loop.

* Fix a small bug where loop->stop_flag was not reset when mode ==
  UV_RUN_ONCE or UV_RUN_NOWAIT. The next call to uv_run() would return
  immediately without doing any work.
2013-02-25 17:01:02 +01:00
Saúl Ibarra Corretgé
bb3d1e24da unix, windows: add uv_stop, stop running event loop 2013-02-25 16:21:37 +01:00
Saúl Ibarra Corretgé
79880121ce windows: align uv_run code with unix 2013-02-25 16:21:28 +01:00
Ben Noordhuis
39c8a90a91 unix: set errno in sendfile emulation
The sendfile emulation in src/unix/fs.c polls the file descriptor for
write readiness. If POLLERR or POLLHUP is set, it bails out but doesn't
set errno (hence it doesn't report a useful error code). Rectify that.

Fixes #620.
2013-02-25 03:22:11 +01:00
Ben Noordhuis
b04fc33ef7 linux: use eventfds for async handles
Use eventfds to drive async handles, fall back to regular pipes on older
kernels (pre-2.6.22).

Gives a nice boost on the async handle benchmarks. Before:

  12,516,113 async events in 5.0 seconds (2,503,222/s, 1,048,576 unique
  async1: 11.95 sec (83,701/sec)
  async2: 11.65 sec (85,862/sec)
  async4: 5.20 sec (192,154/sec)
  async8: 9.97 sec (100,315/sec)
  async_pummel_1: 1,000,000 callbacks in 2.56 seconds (389,919/sec)
  async_pummel_2: 1,000,000 callbacks in 2.65 seconds (377,205/sec)
  async_pummel_4: 1,000,000 callbacks in 2.18 seconds (457,704/sec)
  async_pummel_8: 1,000,000 callbacks in 4.19 seconds (238,632/sec)

After:

  16,168,081 async events in 5.0 seconds (3,233,616/s, 1,048,576 unique
  async1: 11.08 sec (90,213/sec)
  async2: 10.17 sec (98,297/sec)
  async4: 4.81 sec (207,789/sec)
  async8: 8.98 sec (111,419/sec)
  async_pummel_1: 1,000,000 callbacks in 1.16 seconds (863,296/sec)
  async_pummel_2: 1,000,000 callbacks in 1.45 seconds (691,459/sec)
  async_pummel_4: 1,000,000 callbacks in 0.66 seconds (1,514,770/sec)
  async_pummel_8: 1,000,000 callbacks in 1.42 seconds (704,549/sec)

That's a speedup from anywhere between 10% to 330%.
2013-02-25 02:55:24 +01:00
Ben Noordhuis
92151658eb unix: abstract away async pipe infrastructure
This commit lays the groundwork for the switch to eventfds on Linux.
2013-02-25 02:36:52 +01:00
Ben Noordhuis
e89aced8d6 darwin: implement uv_set_process_title, part 2
Make changes to the process title visible to tools like `ps`.

The argv clobber technique is reasonably portable across Unices;
the common code has been moved into src/unix/proctitle.c and is used
on Linux and OS X. Other platforms will probably follow in the future.
2013-02-24 03:56:02 +01:00
Ben Noordhuis
14eb8b0391 darwin: implement uv_set_process_title, part 1
Apply undocumented Carbon magic to change the process title in a way
that's visible in the Activity Monitor.
2013-02-24 03:54:02 +01:00
Ben Noordhuis
c98083ef26 unix: short-circuit on no-op io watcher changes
Don't add the io watcher to the watcher queue if the requested change
is effectively a no-op, that is, when the event mask doesn't change.

The exception here is sunos because the event ports backend requires
that watched file descriptors are re-added on every turn of the event
loop.

This commit is a micro-optimization, it does not change the event
loop's observable behavior in any way.
2013-02-22 17:02:05 +01:00
Ben Noordhuis
da0b84d4e8 unix: auto-unref spawn handle on process exit
Consistent, for better or worse, with uv-win.

Fixes #718.
2013-02-22 14:39:40 +01:00
Ben Noordhuis
3348cd7407 unix: handle EINPROGRESS for unix sockets
Before this commit, it was assumed that connect() on UNIX sockets never
returns EINPROGRESS. It turned out to be a bad assumption: Dave Pacheco
reports sporadic hangups on SmartOS because of that.

It's not clear to me _why_ the Illumos kernel returns that error but
that's inconsequential: whatever the cause, libuv needs to handle it
and now it does.

Fixes joyent/node#4785.
2013-02-21 23:21:29 +01:00
Ben Noordhuis
1d64c8284d unix: use uv__set_artificial_error in uv_write2
* Use uv__set_artificial_error(), slightly more efficient than
  uv__set_sys_error().

* Return UV_EINVAL instead of UV_EOPNOTSUPP.

* Fix up style.
2013-02-21 10:29:17 +01:00
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