Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/coap/coapclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down
8 changes: 8 additions & 0 deletions src/coap/coapserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down