Commit Graph

132 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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é
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
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
4a69c4bb5f unix: change uv_backend_timeout() prototype
* change return value to signed int
* constify loop argument
2012-11-28 17:02:30 +01:00
Fedor Indutny
09a7f85b70 unix: add uv_backend_fd() and uv_backend_timeout()
This can be used in conjuction with uv_run_once() to poll in one thread and run
the event loop's event callbacks in another.

Useful for embedding libuv's event loop in another event loop.
2012-11-28 16:30:50 +01:00
Ben Noordhuis
90271e1a3c darwin, freebsd: set SO_NOSIGPIPE on sockets
Suppresses delivery of SIGPIPE signals when the remote end of the socket has
gone away.
2012-11-22 17:51:56 +01:00
Ben Noordhuis
65bb6f068e unix: rename UV__IO_* constants 2012-11-16 17:33:29 +01:00
Ben Noordhuis
1282d64868 unix: remove dependency on libev 2012-11-16 17:33:25 +01: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
7ac23ee0c6 unix: move getaddrinfo code to getaddrinfo.c 2012-09-28 08:05:53 +02:00
Saúl Ibarra Corretgé
b7047d6701 unix: remove __read_mostly macro
It creates trouble with llvm-gcc on OS X.
2012-09-13 01:47:34 +02:00
Ben Noordhuis
b12b6498d6 darwin, freebsd: use ioctl(FIOCLEX) and ioctl(FIONBIO)
Set the non-blocking and close-on-exec flags with ioctl() instead of fcntl(),
it's about 10-25% faster.

Stick with fcntl() on Solaris. ioctl(FIONBIO) works but is twice as slow as
fcntl(O_NONBLOCK). ioctl(FIOCLEX) doesn't raise an error but doesn't actually
work either.
2012-08-21 23:21:37 +02:00
Ben Noordhuis
6545e9bda4 linux: tag no_accept4 __read_mostly 2012-08-21 01:03:59 +02:00
Ben Noordhuis
ee50db6e36 unix, windows: preliminary signal handler support
* a no-op on Windows for now
* only supports the main loop on UNIX (again, for now)
2012-08-10 02:00:07 +02:00
Ben Noordhuis
9f7cdb20aa unix: add relaxed accept() setting
Mitigates unfair scheduling in multi-process setups that share a single listen
socket across multiple processes.
2012-08-02 15:58:55 +02:00
Ben Noordhuis
be1032431d Merge branch 'v0.8' 2012-07-29 03:13:21 +02:00
Ben Noordhuis
889ab216ae unix: fix 'zero handles, one request' busy loop
Fixes #484.
2012-07-01 23:59:30 +02:00
Ben Noordhuis
b779a0db74 Merge branch 'v0.8' 2012-06-29 02:28:57 +02:00
Ben Noordhuis
f6a02fbe76 linux: don't use accept4() syscall after ENOSYS
Repeatedly calling the syscall when it's not supported has a small but
measurable performance impact.

Besides, it's a silly thing to do.
2012-06-29 02:23:47 +02:00
Ben Noordhuis
0fde10825e linux: set close-on-exec flag with ioctl(FIOCLEX)
ioctl(FIOCLEX) is 25% faster than fcntl(F_SETFD) on a stock 2.6.32 kernel.
2012-06-24 06:06:33 +02:00
Ben Noordhuis
e21cdf1e0d unix: malloc only once in uv_getaddrinfo() 2012-06-23 04:09:22 +02:00
Ben Noordhuis
f01e9d708a unix: clarify that uv_getaddrinfo_t is a req 2012-06-22 16:40:45 +02:00
Ben Noordhuis
cc7c8542a5 unix, windows: add stat() based file watcher
Monitors a file path for changes. Supersedes ev_stat.
2012-05-31 20:32:24 +02:00
Ben Noordhuis
4d7f1e1864 unix: implement uv_disable_stdio_inheritance() 2012-06-14 01:20:49 +02:00
Bert Belder
ade6930241 windows: implement uv_disable_stdio_inheritance 2012-06-14 01:19:52 +02:00
Ben Noordhuis
94cb06fecf unix: make uv__nonblock() EINTR resilient
It's underspecified if and when ioctl(FIONBIO) or fcntl() can return EINTR.
Let's take the safe route.
2012-06-14 01:19:34 +02:00
Ben Noordhuis
b3a97f8981 unix: make uv__cloexec() EINTR resilient
It's somewhat underspecified if and when fcntl() can return EINTR. It never
does on Linux for F_GETFD or F_SETFD but let's not make any assumptions.
2012-06-14 01:19:34 +02:00
Ben Noordhuis
95e89c6a0e unix, windows: share uv__handle_init() 2012-06-13 01:28:58 +02:00
Ben Noordhuis
dea45940cd unix: fix req cb / close cb invoke delay
Finalization of closed handles and associated requests was sometimes delayed
until an external event (network I/O, timeout, etc.) happened. This commit
addresses that.
2012-06-08 01:37:39 +02:00
Ben Noordhuis
649ad50c32 unix: fix event loop stall
Undoes most of the changes made to libev in 7d2ea31 and c9396dd.
2012-06-06 05:12:28 +02:00
Ben Noordhuis
7d2ea31618 unix: fix event loop stall
Stop libev from entering the epoll_wait/kevent/port_getn/etc. syscall when
there are no active handles left, that will block indefinitely.
2012-06-04 23:36:50 +02:00
Ben Noordhuis
c9396dd57e unix: implement timers in libuv
* replace libev backed timers with a pure libuv implementation
* gut ev_run() and make it take a timeout instead of flags

Incidentally speeds up the loop_count_timed benchmark by about 100%.
2012-05-31 03:08:34 +02:00
Ben Noordhuis
171ad8567d unix, windows: add uv_walk()
Lets the libuv user iterate over the open handles. Mostly intended as a
debugging tool or a post-hoc cleanup mechanism.
2012-05-30 02:33:39 +02:00
Ben Noordhuis
9d26f49725 unix, windows: rename flags UV__ACTIVE, UV__REF
Rename UV__ACTIVE and UV__REF to UV__HANDLE_ACTIVE and UV__HANDLE_REF to make
it clear that they apply to handles, not requests or loops.
2012-05-30 01:30:24 +02:00
Ben Noordhuis
58a272e556 unix: rework pending handle/req logic 2012-05-30 00:08:22 +02:00
Ben Noordhuis
4690204682 unix: fix getaddrinfo bad pointer deref 2012-05-29 00:06:11 +02:00
Bert Belder
e4f23aacec Get rid of UV_LEAN_AND_MEAN 2012-05-28 01:53:22 +02:00
isaacs
604802ad47 Fix sunos build: undeclared variable 'handle' 2012-05-24 23:00:31 +02:00
Ben Noordhuis
752ac30ec8 unix: don't pass sockaddr to accept()
Shaves a few nanoseconds off the accept() syscall.
2012-05-24 14:31:53 +02:00
Ben Noordhuis
5fd2c406f1 unix: fix up asserts in core.c and stream.c 2012-05-23 22:19:12 +02:00