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 28f7105843SMark McLoughlin typedef struct NetPacket NetPacket; 29f7105843SMark McLoughlin typedef struct NetQueue NetQueue; 30f7105843SMark McLoughlin 314e68f7a0SStefan Hajnoczi typedef void (NetPacketSent) (NetClientState *sender, ssize_t ret); 32f7105843SMark McLoughlin 33c0b8e49cSMark McLoughlin #define QEMU_NET_PACKET_FLAG_NONE 0 34ca77d175SMark McLoughlin #define QEMU_NET_PACKET_FLAG_RAW (1<<0) 35c0b8e49cSMark McLoughlin 363e033a46SYang Hongyang /* Returns: 373e033a46SYang Hongyang * >0 - success 383e033a46SYang Hongyang * 0 - queue packet for future redelivery 393e033a46SYang Hongyang * <0 - failure (discard packet) 403e033a46SYang Hongyang */ 413e033a46SYang Hongyang typedef ssize_t (NetQueueDeliverFunc)(NetClientState *sender, 423e033a46SYang Hongyang unsigned flags, 433e033a46SYang Hongyang const struct iovec *iov, 443e033a46SYang Hongyang int iovcnt, 453e033a46SYang Hongyang void *opaque); 463e033a46SYang Hongyang 473e033a46SYang Hongyang NetQueue *qemu_new_net_queue(NetQueueDeliverFunc *deliver, void *opaque); 4886a77c38SZhi Yong Wu 49b68c7f76SYang Hongyang void qemu_net_queue_append_iov(NetQueue *queue, 50b68c7f76SYang Hongyang NetClientState *sender, 51b68c7f76SYang Hongyang unsigned flags, 52b68c7f76SYang Hongyang const struct iovec *iov, 53b68c7f76SYang Hongyang int iovcnt, 54b68c7f76SYang Hongyang NetPacketSent *sent_cb); 55b68c7f76SYang Hongyang 56f7105843SMark McLoughlin void qemu_del_net_queue(NetQueue *queue); 57f7105843SMark McLoughlin 58*705df546SJason Wang ssize_t qemu_net_queue_receive(NetQueue *queue, 59*705df546SJason Wang const uint8_t *data, 60*705df546SJason Wang size_t size); 61*705df546SJason Wang 62f7105843SMark McLoughlin ssize_t qemu_net_queue_send(NetQueue *queue, 634e68f7a0SStefan Hajnoczi NetClientState *sender, 64c0b8e49cSMark McLoughlin unsigned flags, 65f7105843SMark McLoughlin const uint8_t *data, 66f7105843SMark McLoughlin size_t size, 67f7105843SMark McLoughlin NetPacketSent *sent_cb); 68f7105843SMark McLoughlin 69f7105843SMark McLoughlin ssize_t qemu_net_queue_send_iov(NetQueue *queue, 704e68f7a0SStefan Hajnoczi NetClientState *sender, 71c0b8e49cSMark McLoughlin unsigned flags, 72f7105843SMark McLoughlin const struct iovec *iov, 73f7105843SMark McLoughlin int iovcnt, 74f7105843SMark McLoughlin NetPacketSent *sent_cb); 75f7105843SMark McLoughlin 764e68f7a0SStefan Hajnoczi void qemu_net_queue_purge(NetQueue *queue, NetClientState *from); 77987a9b48SPaolo Bonzini bool qemu_net_queue_flush(NetQueue *queue); 78f7105843SMark McLoughlin 79f7105843SMark McLoughlin #endif /* QEMU_NET_QUEUE_H */ 80