xref: /qemu/include/net/queue.h (revision 3e033a46a7e39ea31e15f1b53402df990977115a)
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 
37*3e033a46SYang Hongyang /* Returns:
38*3e033a46SYang Hongyang  *   >0 - success
39*3e033a46SYang Hongyang  *    0 - queue packet for future redelivery
40*3e033a46SYang Hongyang  *   <0 - failure (discard packet)
41*3e033a46SYang Hongyang  */
42*3e033a46SYang Hongyang typedef ssize_t (NetQueueDeliverFunc)(NetClientState *sender,
43*3e033a46SYang Hongyang                                       unsigned flags,
44*3e033a46SYang Hongyang                                       const struct iovec *iov,
45*3e033a46SYang Hongyang                                       int iovcnt,
46*3e033a46SYang Hongyang                                       void *opaque);
47*3e033a46SYang Hongyang 
48*3e033a46SYang Hongyang NetQueue *qemu_new_net_queue(NetQueueDeliverFunc *deliver, void *opaque);
4986a77c38SZhi Yong Wu 
50f7105843SMark McLoughlin void qemu_del_net_queue(NetQueue *queue);
51f7105843SMark McLoughlin 
52f7105843SMark McLoughlin ssize_t qemu_net_queue_send(NetQueue *queue,
534e68f7a0SStefan Hajnoczi                             NetClientState *sender,
54c0b8e49cSMark McLoughlin                             unsigned flags,
55f7105843SMark McLoughlin                             const uint8_t *data,
56f7105843SMark McLoughlin                             size_t size,
57f7105843SMark McLoughlin                             NetPacketSent *sent_cb);
58f7105843SMark McLoughlin 
59f7105843SMark McLoughlin ssize_t qemu_net_queue_send_iov(NetQueue *queue,
604e68f7a0SStefan Hajnoczi                                 NetClientState *sender,
61c0b8e49cSMark McLoughlin                                 unsigned flags,
62f7105843SMark McLoughlin                                 const struct iovec *iov,
63f7105843SMark McLoughlin                                 int iovcnt,
64f7105843SMark McLoughlin                                 NetPacketSent *sent_cb);
65f7105843SMark McLoughlin 
664e68f7a0SStefan Hajnoczi void qemu_net_queue_purge(NetQueue *queue, NetClientState *from);
67987a9b48SPaolo Bonzini bool qemu_net_queue_flush(NetQueue *queue);
68f7105843SMark McLoughlin 
69f7105843SMark McLoughlin #endif /* QEMU_NET_QUEUE_H */
70