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>
This commit is contained in:
Mark McLoughlin 2009-10-22 17:43:34 +01:00 committed by Anthony Liguori
parent 76682299a8
commit 38c75be313
1 changed files with 15 additions and 8 deletions

23
net.c
View File

@ -1306,10 +1306,8 @@ static void tap_writable(void *opaque)
qemu_flush_queued_packets(s->vc); qemu_flush_queued_packets(s->vc);
} }
static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov, static ssize_t tap_write_packet(TAPState *s, const struct iovec *iov, int iovcnt)
int iovcnt)
{ {
TAPState *s = vc->opaque;
ssize_t len; ssize_t len;
do { do {
@ -1324,16 +1322,25 @@ static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,
return len; 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) static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
TAPState *s = vc->opaque; TAPState *s = vc->opaque;
ssize_t len; struct iovec iov[1];
int iovcnt = 0;
do { iov[iovcnt].iov_base = (char *)buf;
len = write(s->fd, buf, size); iov[iovcnt].iov_len = size;
} while (len == -1 && (errno == EINTR || errno == EAGAIN)); iovcnt++;
return len; return tap_write_packet(s, iov, iovcnt);
} }
static int tap_can_send(void *opaque) static int tap_can_send(void *opaque)