646d7adc9d51df3aa40a85d908fa3c079d3cf12d
[strongswan.git] / Source / charon / queues / send_queue.h
1 /**
2 * @file send_queue.h
3 *
4 * @brief Interface of send_queue_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef SEND_QUEUE_H_
24 #define SEND_QUEUE_H_
25
26 #include <types.h>
27 #include <network/packet.h>
28
29
30 typedef struct send_queue_t send_queue_t;
31
32 /**
33 * @brief Send-Queue
34 *
35 * Although the send-queue is based on a linked_list_t
36 * all access functions are thread-save implemented.
37 *
38 * @ingroup queues
39 */
40 struct send_queue_t {
41
42 /**
43 * @brief returns number of packets in queue
44 *
45 * @param send_queue_t calling object
46 * @param[out] count integer pointer to store the count in
47 * @returns number of items in queue
48 */
49 int (*get_count) (send_queue_t *send_queue);
50
51 /**
52 * @brief get the next packet from the queue.
53 *
54 * If the queue is empty, this function blocks until a packet can be returned.
55 *
56 * After using, the returned packet has to get destroyed by the caller.
57 *
58 * @param send_queue_t calling object
59 * @return next packet from the queue
60 */
61 packet_t *(*get) (send_queue_t *send_queue);
62
63 /**
64 * @brief adds a packet to the queue.
65 *
66 * This function is non blocking and adds a packet_t to the list.
67 * The specific packet object has to get destroyed by the thread which
68 * removes the packet.
69 *
70 * @param send_queue_t calling object
71 * @param packet packet_t to add to the queue (packet is not copied)
72 */
73 void (*add) (send_queue_t *send_queue, packet_t *packet);
74
75 /**
76 * @brief destroys a send_queue object.
77 *
78 * @warning The caller of this function has to make sure
79 * that no thread is going to add or get a packet from the send_queue
80 * after calling this function.
81 *
82 * @param send_queue_t calling object
83 */
84 void (*destroy) (send_queue_t *send_queue);
85 };
86
87 /**
88 * @brief Creates an empty send_queue_t.
89 *
90 * @return send_queue_t empty send_queue_t
91 *
92 * @ingroup queues
93 */
94 send_queue_t *send_queue_create();
95
96 #endif /*SEND_QUEUE_H_*/