瀏覽代碼

Fix TUN/TAP operation with Linux kernel 3.19.

See: https://bugzilla.kernel.org/show_bug.cgi?id=96381
Ambroz Bizjak 11 年之前
父節點
當前提交
92a2fc831b
共有 1 個文件被更改,包括 7 次插入4 次删除
  1. 7 4
      tuntap/BTap.c

+ 7 - 4
tuntap/BTap.c

@@ -105,8 +105,10 @@ static void fd_handler (BTap *o, int events)
         
         // try reading into the buffer
         int bytes = read(o->fd, o->output_packet, o->frame_mtu);
-        if (bytes < 0) {
-            if (errno == EAGAIN || errno == EWOULDBLOCK) {
+        if (bytes <= 0) {
+            // Treat zero return value the same as EAGAIN.
+            // See: https://bugzilla.kernel.org/show_bug.cgi?id=96381
+            if (bytes == 0 || errno == EAGAIN || errno == EWOULDBLOCK) {
                 // retry later
                 break;
             }
@@ -161,8 +163,9 @@ void output_handler_recv (BTap *o, uint8_t *data)
     
     // attempt read
     int bytes = read(o->fd, data, o->frame_mtu);
-    if (bytes < 0) {
-        if (errno == EAGAIN || errno == EWOULDBLOCK) {
+    if (bytes <= 0) {
+        if (bytes == 0 || errno == EAGAIN || errno == EWOULDBLOCK) {
+            // See note about zero return in fd_handler.
             // retry later in fd_handler
             // remember packet
             o->output_packet = data;