The packetqueue module handles a list of queued packets.
Data Structures | |
struct | packetqueue |
Representation of a packet queue. More... | |
struct | packetqueue_item |
Representation of an item in a packet queue. More... | |
Files | |
file | packetqueue.c |
Packet queue management | |
file | packetqueue.h |
Header file for the packetqueue module | |
Macros | |
#define | PACKETQUEUE(name, size) |
Define a packet queue. More... | |
Functions | |
static void | remove_queued_packet (void *item) |
Packet queue functions. | |
void | packetqueue_init (struct packetqueue *q) |
Initialize a packet queue. More... | |
int | packetqueue_enqueue_packetbuf (struct packetqueue *q, clock_time_t lifetime, void *ptr) |
Enqueue a packetbuf on a packet queue. More... | |
struct packetqueue_item * | packetqueue_first (struct packetqueue *q) |
Access the first item on the packet buffer. More... | |
void | packetqueue_dequeue (struct packetqueue *q) |
Remove the first item on the packet buffer. More... | |
int | packetqueue_len (struct packetqueue *q) |
Get the length of the packet queue. More... | |
Packet queue item functions | |
struct queuebuf * | packetqueue_queuebuf (struct packetqueue_item *i) |
Access the queuebuf in a packet queue item. More... | |
void * | packetqueue_ptr (struct packetqueue_item *i) |
Access the user-defined pointer in a packet queue item. More... | |
#define PACKETQUEUE | ( | name, | |
size | |||
) |
Define a packet queue.
name | The variable name of the packet queue |
size | The maximum size of the packet queue This statement defines a packet queue. A packet queue is defined on a per-module basis. |
void packetqueue_dequeue | ( | struct packetqueue * | q | ) |
Remove the first item on the packet buffer.
q | A pointer to a struct packetqueue. This function removes the first item on the packet queue. The function does not return the first item: to access the first item, the packetqueue_first() function must have been used prior to calling packetqueue_dequeue(). |
References packetqueue_item::buf, ctimer_stop(), i, packetqueue_item::lifetimer, list, list_head(), list_remove(), memb, memb_free(), NULL, and queuebuf_free().
int packetqueue_enqueue_packetbuf | ( | struct packetqueue * | q, |
clock_time_t | lifetime, | ||
void * | ptr | ||
) |
Enqueue a packetbuf on a packet queue.
q | A pointer to a struct packetqueue. |
lifetime | The maximum time that the packet should stay in the packet queue, or zero if the packet should stay on the packet queue indefinitely. |
ptr | An opaque, user-defined pointer that can be used to identify the packet when it later is dequeued. |
Zero | If memory could not be allocated for the packet. |
Non-zero | If the packet was successfully enqueued. |
This function enqueues the \ref packetbuf "packetbuf" to the packet queue pointed to by the q parameter. The packet queue must previously have been defined with PACKETQUEUE() and initialized with packetqueue_init(). Each packet queue item has a maximum lifetime. When the lifetime expires, the packet queue item is automatically removed from the packet queue. If the lifetime parameter is given as zero, the packet never times out from the packet queue. Each packet queue item is tagged with a user-defined pointer. This pointer can be used to identify packets as they later are dequeued from the queue. This is useful if two modules is using the same packet queue: the modules can use the pointer to distinguish to which module a dequeued packet belongs.
References packetqueue_item::buf, ctimer_set(), i, packetqueue_item::lifetimer, list, list_add(), memb, memb_alloc(), memb_free(), NULL, packetqueue_item::ptr, ptr, packetqueue_item::queue, queuebuf_new_from_packetbuf(), and remove_queued_packet().
struct packetqueue_item * packetqueue_first | ( | struct packetqueue * | q | ) |
Access the first item on the packet buffer.
q | A pointer to a struct packetqueue. |
This function returns the first item on the packet queue. The packet queue is unchanged by this function. To dequeue the first item on the list, use the packetqueue_dequeue() function.
References list, and list_head().
void packetqueue_init | ( | struct packetqueue * | q | ) |
Initialize a packet queue.
q | A pointer to a struct packetqueue that was defined with PACKETQUEUE(). This function initializes a packetqueue that has previously been defined with PACKETQUEUE(). |
References list, list_init(), memb, and memb_init().
int packetqueue_len | ( | struct packetqueue * | q | ) |
Get the length of the packet queue.
q | A pointer to a struct packetqueue. |
This function returns the number of packets that are queued on the packet queue.
References list, and list_length().
void * packetqueue_ptr | ( | struct packetqueue_item * | i | ) |
Access the user-defined pointer in a packet queue item.
i | A packet queue item, obtained with packetqueue_first(). |
References NULL, and packetqueue_item::ptr.
struct queuebuf * packetqueue_queuebuf | ( | struct packetqueue_item * | i | ) |
Access the queuebuf in a packet queue item.
i | A packet queue item, obtained with packetqueue_first(). |
References packetqueue_item::buf, and NULL.
|
static |
References packetqueue_item::buf, ctimer_stop(), i, packetqueue_item::lifetimer, list, list_remove(), memb, memb_free(), packetqueue_item::queue, and queuebuf_free().
Referenced by packetqueue_enqueue_packetbuf().