Skip to content

Commit 419556b

Browse files
authored
Merge pull request #11735 from michalpasztamobica/dns_unittest_preparation
Dns unittest preparation
2 parents 6f53899 + 4597641 commit 419556b

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

features/netsocket/nsapi_dns.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <string.h>
2424
#include <stdlib.h>
2525
#include <stdio.h>
26+
#include <stdint.h>
2627
#include "mbed_shared_queues.h"
2728
#include "events/EventQueue.h"
2829
#include "OnboardNetworkStack.h"
@@ -63,7 +64,7 @@ enum dns_state {
6364
};
6465

6566
struct DNS_QUERY {
66-
int unique_id;
67+
intptr_t unique_id;
6768
nsapi_error_t status;
6869
NetworkStack *stack;
6970
char *host;
@@ -94,7 +95,7 @@ static void nsapi_dns_cache_reset();
9495
static nsapi_error_t nsapi_dns_get_server_addr(NetworkStack *stack, uint8_t *index, uint8_t *total_attempts, uint8_t *send_success, SocketAddress *dns_addr, const char *interface_name);
9596

9697
static void nsapi_dns_query_async_create(void *ptr);
97-
static nsapi_error_t nsapi_dns_query_async_delete(int unique_id);
98+
static nsapi_error_t nsapi_dns_query_async_delete(intptr_t unique_id);
9899
static void nsapi_dns_query_async_send(void *ptr);
99100
static void nsapi_dns_query_async_timeout(void);
100101
static void nsapi_dns_query_async_resp(DNS_QUERY *query, nsapi_error_t status, SocketAddress *address);
@@ -122,7 +123,7 @@ static SingletonPtr<PlatformMutex> dns_cache_mutex;
122123
#endif
123124

124125
static uint16_t dns_message_id = 1;
125-
static int dns_unique_id = 1;
126+
static intptr_t dns_unique_id = 1;
126127
static DNS_QUERY *dns_query_queue[DNS_QUERY_QUEUE_SIZE];
127128
// Protects from several threads running asynchronous DNS
128129
static SingletonPtr<PlatformMutex> dns_mutex;
@@ -638,6 +639,8 @@ void nsapi_dns_call_in_set(call_in_callback_cb_t callback)
638639
void nsapi_dns_reset()
639640
{
640641
nsapi_dns_cache_reset();
642+
dns_message_id = 1;
643+
dns_unique_id = 1;
641644
}
642645

643646
nsapi_error_t nsapi_dns_call_in(call_in_callback_cb_t cb, int delay, mbed::Callback<void()> func)
@@ -765,7 +768,7 @@ nsapi_value_or_error_t nsapi_dns_query_multiple_async(NetworkStack *stack, const
765768

766769
static void nsapi_dns_query_async_initiate_next(void)
767770
{
768-
int id = INT32_MAX;
771+
intptr_t id = INTPTR_MAX;
769772
DNS_QUERY *query = NULL;
770773

771774
// Trigger next query to start, find one that has been on queue longest
@@ -842,7 +845,7 @@ static void nsapi_dns_query_async_timeout(void)
842845
dns_mutex->unlock();
843846
}
844847

845-
nsapi_error_t nsapi_dns_query_async_cancel(int id)
848+
nsapi_error_t nsapi_dns_query_async_cancel(nsapi_size_or_error_t id)
846849
{
847850
dns_mutex->lock();
848851

@@ -874,7 +877,7 @@ static void nsapi_dns_query_async_create(void *ptr)
874877
{
875878
dns_mutex->lock();
876879

877-
int unique_id = reinterpret_cast<int>(ptr);
880+
intptr_t unique_id = reinterpret_cast<intptr_t>(ptr);
878881

879882
DNS_QUERY *query = NULL;
880883

@@ -940,7 +943,7 @@ static void nsapi_dns_query_async_create(void *ptr)
940943

941944
}
942945

943-
static nsapi_error_t nsapi_dns_query_async_delete(int unique_id)
946+
static nsapi_error_t nsapi_dns_query_async_delete(intptr_t unique_id)
944947
{
945948
int index = -1;
946949
DNS_QUERY *query = NULL;
@@ -1000,7 +1003,7 @@ static void nsapi_dns_query_async_send(void *ptr)
10001003
{
10011004
dns_mutex->lock();
10021005

1003-
int unique_id = reinterpret_cast<int>(ptr);
1006+
intptr_t unique_id = reinterpret_cast<intptr_t>(ptr);
10041007

10051008
DNS_QUERY *query = NULL;
10061009

@@ -1162,7 +1165,7 @@ static void nsapi_dns_query_async_response(void *ptr)
11621165
{
11631166
dns_mutex->lock();
11641167

1165-
int unique_id = reinterpret_cast<int>(ptr);
1168+
intptr_t unique_id = reinterpret_cast<intptr_t>(ptr);
11661169

11671170
DNS_QUERY *query = NULL;
11681171

features/netsocket/nsapi_dns.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ nsapi_size_or_error_t nsapi_dns_query_multiple(S *stack, const char *host,
216216
* @param id Unique id of the hostname translation operation
217217
* @return 0 on success, negative error code on failure
218218
*/
219-
nsapi_error_t nsapi_dns_query_async_cancel(nsapi_error_t id);
219+
nsapi_error_t nsapi_dns_query_async_cancel(nsapi_size_or_error_t id);
220220

221221
/** Set a call in callback
222222
*

0 commit comments

Comments
 (0)