Skip to content

Commit 0483cca

Browse files
author
Mika Leppänen
committed
Corrected more defects
- Serialized the sending of multiple async DNS queries since limits on event message box sizes - Added timer function that supervises the total time used to make DNS query and triggers socket timeouts - Changed nsapi_error_t to new nsapi_value_or_error_t on interface headers - Corrected wording of gethostbyname_async return values - Clarified .json options - Added a new data type for socket callback that can be used from interrupts - Corrected variable limits to use INT32_MAX etc. defines - Changed mallocs to new - Optimized variable sizes on DNS_QUERY definition
1 parent d4bfed8 commit 0483cca

File tree

8 files changed

+236
-108
lines changed

8 files changed

+236
-108
lines changed

features/netsocket/DNS.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ class DNS {
6969
* @param callback Callback that is called for result
7070
* @param version IP version of address to resolve, NSAPI_UNSPEC indicates
7171
* version is chosen by the stack (defaults to NSAPI_UNSPEC)
72-
* @return 0 on success, negative error code on failure or an unique id that
73-
* represents the hostname translation operation and can be passed to
74-
* cancel
72+
* @return 0 on immediate success,
73+
* negative error code on immediate failure or
74+
* a positive unique id that represents the hostname translation operation
75+
* and can be passed to cancel
7576
*/
76-
virtual nsapi_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback,
77+
virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback,
7778
nsapi_version_t version = NSAPI_UNSPEC) = 0;
7879

7980
/** Cancels asynchronous hostname translation
@@ -83,7 +84,7 @@ class DNS {
8384
* @param id Unique id of the hostname translation operation
8485
* @return 0 on success, negative error code on failure
8586
*/
86-
virtual nsapi_error_t gethostbyname_async_cancel(nsapi_error_t id) = 0;
87+
virtual nsapi_error_t gethostbyname_async_cancel(int id) = 0;
8788

8889
/** Add a domain name server to list of servers to query
8990
*

features/netsocket/NetworkInterface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ nsapi_error_t NetworkInterface::gethostbyname(const char *name, SocketAddress *a
6060
return get_stack()->gethostbyname(name, address, version);
6161
}
6262

63-
nsapi_error_t NetworkInterface::gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version)
63+
nsapi_value_or_error_t NetworkInterface::gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version)
6464
{
6565
return get_stack()->gethostbyname_async(host, callback, version);
6666
}
6767

68-
nsapi_error_t NetworkInterface::gethostbyname_async_cancel(nsapi_error_t handle)
68+
nsapi_error_t NetworkInterface::gethostbyname_async_cancel(int id)
6969
{
70-
return get_stack()->gethostbyname_async_cancel(handle);
70+
return get_stack()->gethostbyname_async_cancel(id);
7171
}
7272

7373
nsapi_error_t NetworkInterface::add_dns_server(const SocketAddress &address)

features/netsocket/NetworkInterface.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,12 @@ class NetworkInterface: public DNS {
161161
* @param callback Callback that is called for result
162162
* @param version IP version of address to resolve, NSAPI_UNSPEC indicates
163163
* version is chosen by the stack (defaults to NSAPI_UNSPEC)
164-
* @return 0 on success, negative error code on failure or an unique id that
165-
* represents the hostname translation operation and can be passed to
166-
* cancel
164+
* @return 0 on immediate success,
165+
* negative error code on immediate failure or
166+
* a positive unique id that represents the hostname translation operation
167+
* and can be passed to cancel
167168
*/
168-
virtual nsapi_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback,
169+
virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback,
169170
nsapi_version_t version = NSAPI_UNSPEC);
170171

171172
/** Cancels asynchronous hostname translation
@@ -175,7 +176,7 @@ class NetworkInterface: public DNS {
175176
* @param id Unique id of the hostname translation operation
176177
* @return 0 on success, negative error code on failure
177178
*/
178-
virtual nsapi_error_t gethostbyname_async_cancel(nsapi_error_t id);
179+
virtual nsapi_error_t gethostbyname_async_cancel(int id);
179180

180181
/** Add a domain name server to list of servers to query
181182
*

features/netsocket/NetworkStack.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ nsapi_error_t NetworkStack::gethostbyname(const char *name, SocketAddress *addre
4949
return nsapi_dns_query(this, name, address, version);
5050
}
5151

52-
nsapi_error_t NetworkStack::gethostbyname_async(const char *name, hostbyname_cb_t callback, nsapi_version_t version)
52+
nsapi_value_or_error_t NetworkStack::gethostbyname_async(const char *name, hostbyname_cb_t callback, nsapi_version_t version)
5353
{
5454
SocketAddress address;
5555

@@ -77,9 +77,9 @@ nsapi_error_t NetworkStack::gethostbyname_async(const char *name, hostbyname_cb_
7777
return nsapi_dns_query_async(this, name, callback, call_in_cb, version);
7878
}
7979

80-
nsapi_error_t NetworkStack::gethostbyname_async_cancel(nsapi_error_t handle)
80+
nsapi_error_t NetworkStack::gethostbyname_async_cancel(int id)
8181
{
82-
return nsapi_dns_query_async_cancel(handle);
82+
return nsapi_dns_query_async_cancel(id);
8383
}
8484

8585
nsapi_error_t NetworkStack::add_dns_server(const SocketAddress &address)
@@ -115,6 +115,7 @@ nsapi_error_t NetworkStack::getsockopt(void *handle, int level, int optname, voi
115115
nsapi_error_t NetworkStack::call_in(int delay, mbed::Callback<void()> func)
116116
{
117117
events::EventQueue *event_queue = mbed::mbed_event_queue();
118+
118119
if (!event_queue) {
119120
return NSAPI_ERROR_NO_MEMORY;
120121
}
@@ -132,20 +133,12 @@ nsapi_error_t NetworkStack::call_in(int delay, mbed::Callback<void()> func)
132133
return NSAPI_ERROR_OK;
133134
}
134135

135-
typedef mbed::Callback<nsapi_error_t (int delay_ms, mbed::Callback<void()> user_cb)> call_in_callback_cb_t;
136-
137136
call_in_callback_cb_t NetworkStack::get_call_in_callback()
138137
{
139-
events::EventQueue *event_queue = mbed::mbed_event_queue();
140-
if (!event_queue) {
141-
return NULL;
142-
}
143-
144138
call_in_callback_cb_t cb(this, &NetworkStack::call_in);
145139
return cb;
146140
}
147141

148-
149142
// NetworkStackWrapper class for encapsulating the raw nsapi_stack structure
150143
class NetworkStackWrapper : public NetworkStack
151144
{

features/netsocket/NetworkStack.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ class NetworkStack: public DNS
9595
* @param callback Callback that is called for result
9696
* @param version IP version of address to resolve, NSAPI_UNSPEC indicates
9797
* version is chosen by the stack (defaults to NSAPI_UNSPEC)
98-
* @return 0 on success, negative error code on failure or an unique id that
99-
* represents the hostname translation operation and can be passed to
100-
* cancel
98+
* @return 0 on immediate success,
99+
* negative error code on immediate failure or
100+
* a positive unique id that represents the hostname translation operation
101+
* and can be passed to cancel
101102
*/
102-
virtual nsapi_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback,
103+
virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback,
103104
nsapi_version_t version = NSAPI_UNSPEC);
104105

105106
/** Cancels asynchronous hostname translation
@@ -109,7 +110,7 @@ class NetworkStack: public DNS
109110
* @param id Unique id of the hostname translation operation
110111
* @return 0 on success, negative error code on failure
111112
*/
112-
virtual nsapi_error_t gethostbyname_async_cancel(nsapi_error_t id);
113+
virtual nsapi_error_t gethostbyname_async_cancel(int id);
113114

114115
/** Add a domain name server to list of servers to query
115116
*

features/netsocket/mbed_lib.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
"present": 1,
55
"default-stack": "LWIP",
66
"dns-response-wait-time": {
7-
"help": "How long the DNS translator waits for a reply from a server",
7+
"help": "How long the DNS translator waits for a reply from a server in milliseconds",
88
"value": 5000
99
},
10-
"dns-total-retries": {
11-
"help": "Number of total DNS query retries that the DNS translator makes",
10+
"dns-total-attempts": {
11+
"help": "Number of total DNS query attempts that the DNS translator makes",
1212
"value": 3
1313
},
1414
"dns-retries": {
15-
"help": "Number of DNS query retries that the DNS translator makes per server",
15+
"help": "Number of DNS query retries that the DNS translator makes per server, before moving on to the next server. Total retries/attempts is always limited by dns-total-attempts.",
1616
"value": 0
1717
},
1818
"dns-cache-size": {

0 commit comments

Comments
 (0)