From 92a2fc831bc5d1293c0d07c4afae055470ebc7a2 Mon Sep 17 00:00:00 2001 From: Ambroz Bizjak Date: Thu, 9 Apr 2015 11:29:45 +0200 Subject: [PATCH] Fix TUN/TAP operation with Linux kernel 3.19. See: https://bugzilla.kernel.org/show_bug.cgi?id=96381 --- tuntap/BTap.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tuntap/BTap.c b/tuntap/BTap.c index 43d3e7a8f..c30bf71ed 100644 --- a/tuntap/BTap.c +++ b/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;