From f66b8d5d417e85e77c749644f76d06ac97b0db26 Mon Sep 17 00:00:00 2001 From: franc0is Date: Sun, 6 Sep 2015 19:25:39 -0700 Subject: [PATCH] WIP - Remove unused context pointer in endpoint and use NTOHS macro everywhere --- include/coap/coap_io.h | 2 -- platform/contiki/platform_utils.h | 1 + platform/lwip/platform_utils.h | 1 + platform/posix/platform_utils.h | 7 +++++++ src/coap_context.c | 3 --- src/pdu.c | 8 +++----- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/coap/coap_io.h b/include/coap/coap_io.h index 7e9b61cd11..47de3bfdb1 100644 --- a/include/coap/coap_io.h +++ b/include/coap/coap_io.h @@ -61,8 +61,6 @@ typedef struct coap_endpoint_t { #ifdef WITH_LWIP struct udp_pcb *pcb; - /**< @FIXME this was added in a hurry, not sure it confirms to the overall model --chrysn */ - struct coap_context_t *context; #endif /* WITH_LWIP */ coap_address_t addr; /**< local interface address */ diff --git a/platform/contiki/platform_utils.h b/platform/contiki/platform_utils.h index 687bd8da0f..5c66500c8e 100644 --- a/platform/contiki/platform_utils.h +++ b/platform/contiki/platform_utils.h @@ -2,5 +2,6 @@ #define _PLATFORM_UTILS_H_ #define HTONS(BYTES) uip_htons(BYTES); +#define NTOHS(BYTES) uip_ntohs(BYTES); #endif /* _PLATFORM_UTILS_H_ */ diff --git a/platform/lwip/platform_utils.h b/platform/lwip/platform_utils.h index 38c0c35ef2..391f9b730c 100644 --- a/platform/lwip/platform_utils.h +++ b/platform/lwip/platform_utils.h @@ -2,5 +2,6 @@ #define _PLATFORM_UTILS_H_ #define HTONS(BYTES) htons(BYTES); +#define NTOHS(BYTES) ntohs(BYTES); #endif /* _PLATFORM_UTILS_H_ */ diff --git a/platform/posix/platform_utils.h b/platform/posix/platform_utils.h index 69743b9bd8..dd7766295f 100644 --- a/platform/posix/platform_utils.h +++ b/platform/posix/platform_utils.h @@ -1,4 +1,11 @@ #ifndef _PLATFORM_UTILS_H_ #define _PLATFORM_UTILS_H_ +#undef NTOHS +#define NTOHS(BYTES) ntohs(BYTES) + +#undef HTONS +#define HTONS(BYTES) htons(BYTES) + + #endif /* _PLATFORM_UTILS_H_ */ diff --git a/src/coap_context.c b/src/coap_context.c index bd4d9b8f55..a243af297a 100644 --- a/src/coap_context.c +++ b/src/coap_context.c @@ -113,9 +113,6 @@ coap_new_context( coap_register_option(c, COAP_OPTION_BLOCK1); c->endpoint = coap_new_endpoint(listen_addr, COAP_ENDPOINT_NOSEC); -#ifdef WITH_LWIP - c->endpoint->context = c; -#endif if (c->endpoint == NULL) { goto onerror; } diff --git a/src/pdu.c b/src/pdu.c index c1996970eb..959d14e74b 100644 --- a/src/pdu.c +++ b/src/pdu.c @@ -25,6 +25,8 @@ #include "encode.h" #include "mem.h" +#include "platform_utils.h" + void coap_pdu_clear(coap_pdu_t *pdu, size_t size) { assert(pdu); @@ -70,11 +72,7 @@ coap_pdu_t * coap_new_pdu(void) { coap_pdu_t *pdu; -#ifndef WITH_CONTIKI - pdu = coap_pdu_init(0, 0, ntohs(COAP_INVALID_TID), COAP_MAX_PDU_SIZE); -#else /* WITH_CONTIKI */ - pdu = coap_pdu_init(0, 0, uip_ntohs(COAP_INVALID_TID), COAP_MAX_PDU_SIZE); -#endif /* WITH_CONTIKI */ + pdu = coap_pdu_init(0, 0, NTOHS(COAP_INVALID_TID), COAP_MAX_PDU_SIZE); #ifndef NDEBUG if (!pdu)