handle EINTR and EAGAIN

Just do the call again instead of failing or logging an error.

Fixes #358
This commit is contained in:
Wim Taymans 2020-11-02 14:51:07 +01:00
parent 395a30b5d6
commit e094640c7b
8 changed files with 33 additions and 12 deletions

View file

@ -1078,11 +1078,17 @@ static inline uint32_t cycle_run(struct client *c)
struct pw_node_activation *driver = c->rt.driver_activation; struct pw_node_activation *driver = c->rt.driver_activation;
/* this is blocking if nothing ready */ /* this is blocking if nothing ready */
if (SPA_UNLIKELY(read(fd, &cmd, sizeof(cmd)) != sizeof(cmd))) { while (true) {
pw_log_warn(NAME" %p: read failed %m", c); if (SPA_UNLIKELY(read(fd, &cmd, sizeof(cmd)) != sizeof(cmd))) {
if (errno == EWOULDBLOCK) if (errno == EAGAIN || errno == EINTR)
return 0; continue;
} else if (SPA_UNLIKELY(cmd > 1)) if (errno == EWOULDBLOCK)
return 0;
pw_log_warn(NAME" %p: read failed %m", c);
}
break;
}
if (SPA_UNLIKELY(cmd > 1))
pw_log_warn(NAME" %p: missed %"PRIu64" wakeups", c, cmd - 1); pw_log_warn(NAME" %p: missed %"PRIu64" wakeups", c, cmd - 1);
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);

View file

@ -1654,11 +1654,14 @@ pa_operation* pa_context_subscribe(pa_context *c, pa_subscription_mask_t m, pa_c
static void io_event_cb(pa_mainloop_api*ea, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata) static void io_event_cb(pa_mainloop_api*ea, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata)
{ {
int res;
pa_context *c = userdata; pa_context *c = userdata;
if (events & PA_IO_EVENT_INPUT) { if (events & PA_IO_EVENT_INPUT) {
pw_log_debug("%p: iterate loop %p", c, c->loop); pw_log_debug("%p: iterate loop %p", c, c->loop);
pw_loop_enter(c->loop); pw_loop_enter(c->loop);
pw_loop_iterate(c->loop, -1); do {
res = pw_loop_iterate(c->loop, 0);
} while (res == -EINTR || res == -EAGAIN);
pw_loop_leave(c->loop); pw_loop_leave(c->loop);
} }
} }

View file

@ -53,7 +53,9 @@ static gboolean source_dispatch (GSource *source, GSourceFunc callback, gpointer
int result; int result;
pw_loop_enter (s->loop); pw_loop_enter (s->loop);
result = pw_loop_iterate (s->loop, 0); do {
result = pw_loop_iterate (s->loop, 0);
} while (result == -EINTR || result == -EAGAIN);
pw_loop_leave (s->loop); pw_loop_leave (s->loop);
if (result < 0) if (result < 0)

View file

@ -352,7 +352,9 @@ int pa_mainloop_poll(pa_mainloop *m)
if (do_iterate) { if (do_iterate) {
pw_loop_enter(m->loop); pw_loop_enter(m->loop);
res = pw_loop_iterate(m->loop, timeout); do {
res = pw_loop_iterate(m->loop, timeout);
} while (res == -EINTR || res == -EAGAIN);
pw_loop_leave(m->loop); pw_loop_leave(m->loop);
} }

View file

@ -1345,6 +1345,8 @@ int sm_media_session_roundtrip(struct sm_media_session *sess)
pw_loop_enter(loop); pw_loop_enter(loop);
while (!done) { while (!done) {
if ((res = pw_loop_iterate(loop, -1)) < 0) { if ((res = pw_loop_iterate(loop, -1)) < 0) {
if (res == -EINTR || res == -EAGAIN)
continue;
pw_log_warn(NAME" %p: iterate error %d (%s)", pw_log_warn(NAME" %p: iterate error %d (%s)",
loop, res, spa_strerror(res)); loop, res, spa_strerror(res));
break; break;

View file

@ -43,7 +43,7 @@ int pw_data_loop_wait(struct pw_data_loop *this, int timeout)
break; break;
} }
if ((res = pw_loop_iterate(this->loop, timeout)) < 0) { if ((res = pw_loop_iterate(this->loop, timeout)) < 0) {
if (errno == EINTR) if (res == -EINTR || res == -EAGAIN)
continue; continue;
} }
break; break;
@ -77,7 +77,7 @@ static void *do_loop(void *user_data)
while (this->running) { while (this->running) {
if ((res = pw_loop_iterate(this->loop, -1)) < 0) { if ((res = pw_loop_iterate(this->loop, -1)) < 0) {
if (errno == EINTR) if (res == -EINTR || res == -EAGAIN)
continue; continue;
pw_log_error(NAME" %p: iterate error %d (%s)", pw_log_error(NAME" %p: iterate error %d (%s)",
this, res, spa_strerror(res)); this, res, spa_strerror(res));

View file

@ -153,9 +153,12 @@ int pw_main_loop_run(struct pw_main_loop *loop)
loop->running = true; loop->running = true;
pw_loop_enter(loop->loop); pw_loop_enter(loop->loop);
while (loop->running) { while (loop->running) {
if ((res = pw_loop_iterate(loop->loop, -1)) < 0) if ((res = pw_loop_iterate(loop->loop, -1)) < 0) {
if (res == -EINTR || res == -EAGAIN)
continue;
pw_log_warn(NAME" %p: iterate error %d (%s)", pw_log_warn(NAME" %p: iterate error %d (%s)",
loop, res, spa_strerror(res)); loop, res, spa_strerror(res));
}
} }
pw_loop_leave(loop->loop); pw_loop_leave(loop->loop);
return res; return res;

View file

@ -238,9 +238,12 @@ static void *do_loop(void *user_data)
pw_loop_enter(this->loop); pw_loop_enter(this->loop);
while (this->running) { while (this->running) {
if ((res = pw_loop_iterate(this->loop, -1)) < 0) if ((res = pw_loop_iterate(this->loop, -1)) < 0) {
if (res == -EINTR || res == -EAGAIN)
continue;
pw_log_warn(NAME" %p: iterate error %d (%s)", pw_log_warn(NAME" %p: iterate error %d (%s)",
this, res, spa_strerror(res)); this, res, spa_strerror(res));
}
} }
pw_log_debug(NAME" %p: leave thread", this); pw_log_debug(NAME" %p: leave thread", this);
pw_loop_leave(this->loop); pw_loop_leave(this->loop);