Reputation: 369
I tried to run the following code and the function keeps returning 0 after the first receive:
while (true)
{
int res = uv_run(uv_default_loop(), UV_RUN_ONCE);
if (res == 0)
printf("ok\n");
}
Is there a way to reset the loop, so that it will return 0 on the second receive and won't stuck on success from the first one ?
Upvotes: 1
Views: 499
Reputation: 50548
uv_run keeps returning success forever
In this case, 0 doesn't mean success.
As mentioned here for uv_run
(emphasis mine):
UV_RUN_ONCE: Poll for i/o once. Note that this function blocks if there are no pending callbacks. Returns zero when done (no active handles or requests left), or non-zero if more callbacks are expected (meaning you should run the event loop again sometime in the future).
If there exists at least one callback, the function call won't block and it will execute them, then it will return. It polls for I/O only once, it is meant for that and you are asking - is it possible to have it working differently from what it is meant for? Well, no.
Use UV_RUN_DEFAULT
instead and close all the handles when you have finished with them, so that the loop ends and the function call returns.
Upvotes: 1