queue.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2003-2008 Fabrice Bellard
  3. * Copyright (c) 2009 Red Hat, Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. #ifndef QEMU_NET_QUEUE_H
  24. #define QEMU_NET_QUEUE_H
  25. typedef struct NetPacket NetPacket;
  26. typedef struct NetQueue NetQueue;
  27. typedef void (NetPacketSent) (NetClientState *sender, ssize_t ret);
  28. #define QEMU_NET_PACKET_FLAG_NONE 0
  29. #define QEMU_NET_PACKET_FLAG_RAW (1<<0)
  30. /* Returns:
  31. * >0 - success
  32. * 0 - queue packet for future redelivery
  33. * <0 - failure (discard packet)
  34. */
  35. typedef ssize_t (NetQueueDeliverFunc)(NetClientState *sender,
  36. unsigned flags,
  37. const struct iovec *iov,
  38. int iovcnt,
  39. void *opaque);
  40. NetQueue *qemu_new_net_queue(NetQueueDeliverFunc *deliver, void *opaque);
  41. void qemu_net_queue_append_iov(NetQueue *queue,
  42. NetClientState *sender,
  43. unsigned flags,
  44. const struct iovec *iov,
  45. int iovcnt,
  46. NetPacketSent *sent_cb);
  47. void qemu_del_net_queue(NetQueue *queue);
  48. ssize_t qemu_net_queue_receive(NetQueue *queue,
  49. const uint8_t *data,
  50. size_t size);
  51. ssize_t qemu_net_queue_send(NetQueue *queue,
  52. NetClientState *sender,
  53. unsigned flags,
  54. const uint8_t *data,
  55. size_t size,
  56. NetPacketSent *sent_cb);
  57. ssize_t qemu_net_queue_send_iov(NetQueue *queue,
  58. NetClientState *sender,
  59. unsigned flags,
  60. const struct iovec *iov,
  61. int iovcnt,
  62. NetPacketSent *sent_cb);
  63. void qemu_net_queue_purge(NetQueue *queue, NetClientState *from);
  64. bool qemu_net_queue_flush(NetQueue *queue);
  65. #endif /* QEMU_NET_QUEUE_H */