aboutsummaryrefslogtreecommitdiff
path: root/net.c
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2009-10-22 17:43:34 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-27 12:29:00 -0500
commit38c75be3139a117b02350dbda9d48d47aa57fa3d (patch)
treee0a83df9dd9c4d7c11bca7176e00e09e787aba03 /net.c
parent76682299a865e916c9f106b167da8e88caa86fa3 (diff)
net: make tap_receive() re-use tap_receive_iov() code
In future we will want to prepend a virtio_net header if the NIC didn't supply one but IFF_VNET_HDR is enabled on the interface. This is most easily achived by using writev() in all cases. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'net.c')
-rw-r--r--net.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/net.c b/net.c
index acddb971c8..a96e42d8b0 100644
--- a/net.c
+++ b/net.c
@@ -1306,10 +1306,8 @@ static void tap_writable(void *opaque)
qemu_flush_queued_packets(s->vc);
}
-static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,
- int iovcnt)
+static ssize_t tap_write_packet(TAPState *s, const struct iovec *iov, int iovcnt)
{
- TAPState *s = vc->opaque;
ssize_t len;
do {
@@ -1324,16 +1322,25 @@ static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,
return len;
}
+static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,
+ int iovcnt)
+{
+ TAPState *s = vc->opaque;
+
+ return tap_write_packet(s, iov, iovcnt);
+}
+
static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{
TAPState *s = vc->opaque;
- ssize_t len;
+ struct iovec iov[1];
+ int iovcnt = 0;
- do {
- len = write(s->fd, buf, size);
- } while (len == -1 && (errno == EINTR || errno == EAGAIN));
+ iov[iovcnt].iov_base = (char *)buf;
+ iov[iovcnt].iov_len = size;
+ iovcnt++;
- return len;
+ return tap_write_packet(s, iov, iovcnt);
}
static int tap_can_send(void *opaque)