net: factor tap_read_packet() out of tap_send()

Move portability clutter out into its own function.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
This commit is contained in:
Mark McLoughlin 2009-04-29 09:43:37 +01:00
parent b8e8af38ee
commit 5a6d881574

28
net.c
View File

@ -951,21 +951,31 @@ static void tap_receive(void *opaque, const uint8_t *buf, int size)
} }
} }
#ifdef __sun__
static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
{
struct strbuf sbuf;
int f = 0;
sbuf.maxlen = maxlen;
sbuf.buf = (char *)buf;
return getmsg(tapfd, NULL, &sbuf, &f) >= 0 ? sbuf.len : -1;
}
#else
static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
{
return read(tapfd, buf, maxlen);
}
#endif
static void tap_send(void *opaque) static void tap_send(void *opaque)
{ {
TAPState *s = opaque; TAPState *s = opaque;
uint8_t buf[4096]; uint8_t buf[4096];
int size; int size;
#ifdef __sun__ size = tap_read_packet(s->fd, buf, sizeof(buf));
struct strbuf sbuf;
int f = 0;
sbuf.maxlen = sizeof(buf);
sbuf.buf = (char *)buf;
size = getmsg(s->fd, NULL, &sbuf, &f) >=0 ? sbuf.len : -1;
#else
size = read(s->fd, buf, sizeof(buf));
#endif
if (size > 0) { if (size > 0) {
qemu_send_packet(s->vc, buf, size); qemu_send_packet(s->vc, buf, size);
} }