Skip to content

Commit 21d21c5

Browse files
author
Mika Leppänen
committed
Changed mutexes, delete and DNS call in callback set
- Changed mutexes to platform mutexes - Removed not needed null check from delete - Changed nsapi_dns_call_in_set() to use call_in_callback_cb_t and added prototype to header
1 parent 0483cca commit 21d21c5

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

features/netsocket/nsapi_dns.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "EventQueue.h"
2828
#include "OnboardNetworkStack.h"
2929
#include "Kernel.h"
30+
#include "PlatformMutex.h"
3031

3132
#define CLASS_IN 1
3233

@@ -76,9 +77,6 @@ struct DNS_QUERY {
7677
uint8_t count;
7778
};
7879

79-
typedef nsapi_error_t (*nsapi_dns_call_t)(mbed::Callback<void()> func);
80-
typedef nsapi_error_t (*nsapi_dns_call_in_t)(int delay, mbed::Callback<void()> func);
81-
8280
static void nsapi_dns_cache_add(const char *host, nsapi_addr_t *address, uint32_t ttl);
8381
static nsapi_size_or_error_t nsapi_dns_cache_find(const char *host, nsapi_version_t version, nsapi_addr_t *address);
8482

@@ -107,10 +105,10 @@ static uint16_t dns_message_id = 1;
107105
static int dns_unique_id = 1;
108106
static DNS_QUERY *dns_query_queue[DNS_QUERY_QUEUE_SIZE];
109107
// Protects cache shared between blocking and asynchronous calls
110-
static rtos::Mutex dns_cache_mutex;
108+
static PlatformMutex dns_cache_mutex;
111109
// Protects from several threads running asynchronous DNS
112-
static rtos::Mutex dns_mutex;
113-
static nsapi_dns_call_in_t dns_call_in = 0;
110+
static PlatformMutex dns_mutex;
111+
static call_in_callback_cb_t dns_call_in = 0;
114112

115113
// DNS server configuration
116114
extern "C" nsapi_error_t nsapi_dns_add_server(nsapi_addr_t addr)
@@ -558,7 +556,7 @@ nsapi_value_or_error_t nsapi_dns_query_async(NetworkStack *stack, const char *ho
558556
return nsapi_dns_query_multiple_async(stack, host, callback, 0, call_in_cb, version);
559557
}
560558

561-
void nsapi_dns_call_in_set(nsapi_dns_call_in_t callback)
559+
void nsapi_dns_call_in_set(call_in_callback_cb_t callback)
562560
{
563561
dns_call_in = callback;
564562
}
@@ -1069,9 +1067,7 @@ static void nsapi_dns_query_async_response(void *ptr)
10691067

10701068
nsapi_dns_query_async_resp(query, status, addresses);
10711069

1072-
if (addresses) {
1073-
delete[] addresses;
1074-
}
1070+
delete[] addresses;
10751071
} else {
10761072
dns_mutex.unlock();
10771073
}

features/netsocket/nsapi_dns.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ nsapi_size_or_error_t nsapi_dns_query_multiple(S *stack, const char *host,
188188
*/
189189
nsapi_error_t nsapi_dns_query_async_cancel(nsapi_error_t id);
190190

191+
/** Set a call in callback
192+
*
193+
* Can be used to provide an application specific call in callback to
194+
* DNS resolver. When callback is set it is used instead of stack
195+
* specific call in callbacks.
196+
*
197+
* @param callback Callback
198+
*/
199+
void nsapi_dns_call_in_set(call_in_callback_cb_t callback);
200+
191201
/** Add a domain name server to list of servers to query
192202
*
193203
* @param addr Destination for the host address

0 commit comments

Comments
 (0)