vfs/poll: round timeout up to next full tick. Calling poll() with timeout less than half tick (thus MSEC2TICK(timeout) => 0) caused returning error with EAGAIN. Instead of rounding timeout down, value should be rounded up. Open Group spec for poll says: "Implementations may place limitations on the granularity of timeout intervals. If the requested timeout interval requires a finer granularity than the implementation supports, the actual timeout interval will be rounded up to the next supported value."
This commit is contained in:
parent
9431fb1d91
commit
37ca797d1c
@ -388,6 +388,25 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
}
|
||||
else if (timeout > 0)
|
||||
{
|
||||
systime_t ticks;
|
||||
|
||||
/* "Implementations may place limitations on the granularity of
|
||||
* timeout intervals. If the requested timeout interval requires
|
||||
* a finer granularity than the implementation supports, the
|
||||
* actual timeout interval will be rounded up to the next
|
||||
* supported value." -- opengroup.org
|
||||
*
|
||||
* Round timeout up to next full tick.
|
||||
*/
|
||||
|
||||
#if (MSEC_PER_TICK * USEC_PER_MSEC) != USEC_PER_TICK && \
|
||||
defined(CONFIG_HAVE_LONG_LONG)
|
||||
ticks = ((long long)timeout * USEC_PER_MSEC) + (USEC_PER_TICK - 1) /
|
||||
USEC_PER_TICK;
|
||||
#else
|
||||
ticks = (timeout + (MSEC_PER_TICK - 1)) / MSEC_PER_TICK;
|
||||
#endif
|
||||
|
||||
/* Either wait for either a poll event(s), for a signal to occur,
|
||||
* or for the specified timeout to elapse with no event.
|
||||
*
|
||||
@ -396,7 +415,7 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
* immediately.
|
||||
*/
|
||||
|
||||
ret = sem_tickwait(&sem, clock_systimer(), MSEC2TICK(timeout));
|
||||
ret = sem_tickwait(&sem, clock_systimer(), ticks);
|
||||
if (ret < 0)
|
||||
{
|
||||
if (ret == -ETIMEDOUT)
|
||||
|
Loading…
Reference in New Issue
Block a user