Changes since version 1.22.0:
* win,pipe: restore compatibility with the old IPC framing protocol (Bert
Belder)
* fs: add uv_open_osfhandle (Bartosz Sosnowski)
* doc: update Visual C++ Build Tools URL (Michał Kozakiewicz)
* unix: loop starvation on successful write complete (jBarz)
* win: add uv__getnameinfo_work() error handling (A. Hauptmann)
* win: return UV_ENOMEM from uv_loop_init() (cjihrig)
* unix,win: add uv_os_{get,set}priority() (cjihrig)
* test: fix warning in test-tcp-open (Santiago Gimeno)
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - https://gpgtools.org
iQIzBAABCgAdFiEElK42Z1xGTWS6+mjddDQ5C9vpucUFAlt2LW8ACgkQdDQ5C9vp
ucXlDBAAlCVoa6GZthYy7fOBddNn2410GVKNZTUwNZ+bZL6ctpFxhgoH/Vir2SVg
/8Je+Se3jz6QXJx0cA2+gLZdZ+nmZn4cAOGo9p6pWq2SVhmtc7F89KkHc8DDG0GR
yGF09utyM4fQL0pnDYLzg66iquQJPCd1BwP32LlHOM0kqDyqli+OVphw/X9ABeHl
GFPMD8i8wuHAKcOQo7xLsIETZVax/LC6N7seeMxO2ZIdAZFSeBw4OEyHra9hLq2r
eleTccsA5R+tZZE9gUyefZ4s0desZkfndC0iL3qoWaM+TVxwpuB379BquDwhVwC1
CFaFv7HLikNjUgwTSz9nUbsqxni2z+QH5gmgaF7WWpPIJcSf3ZH4T8wW9abRwizR
BIehRtVHEM+TmC3Hr1ttfnDjMoFtyO33Tw1lSpQ9vlhll+sotei8RP7+oPumjlAN
rs6dfnZ2FTxjNDWG1yaDXxoh2GWwR9gbxr/SiL/ZhoNHukJNN+gPAamF11S3Sk0v
+h+iC9dtdiOPPWipxCZ+xeB3Tdus5Z+HVgG7Se859nt1r0kwA5zKfGw9pv65La9g
KZuTCZjgvx7fCh4Mcw+uVExJ1vTWy+x5kOKk4l62RQj+L9f1YJZxgljMrBQTG9AU
s4hMGI4gDMblyVM35T3vHModFBvwY0Uy90hn/yBCNILGbznNmD0=
=Uf50
-----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
iQIzBAABCAAdFiEEYS8OrZQBYiN530QC8ow8jaM8A74FAlt/3vUACgkQ8ow8jaM8
A76jzQ//fAIPMjf42ifdQhD3/EFskQ9AwdiPLmDALUM9qn5hzfGp6XZ/XJKq87kg
i2tm9wqh8m+QknSbnRkZMjDQrpmQuOypS+mqBDTVuPHHJ5V53f0zgStqlZ2dE5h9
B/5YcGTukVjK6BIlazFH5QO8urc9IsYefSvPp9gepO1XnLCzkE9OpVgL9jFTLcaG
Yvovtkbm4tkdYlOYZEp8LitnocRH84eJCZZipA3cfwctaWShKjPL6i/vB6TsmyH2
7QSdKcBkbYJ50r03gUSRYNQYpoJDJEg7eht/XGPVbUGMhcZ53oz6DqGE+bqalZ5P
VbD76KC96tqDhW99nCUij/RdT4Xo7NbK2+RiMXznr2H3KkpIt3eKEdD62B3ax1Hc
cNzk/fINareTe/6gPVg08A8Tzpsg48PNnLpGkzYpHghCn2XBR1iTtQNpIOa1UpxO
Gqe+uEP8k08tQ/n9rpBzBnNsC+fCZQU6Q5LGpWnTXMRjNtQuWM99O9k06TBPmDWI
AQyJ9MByEt5bwNqsIg9nVe+iXkxNbZBOLHmqbkDUWNTDhjY3+oVh8Dq/18nvfgMk
dIIBrBa0FEGbG/r/uKpuMqNmxCQel8nkC0sQ5vdIN8CfzAfQnoMww93GyPEpQTSR
FAwdk7ri+mGcGw3igUp8IsgAKwgjJAkkWzAX3gAwHrw1aoUnc60=
=3idK
-----END PGP SIGNATURE-----
Merge tag 'v1.23.0' into merge_1.23.0
PR-URL: https://github.com/libuv/libuv/pull/1952
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
146 lines
4.2 KiB
C
146 lines
4.2 KiB
C
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to
|
|
* deal in the Software without restriction, including without limitation the
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
* IN THE SOFTWARE.
|
|
*/
|
|
|
|
#include "uv.h"
|
|
#include "task.h"
|
|
|
|
|
|
static int close_cb_called = 0;
|
|
static int repeat_1_cb_called = 0;
|
|
static int repeat_2_cb_called = 0;
|
|
|
|
static int repeat_2_cb_allowed = 0;
|
|
|
|
static uv_timer_t dummy, repeat_1, repeat_2;
|
|
|
|
static uint64_t start_time;
|
|
|
|
|
|
static void close_cb(uv_handle_t* handle) {
|
|
ASSERT(handle != NULL);
|
|
|
|
close_cb_called++;
|
|
}
|
|
|
|
|
|
static void repeat_1_cb(uv_timer_t* handle) {
|
|
int r;
|
|
|
|
ASSERT(handle == &repeat_1);
|
|
ASSERT(uv_timer_get_repeat((uv_timer_t*)handle) == 50);
|
|
|
|
fprintf(stderr, "repeat_1_cb called after %ld ms\n",
|
|
(long int)(uv_now(uv_default_loop()) - start_time));
|
|
fflush(stderr);
|
|
|
|
repeat_1_cb_called++;
|
|
|
|
r = uv_timer_again(&repeat_2);
|
|
ASSERT(r == 0);
|
|
|
|
if (repeat_1_cb_called == 10) {
|
|
uv_close((uv_handle_t*)handle, close_cb);
|
|
/* We're not calling uv_timer_again on repeat_2 any more, so after this
|
|
* timer_2_cb is expected. */
|
|
repeat_2_cb_allowed = 1;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
static void repeat_2_cb(uv_timer_t* handle) {
|
|
ASSERT(handle == &repeat_2);
|
|
ASSERT(repeat_2_cb_allowed);
|
|
|
|
fprintf(stderr, "repeat_2_cb called after %ld ms\n",
|
|
(long int)(uv_now(uv_default_loop()) - start_time));
|
|
fflush(stderr);
|
|
|
|
repeat_2_cb_called++;
|
|
|
|
if (uv_timer_get_repeat(&repeat_2) == 0) {
|
|
ASSERT(0 == uv_is_active((uv_handle_t*) handle));
|
|
uv_close((uv_handle_t*)handle, close_cb);
|
|
return;
|
|
}
|
|
|
|
fprintf(stderr, "uv_timer_get_repeat %ld ms\n",
|
|
(long int)uv_timer_get_repeat(&repeat_2));
|
|
fflush(stderr);
|
|
ASSERT(uv_timer_get_repeat(&repeat_2) == 100);
|
|
|
|
/* This shouldn't take effect immediately. */
|
|
uv_timer_set_repeat(&repeat_2, 0);
|
|
}
|
|
|
|
|
|
TEST_IMPL(timer_again) {
|
|
int r;
|
|
|
|
start_time = uv_now(uv_default_loop());
|
|
ASSERT(0 < start_time);
|
|
|
|
/* Verify that it is not possible to uv_timer_again a never-started timer. */
|
|
r = uv_timer_init(uv_default_loop(), &dummy);
|
|
ASSERT(r == 0);
|
|
r = uv_timer_again(&dummy);
|
|
ASSERT(r == UV_EINVAL);
|
|
uv_unref((uv_handle_t*)&dummy);
|
|
|
|
/* Start timer repeat_1. */
|
|
r = uv_timer_init(uv_default_loop(), &repeat_1);
|
|
ASSERT(r == 0);
|
|
r = uv_timer_start(&repeat_1, repeat_1_cb, 50, 0);
|
|
ASSERT(r == 0);
|
|
ASSERT(uv_timer_get_repeat(&repeat_1) == 0);
|
|
|
|
/* Verify that it is not possible to uv_timer_again a non-repeating timer. */
|
|
r = uv_timer_again(&repeat_1);
|
|
ASSERT(r == UV_EINVAL);
|
|
|
|
/* Actually make repeat_1 repeating. */
|
|
uv_timer_set_repeat(&repeat_1, 50);
|
|
ASSERT(uv_timer_get_repeat(&repeat_1) == 50);
|
|
|
|
/*
|
|
* Start another repeating timer. It'll be again()ed by the repeat_1 so
|
|
* it should not time out until repeat_1 stops.
|
|
*/
|
|
r = uv_timer_init(uv_default_loop(), &repeat_2);
|
|
ASSERT(r == 0);
|
|
r = uv_timer_start(&repeat_2, repeat_2_cb, 100, 100);
|
|
ASSERT(r == 0);
|
|
ASSERT(uv_timer_get_repeat(&repeat_2) == 100);
|
|
|
|
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
|
|
|
ASSERT(repeat_1_cb_called == 10);
|
|
ASSERT(repeat_2_cb_called == 2);
|
|
ASSERT(close_cb_called == 2);
|
|
|
|
fprintf(stderr, "Test took %ld ms (expected ~700 ms)\n",
|
|
(long int)(uv_now(uv_default_loop()) - start_time));
|
|
fflush(stderr);
|
|
|
|
MAKE_VALGRIND_HAPPY();
|
|
return 0;
|
|
}
|