Commit 5a6d88157420d7f10b46270edabbeed11ee4ebe5
1 parent
b8e8af38
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>
Showing
1 changed file
with
19 additions
and
9 deletions
net.c
... | ... | @@ -951,21 +951,31 @@ static void tap_receive(void *opaque, const uint8_t *buf, int size) |
951 | 951 | } |
952 | 952 | } |
953 | 953 | |
954 | -static void tap_send(void *opaque) | |
955 | -{ | |
956 | - TAPState *s = opaque; | |
957 | - uint8_t buf[4096]; | |
958 | - int size; | |
959 | - | |
960 | 954 | #ifdef __sun__ |
955 | +static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen) | |
956 | +{ | |
961 | 957 | struct strbuf sbuf; |
962 | 958 | int f = 0; |
963 | - sbuf.maxlen = sizeof(buf); | |
959 | + | |
960 | + sbuf.maxlen = maxlen; | |
964 | 961 | sbuf.buf = (char *)buf; |
965 | - size = getmsg(s->fd, NULL, &sbuf, &f) >=0 ? sbuf.len : -1; | |
962 | + | |
963 | + return getmsg(tapfd, NULL, &sbuf, &f) >= 0 ? sbuf.len : -1; | |
964 | +} | |
966 | 965 | #else |
967 | - size = read(s->fd, buf, sizeof(buf)); | |
966 | +static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen) | |
967 | +{ | |
968 | + return read(tapfd, buf, maxlen); | |
969 | +} | |
968 | 970 | #endif |
971 | + | |
972 | +static void tap_send(void *opaque) | |
973 | +{ | |
974 | + TAPState *s = opaque; | |
975 | + uint8_t buf[4096]; | |
976 | + int size; | |
977 | + | |
978 | + size = tap_read_packet(s->fd, buf, sizeof(buf)); | |
969 | 979 | if (size > 0) { |
970 | 980 | qemu_send_packet(s->vc, buf, size); |
971 | 981 | } | ... | ... |