Commit Graph

30 Commits

Author SHA1 Message Date
seny
2ee2d4622a
timer: fix uv_timer_start on closing timer
Return `UV_EINVAL` in this case.

Fixes: https://github.com/libuv/libuv/issues/2416
PR-URL: https://github.com/libuv/libuv/pull/2424
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2019-08-23 20:42:37 +02:00
João Reis
427e4c9d48 win: wait for full timeout duration
uv_poll should wait for at least the full timeout duration when there
is nothing else to do. This was not happening because
GetQueuedCompletionStatus can occasionally return up to 15ms early.

The added test reproduces d13d7f74d7/test/simple/test-timers-first-fire.js
on libuv, being flaky before this fix.

Fixes: https://github.com/joyent/node/issues/8960
PR-URL: https://github.com/libuv/libuv/pull/385
Reviewed-By: Alexis Campailla <alexis@janeasystems.com>
Reviewed-by: Bert Belder <bertbelder@gmail.com>
2015-12-16 12:08:46 +01:00
Saúl Ibarra Corretgé
7ff52b836d unix, windows: don't allow a NULL callback on timers 2014-09-05 16:59:18 +02:00
Saúl Ibarra Corretgé
db2a9072bc unix, windows: removed unused status parameter
async, timer, prepare, idle and check handles don't need the status
parameter.
2014-03-17 21:42:36 +01:00
Ben Noordhuis
d7115f0677 unix, windows: make uv_is_*() always return 0 or 1
Ensure that the following API functions always return either 0 or 1:

  * uv_is_active()
  * uv_is_closing()
  * uv_is_readable()
  * uv_is_writable()
2013-09-12 13:30:06 +02:00
Ben Noordhuis
f6d8ba3c9a unix, windows: run expired timers in run-once mode
Before this commit, creating an event loop, starting a timer and
calling uv_run(UV_RUN_ONCE) blocked in uv_run() until the timer
expired - but didn't actually run the timer.
2013-05-30 00:33:23 +02:00
Ben Noordhuis
9b619396d9 unix: make timers handle large timeouts
This commit fixes two closely related integer overflow bugs:

* Timers with a timeout > INT_MAX cause uv__next_timeout() to return
  a negative value.

* Timers with very large timeouts (close or equal to ULLONG_MAX) run on
  the next tick.

In both cases, clamp the values to prevent the overflow from happening.

Fixes joyent/node#5101.
2013-03-21 14:54:36 +01:00
Brian Mazza
77cb29a723 unix: make uv_timer_init() initialize repeat
uv_timer_get_repeat() should return 0 for timers that haven't been
started.
2013-03-19 23:15:30 +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
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
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
894a8523cb test: fix signed/unsigned comparison warnings 2012-11-02 14:32:14 +01:00
Bert Belder
47eb03490a test: move loop cleanup code to the individual tests 2012-10-17 01:24:49 +02:00
Ben Noordhuis
028fef84b8 unix: update timer if already active
uv_timer_start() no longer returns an error when the timer is already active,
now it just updates the timer. Consistent with the uv-win implementation.

Fixes #425.
2012-05-26 02:09:59 +02:00
Ben Noordhuis
ae9d4c2aab test: add 'is active?' checks to test-timer.c 2012-05-26 01:57:49 +02:00
Ben Noordhuis
9efa8b3571 unix, windows: rework reference counting scheme
This commit changes how the event loop determines if it needs to stay alive.

Previously, an internal counter was increased whenever a handle got created
and decreased again when the handle was closed.

While conceptually simple, it turned out hard to work with: you often want
to keep the event loop alive only if the handle is actually doing something.
Stopped or inactive handles were a frequent source of hanging event loops.

That's why this commit changes the reference counting scheme to a model where
a handle only references the event loop when it's active. 'Active' means
different things for different handle types, e.g.:

 * timers: ticking
 * sockets: reading, writing or listening
 * processes: always active (for now, subject to change)
 * idle, check, prepare: only active when started

This commit also changes how the uv_ref() and uv_unref() functions work: they
now operate on the level of individual handles, not the whole event loop.

The Windows implementation was done by Bert Belder.
2012-05-17 07:07:53 +02:00
Ben Noordhuis
dd7e6f0163 test: don't use malloc/free in test-timer 2012-01-18 19:00:55 +01:00
Ben Noordhuis
ac218a7ed5 test: add lots of refcount tests 2012-01-14 00:22:20 +01:00
Ryan Dahl
3e5aa06c49 Add two timer ref count tests 2011-09-26 22:01:21 -07:00
Bert Belder
0dc564a2aa Remove uv_init calls from tests and benchmarks 2011-09-12 11:32:41 -07:00
Bert Belder
3aec77f9d4 bring back uv_init 2011-08-31 04:19:07 +02:00
Ryan Dahl
56dcaf9b06 unix: multiplicity 2011-08-31 04:18:55 +02:00
Ryan Dahl
ce8ff3031c src/ and include/ directories
Helps #71 but does not update the MSVC files.
2011-07-07 07:52:57 -07:00
Bert Belder
4eb06151bd Split up uv_loop type 2011-06-17 23:00:39 +02:00
Ryan Dahl
04b6aaeb44 API Change: Move close_cb to uv_close from init functions 2011-06-08 05:44:22 -07:00
Ryan Dahl
7db9629f87 API Change: Remove data parameters from init functions 2011-06-08 05:43:02 -07:00
Ryan Dahl
7770b1a1f6 API change: alloc_cb moved to uv_read_start()
Fixes #47.
2011-06-03 02:30:00 -07:00
Ryan Dahl
11a4ad50c8 Separate out uv_handle_t into different types
Fixes #4
2011-06-03 11:03:52 +02:00
Ryan Dahl
816289ae8f unix: implement timers
currently loop_handles is broken.
2011-05-16 17:08:43 -07:00
Bert Belder
810651e04c Update tests & benchmarks to use the new timer api 2011-05-17 01:17:48 +02:00