]> The Tcpdump Group git mirrors - libpcap/commitdiff
Bluetooth: fix non-blocking mode
authorMatias Karhumaa <[email protected]>
Fri, 19 Mar 2021 13:00:52 +0000 (15:00 +0200)
committerGuy Harris <[email protected]>
Sat, 20 Mar 2021 07:09:47 +0000 (00:09 -0700)
Fix non-blocking mode with bt-linux and bt-monitor-linux. Previously
when fd was set to non-blocking mode and pcap_dispatch() was called
from application, it returned -1 with errno EAGAIN breaking the api
contract.

Fix is to handle errnos EAGAIN and EWOULDBLOCK so that 0 is returned.

(cherry picked from commit 747ca9149a4158fafc4551550976cdb028916182)

pcap-bt-linux.c
pcap-bt-monitor-linux.c

index 2969ff8d24292ea4121df5249c07fe045333651c..8e70febc6f99babd9b0fb5b5af0d2651cfc0f2a7 100644 (file)
@@ -341,6 +341,10 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char
        } while ((ret == -1) && (errno == EINTR));
 
        if (ret < 0) {
+               if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                       /* Nonblocking mode, no data */
+                       return 0;
+               }
                pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
                    errno, "Can't receive packet");
                return -1;
index ad4fc375c7c993fef384c4e774dc20629f73a989..206e65b521221cdb13c9adcaa255ccff0847a10d 100644 (file)
@@ -127,6 +127,10 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
     } while ((ret == -1) && (errno == EINTR));
 
     if (ret < 0) {
+        if (errno == EAGAIN || errno == EWOULDBLOCK) {
+            /* Nonblocking mode, no data */
+            return 0;
+        }
         pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
             errno, "Can't receive packet");
         return -1;