1f7105843SMark McLoughlin /* 2f7105843SMark McLoughlin * Copyright (c) 2003-2008 Fabrice Bellard 3f7105843SMark McLoughlin * Copyright (c) 2009 Red Hat, Inc. 4f7105843SMark McLoughlin * 5f7105843SMark McLoughlin * Permission is hereby granted, free of charge, to any person obtaining a copy 6f7105843SMark McLoughlin * of this software and associated documentation files (the "Software"), to deal 7f7105843SMark McLoughlin * in the Software without restriction, including without limitation the rights 8f7105843SMark McLoughlin * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9f7105843SMark McLoughlin * copies of the Software, and to permit persons to whom the Software is 10f7105843SMark McLoughlin * furnished to do so, subject to the following conditions: 11f7105843SMark McLoughlin * 12f7105843SMark McLoughlin * The above copyright notice and this permission notice shall be included in 13f7105843SMark McLoughlin * all copies or substantial portions of the Software. 14f7105843SMark McLoughlin * 15f7105843SMark McLoughlin * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16f7105843SMark McLoughlin * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17f7105843SMark McLoughlin * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18f7105843SMark McLoughlin * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19f7105843SMark McLoughlin * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20f7105843SMark McLoughlin * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21f7105843SMark McLoughlin * THE SOFTWARE. 22f7105843SMark McLoughlin */ 23f7105843SMark McLoughlin 24f7105843SMark McLoughlin #ifndef QEMU_NET_QUEUE_H 25f7105843SMark McLoughlin #define QEMU_NET_QUEUE_H 26f7105843SMark McLoughlin 27f7105843SMark McLoughlin #include "qemu-common.h" 28f7105843SMark McLoughlin 29f7105843SMark McLoughlin typedef struct NetPacket NetPacket; 30f7105843SMark McLoughlin typedef struct NetQueue NetQueue; 31f7105843SMark McLoughlin 324e68f7a0SStefan Hajnoczi typedef void (NetPacketSent) (NetClientState *sender, ssize_t ret); 33f7105843SMark McLoughlin 34c0b8e49cSMark McLoughlin #define QEMU_NET_PACKET_FLAG_NONE 0 35ca77d175SMark McLoughlin #define QEMU_NET_PACKET_FLAG_RAW (1<<0) 36c0b8e49cSMark McLoughlin 373e033a46SYang Hongyang /* Returns: 383e033a46SYang Hongyang * >0 - success 393e033a46SYang Hongyang * 0 - queue packet for future redelivery 403e033a46SYang Hongyang * <0 - failure (discard packet) 413e033a46SYang Hongyang */ 423e033a46SYang Hongyang typedef ssize_t (NetQueueDeliverFunc)(NetClientState *sender, 433e033a46SYang Hongyang unsigned flags, 443e033a46SYang Hongyang const struct iovec *iov, 453e033a46SYang Hongyang int iovcnt, 463e033a46SYang Hongyang void *opaque); 473e033a46SYang Hongyang 483e033a46SYang Hongyang NetQueue *qemu_new_net_queue(NetQueueDeliverFunc *deliver, void *opaque); 4986a77c38SZhi Yong Wu 50*b68c7f76SYang Hongyang void qemu_net_queue_append_iov(NetQueue *queue, 51*b68c7f76SYang Hongyang NetClientState *sender, 52*b68c7f76SYang Hongyang unsigned flags, 53*b68c7f76SYang Hongyang const struct iovec *iov, 54*b68c7f76SYang Hongyang int iovcnt, 55*b68c7f76SYang Hongyang NetPacketSent *sent_cb); 56*b68c7f76SYang Hongyang 57f7105843SMark McLoughlin void qemu_del_net_queue(NetQueue *queue); 58f7105843SMark McLoughlin 59f7105843SMark McLoughlin ssize_t qemu_net_queue_send(NetQueue *queue, 604e68f7a0SStefan Hajnoczi NetClientState *sender, 61c0b8e49cSMark McLoughlin unsigned flags, 62f7105843SMark McLoughlin const uint8_t *data, 63f7105843SMark McLoughlin size_t size, 64f7105843SMark McLoughlin NetPacketSent *sent_cb); 65f7105843SMark McLoughlin 66f7105843SMark McLoughlin ssize_t qemu_net_queue_send_iov(NetQueue *queue, 674e68f7a0SStefan Hajnoczi NetClientState *sender, 68c0b8e49cSMark McLoughlin unsigned flags, 69f7105843SMark McLoughlin const struct iovec *iov, 70f7105843SMark McLoughlin int iovcnt, 71f7105843SMark McLoughlin NetPacketSent *sent_cb); 72f7105843SMark McLoughlin 734e68f7a0SStefan Hajnoczi void qemu_net_queue_purge(NetQueue *queue, NetClientState *from); 74987a9b48SPaolo Bonzini bool qemu_net_queue_flush(NetQueue *queue); 75f7105843SMark McLoughlin 76f7105843SMark McLoughlin #endif /* QEMU_NET_QUEUE_H */ 77