Improve poll(2) handling and log messages
* Better error handling and log messages inside
uipc_flush_ch_locked()
* Add missing error check inside UIPC_Read()
* Add missing OSI_NO_INTR() wrapper around poll()
inside function btu_exec_tap_fd_read()
Bug: 28823662
Change-Id: I5f1c720861bea594d53ed6465a5ff327ba352598
diff --git a/btif/src/btif_pan.cc b/btif/src/btif_pan.cc
index fe6bdbd..1eef784 100644
--- a/btif/src/btif_pan.cc
+++ b/btif/src/btif_pan.cc
@@ -787,7 +787,10 @@
ufd.fd = fd;
ufd.events = POLLIN;
ufd.revents = 0;
- if (poll(&ufd, 1, 0) <= 0 || IS_EXCEPTION(ufd.revents))
+
+ int ret;
+ OSI_NO_INTR(ret = poll(&ufd, 1, 0));
+ if (ret <= 0 || IS_EXCEPTION(ufd.revents))
break;
}
diff --git a/udrv/ulinux/uipc.c b/udrv/ulinux/uipc.c
index c9ff0f1..66b26d5 100644
--- a/udrv/ulinux/uipc.c
+++ b/udrv/ulinux/uipc.c
@@ -394,6 +394,16 @@
{
int ret;
OSI_NO_INTR(ret = poll(&pfd, 1, 1));
+ if (ret == 0) {
+ BTIF_TRACE_VERBOSE("%s(): poll() timeout - nothing to do. Exiting",
+ __func__);
+ return;
+ }
+ if (ret < 0) {
+ BTIF_TRACE_WARNING("%s() - poll() failed: return %d errno %d (%s). Exiting",
+ __func__, ret, errno, strerror(errno));
+ return;
+ }
BTIF_TRACE_VERBOSE("%s() - polling fd %d, revents: 0x%x, ret %d",
__FUNCTION__, pfd.fd, pfd.revents, ret);
if (pfd.revents & (POLLERR|POLLHUP))
@@ -402,13 +412,6 @@
return;
}
- if (ret <= 0)
- {
- BTIF_TRACE_WARNING("%s() - poll() failed (%s). Exiting",
- __FUNCTION__, strerror(errno));
- return;
- }
-
/* read sufficiently large buffer to ensure flush empties socket faster than
it is getting refilled */
read(pfd.fd, &buf, UIPC_FLUSH_BUFFER_SIZE);
@@ -747,6 +750,11 @@
BTIF_TRACE_WARNING("poll timeout (%d ms)", uipc_main.ch[ch_id].read_poll_tmo_ms);
break;
}
+ if (poll_ret < 0) {
+ BTIF_TRACE_ERROR("%s(): poll() failed: return %d errno %d (%s)",
+ __func__, poll_ret, errno, strerror(errno));
+ break;
+ }
//BTIF_TRACE_EVENT("poll revents %x", pfd.revents);