mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
bluetooth: Refactor POLLHUP handling
The code in the "io_fail" section was only used for HUP handling, but there were jumps to there also from places where reading or writing failed, because the read/write failure could have been caused by HUP. This patch simplifies things by checking for HUP condition before trying to read or write. Now if reading or writing fails, we will jump to "fail" directly instead of going via the "io_fail" label. As a result, the "io_fail" label isn't needed any more.
This commit is contained in:
parent
59a8618dcd
commit
15ae55ed9b
1 changed files with 20 additions and 28 deletions
|
|
@ -1082,6 +1082,24 @@ static void thread_func(void *userdata) {
|
||||||
|
|
||||||
pollfd = u->rtpoll_item ? pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL) : NULL;
|
pollfd = u->rtpoll_item ? pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL) : NULL;
|
||||||
|
|
||||||
|
if (pollfd && (pollfd->revents & ~(POLLOUT|POLLIN))) {
|
||||||
|
pa_log_info("FD error: %s%s%s%s",
|
||||||
|
pollfd->revents & POLLERR ? "POLLERR " :"",
|
||||||
|
pollfd->revents & POLLHUP ? "POLLHUP " :"",
|
||||||
|
pollfd->revents & POLLPRI ? "POLLPRI " :"",
|
||||||
|
pollfd->revents & POLLNVAL ? "POLLNVAL " :"");
|
||||||
|
|
||||||
|
if (pollfd->revents & POLLHUP) {
|
||||||
|
pollfd = NULL;
|
||||||
|
teardown_stream(u);
|
||||||
|
do_write = 0;
|
||||||
|
pending_read_bytes = 0;
|
||||||
|
writable = false;
|
||||||
|
pa_asyncmsgq_post(pa_thread_mq_get()->outq, PA_MSGOBJECT(u->msg), BLUETOOTH_MESSAGE_STREAM_FD_HUP, NULL, 0, NULL, NULL);
|
||||||
|
} else
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
if (u->source && PA_SOURCE_IS_LINKED(u->source->thread_info.state)) {
|
if (u->source && PA_SOURCE_IS_LINKED(u->source->thread_info.state)) {
|
||||||
|
|
||||||
/* We should send two blocks to the device before we expect
|
/* We should send two blocks to the device before we expect
|
||||||
|
|
@ -1096,7 +1114,7 @@ static void thread_func(void *userdata) {
|
||||||
n_read = a2dp_process_push(u);
|
n_read = a2dp_process_push(u);
|
||||||
|
|
||||||
if (n_read < 0)
|
if (n_read < 0)
|
||||||
goto io_fail;
|
goto fail;
|
||||||
|
|
||||||
if (n_read > 0) {
|
if (n_read > 0) {
|
||||||
/* We just read something, so we are supposed to write something, too */
|
/* We just read something, so we are supposed to write something, too */
|
||||||
|
|
@ -1165,7 +1183,7 @@ static void thread_func(void *userdata) {
|
||||||
u->started_at = pa_rtclock_now();
|
u->started_at = pa_rtclock_now();
|
||||||
|
|
||||||
if ((n_written = a2dp_process_render(u)) < 0)
|
if ((n_written = a2dp_process_render(u)) < 0)
|
||||||
goto io_fail;
|
goto fail;
|
||||||
|
|
||||||
if (n_written == 0)
|
if (n_written == 0)
|
||||||
pa_log("Broken kernel: we got EAGAIN on write() after POLLOUT!");
|
pa_log("Broken kernel: we got EAGAIN on write() after POLLOUT!");
|
||||||
|
|
@ -1212,32 +1230,6 @@ static void thread_func(void *userdata) {
|
||||||
transport_release(u);
|
transport_release(u);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
pollfd = u->rtpoll_item ? pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL) : NULL;
|
|
||||||
|
|
||||||
if (pollfd && (pollfd->revents & ~(POLLOUT|POLLIN))) {
|
|
||||||
pa_log_info("FD error: %s%s%s%s",
|
|
||||||
pollfd->revents & POLLERR ? "POLLERR " :"",
|
|
||||||
pollfd->revents & POLLHUP ? "POLLHUP " :"",
|
|
||||||
pollfd->revents & POLLPRI ? "POLLPRI " :"",
|
|
||||||
pollfd->revents & POLLNVAL ? "POLLNVAL " :"");
|
|
||||||
goto io_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
|
|
||||||
io_fail:
|
|
||||||
/* In case of HUP, just tear down the streams */
|
|
||||||
if (!pollfd || (pollfd->revents & POLLHUP) == 0)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
do_write = 0;
|
|
||||||
pending_read_bytes = 0;
|
|
||||||
writable = false;
|
|
||||||
|
|
||||||
pa_asyncmsgq_post(pa_thread_mq_get()->outq, PA_MSGOBJECT(u->msg), BLUETOOTH_MESSAGE_STREAM_FD_HUP, NULL, 0, NULL, NULL);
|
|
||||||
|
|
||||||
teardown_stream(u);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue