handle read from timerfd correctly

When reading the timerfd gives an error, we should return right away
because the timeout did not happen.

If we change the timerfd timeout before reading it, we can get -EAGAIN.
Don't log an error in that case but wait for the new timeout.
This commit is contained in:
Wim Taymans 2022-12-09 17:30:31 +01:00
parent 3a443b4e1c
commit f44d55f6c2
14 changed files with 153 additions and 55 deletions

View file

@ -32,6 +32,7 @@
#include <spa/support/log.h>
#include <spa/support/loop.h>
#include <spa/utils/names.h>
#include <spa/utils/result.h>
#include <spa/utils/string.h>
#include <spa/node/node.h>
#include <spa/node/keys.h>
@ -180,14 +181,16 @@ static void on_timeout(struct spa_source *source)
struct impl *this = source->data;
uint64_t expirations, nsec, duration;
uint32_t rate;
int res;
spa_log_trace(this->log, "timeout");
if (spa_system_timerfd_read(this->data_system,
this->timer_source.fd, &expirations) < 0) {
if (errno == EAGAIN)
return;
perror("read timerfd");
if ((res = spa_system_timerfd_read(this->data_system,
this->timer_source.fd, &expirations)) < 0) {
if (res != EAGAIN)
spa_log_error(this->log, NAME " %p: timerfd error: %s",
this, spa_strerror(res));
return;
}
nsec = this->next_time;

View file

@ -35,6 +35,7 @@
#include <spa/utils/list.h>
#include <spa/utils/keys.h>
#include <spa/utils/json.h>
#include <spa/utils/result.h>
#include <spa/utils/string.h>
#include <spa/node/node.h>
#include <spa/node/utils.h>
@ -282,14 +283,16 @@ static void on_timeout(struct spa_source *source)
struct impl *this = source->data;
uint64_t expirations, nsec, duration = 10;
uint32_t rate;
int res;
spa_log_trace(this->log, "timeout");
if (spa_system_timerfd_read(this->data_system,
this->timer_source.fd, &expirations) < 0) {
if (errno == EAGAIN)
return;
perror("read timerfd");
if ((res = spa_system_timerfd_read(this->data_system,
this->timer_source.fd, &expirations)) < 0) {
if (res != EAGAIN)
spa_log_error(this->log, NAME " %p: timerfd error: %s",
this, spa_strerror(res));
return;
}
nsec = this->next_time;