11422e32dSPaolo Bonzini /* 21422e32dSPaolo Bonzini * Copyright (c) 2003-2008 Fabrice Bellard 31422e32dSPaolo Bonzini * Copyright (c) 2009 Red Hat, Inc. 41422e32dSPaolo Bonzini * 51422e32dSPaolo Bonzini * Permission is hereby granted, free of charge, to any person obtaining a copy 61422e32dSPaolo Bonzini * of this software and associated documentation files (the "Software"), to deal 71422e32dSPaolo Bonzini * in the Software without restriction, including without limitation the rights 81422e32dSPaolo Bonzini * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 91422e32dSPaolo Bonzini * copies of the Software, and to permit persons to whom the Software is 101422e32dSPaolo Bonzini * furnished to do so, subject to the following conditions: 111422e32dSPaolo Bonzini * 121422e32dSPaolo Bonzini * The above copyright notice and this permission notice shall be included in 131422e32dSPaolo Bonzini * all copies or substantial portions of the Software. 141422e32dSPaolo Bonzini * 151422e32dSPaolo Bonzini * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 161422e32dSPaolo Bonzini * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 171422e32dSPaolo Bonzini * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 181422e32dSPaolo Bonzini * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 191422e32dSPaolo Bonzini * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 201422e32dSPaolo Bonzini * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 211422e32dSPaolo Bonzini * THE SOFTWARE. 221422e32dSPaolo Bonzini */ 231422e32dSPaolo Bonzini 241422e32dSPaolo Bonzini #ifndef QEMU_NET_QUEUE_H 251422e32dSPaolo Bonzini #define QEMU_NET_QUEUE_H 261422e32dSPaolo Bonzini 271422e32dSPaolo Bonzini 281422e32dSPaolo Bonzini typedef struct NetPacket NetPacket; 291422e32dSPaolo Bonzini typedef struct NetQueue NetQueue; 301422e32dSPaolo Bonzini 311422e32dSPaolo Bonzini typedef void (NetPacketSent) (NetClientState *sender, ssize_t ret); 321422e32dSPaolo Bonzini 331422e32dSPaolo Bonzini #define QEMU_NET_PACKET_FLAG_NONE 0 341422e32dSPaolo Bonzini #define QEMU_NET_PACKET_FLAG_RAW (1<<0) 351422e32dSPaolo Bonzini 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); 481422e32dSPaolo Bonzini 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 561422e32dSPaolo Bonzini void qemu_del_net_queue(NetQueue *queue); 571422e32dSPaolo Bonzini 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 621422e32dSPaolo Bonzini ssize_t qemu_net_queue_send(NetQueue *queue, 631422e32dSPaolo Bonzini NetClientState *sender, 641422e32dSPaolo Bonzini unsigned flags, 651422e32dSPaolo Bonzini const uint8_t *data, 661422e32dSPaolo Bonzini size_t size, 671422e32dSPaolo Bonzini NetPacketSent *sent_cb); 681422e32dSPaolo Bonzini 691422e32dSPaolo Bonzini ssize_t qemu_net_queue_send_iov(NetQueue *queue, 701422e32dSPaolo Bonzini NetClientState *sender, 711422e32dSPaolo Bonzini unsigned flags, 721422e32dSPaolo Bonzini const struct iovec *iov, 731422e32dSPaolo Bonzini int iovcnt, 741422e32dSPaolo Bonzini NetPacketSent *sent_cb); 751422e32dSPaolo Bonzini 761422e32dSPaolo Bonzini void qemu_net_queue_purge(NetQueue *queue, NetClientState *from); 771422e32dSPaolo Bonzini bool qemu_net_queue_flush(NetQueue *queue); 781422e32dSPaolo Bonzini 791422e32dSPaolo Bonzini #endif /* QEMU_NET_QUEUE_H */ 80