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;