mbed port of tinydtls
netq.h@1:bc8a649bad13, 2013-10-11 (annotated)
- Committer:
- ashleymills
- Date:
- Fri Oct 11 08:46:21 2013 +0000
- Revision:
- 1:bc8a649bad13
- Parent:
- 0:04990d454f45
Cleaned up all the debug stuff I added finding the hash table bug.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 0:04990d454f45 | 1 | /* netq.h -- Simple packet queue |
ashleymills | 0:04990d454f45 | 2 | * |
ashleymills | 0:04990d454f45 | 3 | * Copyright (C) 2010--2012 Olaf Bergmann <bergmann@tzi.org> |
ashleymills | 0:04990d454f45 | 4 | * |
ashleymills | 0:04990d454f45 | 5 | * This file is part of the library tinyDTLS. Please see the file |
ashleymills | 0:04990d454f45 | 6 | * LICENSE for terms of use. |
ashleymills | 0:04990d454f45 | 7 | */ |
ashleymills | 0:04990d454f45 | 8 | |
ashleymills | 0:04990d454f45 | 9 | #ifndef _NETQ_H_ |
ashleymills | 0:04990d454f45 | 10 | #define _NETQ_H_ |
ashleymills | 0:04990d454f45 | 11 | |
ashleymills | 0:04990d454f45 | 12 | #include "config.h" |
ashleymills | 0:04990d454f45 | 13 | #include "global.h" |
ashleymills | 0:04990d454f45 | 14 | //#include "dtls.h" |
ashleymills | 0:04990d454f45 | 15 | #include "time.h" |
ashleymills | 0:04990d454f45 | 16 | #include "peer.h" |
ashleymills | 0:04990d454f45 | 17 | |
ashleymills | 0:04990d454f45 | 18 | /** |
ashleymills | 0:04990d454f45 | 19 | * \defgroup netq Network Packet Queue |
ashleymills | 0:04990d454f45 | 20 | * The netq utility functions implement an ordered queue of data packets |
ashleymills | 0:04990d454f45 | 21 | * to send over the network and can also be used to queue received packets |
ashleymills | 0:04990d454f45 | 22 | * from the network. |
ashleymills | 0:04990d454f45 | 23 | * @{ |
ashleymills | 0:04990d454f45 | 24 | */ |
ashleymills | 0:04990d454f45 | 25 | |
ashleymills | 0:04990d454f45 | 26 | #ifndef NETQ_MAXCNT |
ashleymills | 0:04990d454f45 | 27 | #define NETQ_MAXCNT 4 /**< maximum number of elements in netq structure */ |
ashleymills | 0:04990d454f45 | 28 | #endif |
ashleymills | 0:04990d454f45 | 29 | |
ashleymills | 0:04990d454f45 | 30 | /** |
ashleymills | 0:04990d454f45 | 31 | * Datagrams in the netq_t structure have a fixed maximum size of |
ashleymills | 0:04990d454f45 | 32 | * DTLS_MAX_BUF to simplify memory management on constrained nodes. */ |
ashleymills | 0:04990d454f45 | 33 | typedef unsigned char netq_packet_t[DTLS_MAX_BUF]; |
ashleymills | 0:04990d454f45 | 34 | |
ashleymills | 0:04990d454f45 | 35 | typedef struct netq_t { |
ashleymills | 0:04990d454f45 | 36 | struct netq_t *next; |
ashleymills | 0:04990d454f45 | 37 | |
ashleymills | 0:04990d454f45 | 38 | clock_time_t t; /**< when to send PDU for the next time */ |
ashleymills | 0:04990d454f45 | 39 | unsigned char retransmit_cnt; /**< retransmission counter, will be removed when zero */ |
ashleymills | 0:04990d454f45 | 40 | unsigned int timeout; /**< randomized timeout value */ |
ashleymills | 0:04990d454f45 | 41 | |
ashleymills | 0:04990d454f45 | 42 | dtls_peer_t *peer; /**< remote address */ |
ashleymills | 0:04990d454f45 | 43 | |
ashleymills | 0:04990d454f45 | 44 | size_t length; /**< actual length of data */ |
ashleymills | 0:04990d454f45 | 45 | netq_packet_t data; /**< the datagram to send */ |
ashleymills | 0:04990d454f45 | 46 | } netq_t; |
ashleymills | 0:04990d454f45 | 47 | |
ashleymills | 0:04990d454f45 | 48 | /** |
ashleymills | 0:04990d454f45 | 49 | * Adds a node to the given queue, ordered by their time-stamp t. |
ashleymills | 0:04990d454f45 | 50 | * This function returns @c 0 on error, or non-zero if @p node has |
ashleymills | 0:04990d454f45 | 51 | * been added successfully. |
ashleymills | 0:04990d454f45 | 52 | * |
ashleymills | 0:04990d454f45 | 53 | * @param queue A pointer to the queue head where @p node will be added. |
ashleymills | 0:04990d454f45 | 54 | * @param node The new item to add. |
ashleymills | 0:04990d454f45 | 55 | * @return @c 0 on error, or non-zero if the new item was added. |
ashleymills | 0:04990d454f45 | 56 | */ |
ashleymills | 0:04990d454f45 | 57 | int netq_insert_node(netq_t **queue, netq_t *node); |
ashleymills | 0:04990d454f45 | 58 | |
ashleymills | 0:04990d454f45 | 59 | /** Destroys specified node and releases any memory that was allocated |
ashleymills | 0:04990d454f45 | 60 | * for the associated datagram. */ |
ashleymills | 0:04990d454f45 | 61 | void netq_node_free(netq_t *node); |
ashleymills | 0:04990d454f45 | 62 | |
ashleymills | 0:04990d454f45 | 63 | /** Removes all items from given queue and frees the allocated storage */ |
ashleymills | 0:04990d454f45 | 64 | void netq_delete_all(netq_t *queue); |
ashleymills | 0:04990d454f45 | 65 | |
ashleymills | 0:04990d454f45 | 66 | /** Creates a new node suitable for adding to a netq_t queue. */ |
ashleymills | 0:04990d454f45 | 67 | netq_t *netq_node_new(); |
ashleymills | 0:04990d454f45 | 68 | |
ashleymills | 0:04990d454f45 | 69 | /** |
ashleymills | 0:04990d454f45 | 70 | * Returns a pointer to the first item in given queue or NULL if |
ashleymills | 0:04990d454f45 | 71 | * empty. |
ashleymills | 0:04990d454f45 | 72 | */ |
ashleymills | 0:04990d454f45 | 73 | netq_t *netq_head(netq_t **queue); |
ashleymills | 0:04990d454f45 | 74 | |
ashleymills | 0:04990d454f45 | 75 | /** |
ashleymills | 0:04990d454f45 | 76 | * Removes the first item in given queue and returns a pointer to the |
ashleymills | 0:04990d454f45 | 77 | * removed element. If queue is empty when netq_pop_first() is called, |
ashleymills | 0:04990d454f45 | 78 | * this function returns NULL. |
ashleymills | 0:04990d454f45 | 79 | */ |
ashleymills | 0:04990d454f45 | 80 | netq_t *netq_pop_first(netq_t **queue); |
ashleymills | 0:04990d454f45 | 81 | |
ashleymills | 0:04990d454f45 | 82 | /**@}*/ |
ashleymills | 0:04990d454f45 | 83 | |
ashleymills | 0:04990d454f45 | 84 | #endif /* _NETQ_H_ */ |