diff --git a/src/coap/coapclient.c b/src/coap/coapclient.c index a4c8238..1f5b9e2 100755 --- a/src/coap/coapclient.c +++ b/src/coap/coapclient.c @@ -32,11 +32,15 @@ static osal_basetype_t m_sock = 0; static bool m_client_opened = false; static uint16_t m_transaction_id = 0; static osal_task_t recvt_id_task; + +#ifndef USE_EXTERNAL_RECV_TASKS #if defined(OSAL_LINUX) static void *recv_fn(void*); #else static void recv_fn(void*); #endif +#endif + int write_option( uint8_t *buf, uint16_t buf_len, coap_option_t this_option, coap_option_t *last_option, const uint8_t* option_buf, uint32_t option_len, uint32_t *written_len ); void process_response(uint8_t* data, uint16_t len, struct sockaddr_in6 *from); @@ -45,7 +49,9 @@ void coap_option_map(uint32_t val, uint8_t *map); int coapclient_stop() { m_client_opened = false; +#ifndef USE_EXTERNAL_RECV_TASKS osal_task_cancel(recvt_id_task); +#endif return close(m_sock); } @@ -72,9 +78,11 @@ int coapclient_open(response_handler_t response_handler) m_sock = sockfd; m_client_opened = true; +#ifndef USE_EXTERNAL_RECV_TASKS ret = osal_task_create(&recvt_id_task, NULL, 0, 0, recv_fn, NULL); DPRINTF("CoapClient.open - %s.\n" , (ret == OSAL_SUCCESS) ? "task created" : "task creation failed"); assert(ret == OSAL_SUCCESS); +#endif return 0; } @@ -236,6 +244,8 @@ void coap_option_map(uint32_t val, uint8_t *map) else if (val <= 0xffff + 269) *map = 14; } + +#ifndef USE_EXTERNAL_RECV_TASKS #if defined(OSAL_LINUX) static void *recv_fn(void* arg) #else @@ -270,6 +280,7 @@ static void recv_fn(void* arg) return NULL; #endif } +#endif void process_response(uint8_t* data, uint16_t len, struct sockaddr_in6 *from) { diff --git a/src/coap/coapserver.c b/src/coap/coapserver.c index 7ee6a1e..399fe9a 100755 --- a/src/coap/coapserver.c +++ b/src/coap/coapserver.c @@ -36,16 +36,20 @@ static recv_handler_t m_recv_handler = NULL; void process_datagram(void *data, uint16_t len, struct sockaddr_in6 *from ); void send_internal_response(const struct sockaddr_in6 *from, uint16_t tx_id, uint8_t token_length, uint8_t *token, uint16_t status); +#ifndef USE_EXTERNAL_RECV_TASKS #if defined(OSAL_LINUX) static void *recv_thread(void* arg); #else static void recv_thread(void* arg); #endif +#endif int coapserver_stop() { m_server_opened = false; +#ifndef USE_EXTERNAL_RECV_TASKS osal_task_cancel(recvt_id_task); +#endif return close(m_sockfd); } @@ -85,13 +89,16 @@ int coapserver_listen(uint16_t sport, recv_handler_t recv_handler) m_sockfd = sockfd; m_server_opened = true; +#ifndef USE_EXTERNAL_RECV_TASKS ret = osal_task_create(&recvt_id_task, NULL, 0, 0, recv_thread, NULL); DPRINTF("coapserver - %s.\n" , (ret == OSAL_SUCCESS) ? "task created" : "task creation failed"); assert(ret == OSAL_SUCCESS); +#endif return 0; } +#ifndef USE_EXTERNAL_RECV_TASKS #ifdef OSAL_LINUX static void *recv_thread(void* arg) #else @@ -135,6 +142,7 @@ static void recv_thread(void* arg) return NULL; #endif } +#endif int coapserver_response(const struct sockaddr_in6 *to, coap_transaction_type_t tx_type,