From: Luiz Augusto von Dentz Date: Tue, 28 Jan 2014 17:14:46 +0000 (-0800) Subject: android/hal-audio: Set stream fd to blocking X-Git-Tag: android-x86-4.4-r3~5621 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=55c3cacc1ea42e76c54e7215fc34b90a94fa7f5c;p=android-x86%2Fexternal-bluetooth-bluez.git android/hal-audio: Set stream fd to blocking This makes the stream to block on io operation so it does not return EAGAIN on syscall such as write. --- diff --git a/android/hal-audio.c b/android/hal-audio.c index 2ca628948..b1323b0b4 100644 --- a/android/hal-audio.c +++ b/android/hal-audio.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -1108,6 +1109,24 @@ static int in_remove_audio_effect(const struct audio_stream *stream, return -ENOSYS; } +static int set_blocking(int fd) +{ + int flags; + + flags = fcntl(fd, F_GETFL, 0); + if (flags < 0) { + error("fcntl(F_GETFL): %s (%d)", strerror(errno), errno); + return -errno; + } + + if (fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) < 0) { + error("fcntl(F_SETFL): %s (%d)", strerror(errno), errno); + return -errno; + } + + return 0; +} + static int audio_open_output_stream(struct audio_hw_device *dev, audio_io_handle_t handle, audio_devices_t devices, @@ -1156,8 +1175,10 @@ static int audio_open_output_stream(struct audio_hw_device *dev, if (!preset || fd < 0) goto fail; - out->ep->fd = fd; + if (set_blocking(fd) < 0) + goto fail; + out->ep->fd = fd; codec = out->ep->codec; codec->init(preset, mtu, &out->ep->codec_data);