53 #define LOG_MODULE "coap" 54 #define LOG_LEVEL LOG_LEVEL_COAP 57 MEMB(transactions_memb, coap_transaction_t, COAP_MAX_OPEN_TRANSACTIONS);
58 LIST(transactions_list);
62 coap_retransmit_transaction(coap_timer_t *nt)
66 LOG_DBG(
"No retransmission data in coap_timer!\n");
69 ++(t->retrans_counter);
70 LOG_DBG(
"Retransmitting %u (%u)\n", t->mid, t->retrans_counter);
71 coap_send_transaction(t);
79 coap_new_transaction(uint16_t mid,
const coap_endpoint_t *endpoint)
81 coap_transaction_t *t =
memb_alloc(&transactions_memb);
85 t->retrans_counter = 0;
97 coap_send_transaction(coap_transaction_t *t)
99 LOG_DBG(
"Sending transaction %u\n", t->mid);
102 ((COAP_HEADER_TYPE_MASK & t->message[0]) >> COAP_HEADER_TYPE_POSITION)) {
103 if(t->retrans_counter <= COAP_MAX_RETRANSMIT) {
105 coap_sendto(&t->endpoint, t->message, t->message_len);
106 LOG_DBG(
"Keeping transaction %u\n", t->mid);
108 if(t->retrans_counter == 0) {
111 t->retrans_interval =
112 COAP_RESPONSE_TIMEOUT_TICKS + (rand() %
113 COAP_RESPONSE_TIMEOUT_BACKOFF_MASK);
114 LOG_DBG(
"Initial interval %lu msec\n",
115 (
unsigned long)t->retrans_interval);
117 t->retrans_interval <<= 1;
118 LOG_DBG(
"Doubled (%u) interval %lu s\n", t->retrans_counter,
119 (
unsigned long)(t->retrans_interval / 1000));
126 LOG_DBG(
"Timeout\n");
127 coap_resource_response_handler_t callback = t->callback;
128 void *callback_data = t->callback_data;
131 coap_remove_observer_by_client(&t->endpoint);
133 coap_clear_transaction(t);
136 callback(callback_data, NULL);
140 coap_sendto(&t->endpoint, t->message, t->message_len);
141 coap_clear_transaction(t);
146 coap_clear_transaction(coap_transaction_t *t)
149 LOG_DBG(
"Freeing transaction %u: %p\n", t->mid, t);
158 coap_get_transaction_by_mid(uint16_t mid)
160 coap_transaction_t *t = NULL;
162 for(t = (coap_transaction_t *)
list_head(transactions_list); t; t = t->next) {
164 LOG_DBG(
"Found transaction for MID %u: %p\n", t->mid, t);
CoAP module for observing resources (draft-ietf-core-observe-11).
static void * coap_timer_get_user_data(coap_timer_t *timer)
Get user data that has been attached to a CoAP timer.
static void coap_timer_set_callback(coap_timer_t *timer, void(*callback)(coap_timer_t *))
Set a callback function to be called when a CoAP timer expires.
Linked list manipulation routines.
void * list_head(list_t list)
Get a pointer to the first element of a list.
int coap_sendto(const coap_endpoint_t *ep, const uint8_t *data, uint16_t len)
Send a message to the specified CoAP endpoint.
Memory block allocation routines.
void list_add(list_t list, void *item)
Add an item at the end of a list.
#define LIST(name)
Declare a linked list.
void * memb_alloc(struct memb *m)
Allocate a memory block from a block of memory declared with MEMB().
static void coap_timer_set_user_data(coap_timer_t *timer, void *data)
Attach user data to a CoAP timer.
void coap_endpoint_copy(coap_endpoint_t *dest, const coap_endpoint_t *src)
Copy a CoAP endpoint from one memory area to another.
void coap_timer_stop(coap_timer_t *timer)
Stop a pending CoAP timer.
CoAP module for reliable transport
void coap_timer_set(coap_timer_t *timer, uint64_t time)
Set a CoAP timer to expire after the specified time.
char memb_free(struct memb *m, void *ptr)
Deallocate a memory block from a memory block previously declared with MEMB().
void list_remove(list_t list, void *item)
Remove a specific element from a list.
#define MEMB(name, structure, num)
Declare a memory block.