Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

nyoci_plat_wait() returns wrong value when timer fires #18

Open
snej opened this issue Sep 12, 2018 · 2 comments
Open

nyoci_plat_wait() returns wrong value when timer fires #18

snej opened this issue Sep 12, 2018 · 2 comments

Comments

@snej
Copy link
Contributor

snej commented Sep 12, 2018

The header doc for nyoci_plat_wait() says "it returns 0 if nyoci_plat_process() should be executed". The POSIX implementation doesn't quite agree with this: it does return 0 if a file descriptor has input, but it returns NYOCI_STATUS_TIMEOUT if a timer is ready to fire. Thus, a loop like this one won't work because it never handles timers until a packet arrives:

            while (true) {
                if (nyoci_plat_wait(_nyoci, MSEC_PER_SEC) == 0)
                    nyoci_plat_process(_nyoci);
            }

This happens because the function doesn't distinguish whether it's the timeout given by the caller that's elapsed, or the timeout till the next timer. In the latter case it should return 0.

Alternatively, the docs could be amended to match the implementation, by saying that if the function returns NYOCI_STATUS_TIMEOUT, then nyoci_handle_timers() should be called.

@darconeous
Copy link
Owner

Good catch!

NYOCI_STATUS_TIMEOUT should only be returned if the actual call timed out, not if a timer fired—that should just return NYOCI_STATUS_OK (zero).

@darconeous
Copy link
Owner

Happy to take a patch, otherwise it may be a week or two before I can get to this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants