OSDN Git Service

Improve poll(2) handling and log messages
authorPavlin Radoslavov <pavlin@google.com>
Wed, 18 May 2016 21:34:31 +0000 (14:34 -0700)
committerPavlin Radoslavov <pavlin@google.com>
Thu, 19 May 2016 21:20:23 +0000 (14:20 -0700)
 * 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

btif/src/btif_pan.c
udrv/ulinux/uipc.c

index c3ad281..5bd87fa 100644 (file)
@@ -787,7 +787,10 @@ static void btu_exec_tap_fd_read(void *p_param) {
         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;
     }
 
index 524cde5..abb747d 100644 (file)
@@ -401,6 +401,16 @@ static void uipc_flush_ch_locked(tUIPC_CH_ID ch_id)
     {
         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))
@@ -409,13 +419,6 @@ static void uipc_flush_ch_locked(tUIPC_CH_ID ch_id)
             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);
@@ -754,6 +757,11 @@ UINT32 UIPC_Read(tUIPC_CH_ID ch_id, UINT16 *p_msg_evt, UINT8 *p_buf, UINT32 len)
             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);