Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 148002
b: refs/heads/master
c: 4a8962e
h: refs/heads/master
v: v3
  • Loading branch information
Rusty Russell committed Jun 12, 2009
1 parent 09efe65 commit 4818d00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 95c517c09bad31a03e22f2fdb5f0aa26a490a92d
refs/heads/master: 4a8962e21bc505c714fc2508494d4c7dd3fe2d29
17 changes: 16 additions & 1 deletion trunk/Documentation/lguest/lguest.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,16 @@ static void net_output(struct virtqueue *vq)
add_used(vq, head, 0);
}

/* Will reading from this file descriptor block? */
static bool will_block(int fd)
{
fd_set fdset;
struct timeval zero = { 0, 0 };
FD_ZERO(&fdset);
FD_SET(fd, &fdset);
return select(fd+1, &fdset, NULL, NULL, &zero) != 1;
}

/* This is where we handle packets coming in from the tun device to our
* Guest. */
static void net_input(struct virtqueue *vq)
Expand All @@ -781,10 +791,15 @@ static void net_input(struct virtqueue *vq)
head = wait_for_vq_desc(vq, iov, &out, &in);
if (out)
errx(1, "Output buffers in net input queue?");

/* Deliver interrupt now, since we're about to sleep. */
if (vq->pending_used && will_block(net_info->tunfd))
trigger_irq(vq);

len = readv(net_info->tunfd, iov, in);
if (len <= 0)
err(1, "Failed to read from tun.");
add_used_and_trigger(vq, head, len);
add_used(vq, head, len);
}

/* This is the helper to create threads. */
Expand Down

0 comments on commit 4818d00

Please sign in to comment.