net: dns: Refactor because of timeout overhaul

Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2020-04-02 20:32:38 +03:00
commit a49741ff66
6 changed files with 20 additions and 17 deletions

View file

@ -178,7 +178,7 @@ struct dns_resolve_context {
/** This timeout is also used when a buffer is required from the
* buffer pools.
*/
s32_t buf_timeout;
k_timeout_t buf_timeout;
/** Result callbacks. We have multiple callbacks here so that it is
* possible to do multiple queries at the same time.
@ -197,7 +197,7 @@ struct dns_resolve_context {
void *user_data;
/** TX timeout */
s32_t timeout;
k_timeout_t timeout;
/** String containing the thing to resolve like www.example.com
*/

View file

@ -28,7 +28,7 @@ static void do_mdns_ipv6_lookup(struct k_work *work);
#endif
#endif
#define DNS_TIMEOUT K_SECONDS(2)
#define DNS_TIMEOUT (2 * MSEC_PER_SEC)
void dns_result_cb(enum dns_resolve_status status,
struct dns_addrinfo *info,

View file

@ -1645,7 +1645,7 @@ static int cmd_net_dns_query(const struct shell *shell, size_t argc,
{
#if defined(CONFIG_DNS_RESOLVER)
#define DNS_TIMEOUT K_MSEC(2000) /* ms */
#define DNS_TIMEOUT (MSEC_PER_SEC * 2) /* ms */
enum dns_query_type qtype = DNS_QUERY_TYPE_A;
char *host, *type = NULL;
int ret, arg = 1;

View file

@ -34,7 +34,7 @@ LOG_MODULE_REGISTER(net_dns_resolve, CONFIG_DNS_RESOLVER_LOG_LEVEL);
#define LLMNR_IPV4_ADDR "224.0.0.252:5355"
#define LLMNR_IPV6_ADDR "[ff02::1:3]:5355"
#define DNS_BUF_TIMEOUT 500 /* ms */
#define DNS_BUF_TIMEOUT K_MSEC(500) /* ms */
/* RFC 1035, 3.1. Name space definitions
* To simplify implementations, the total length of a domain name (i.e.,
@ -764,17 +764,13 @@ static int dns_write(struct dns_resolve_context *ctx,
ctx->queries[query_idx].timeout);
if (ret < 0) {
NET_DBG("[%u] cannot submit work to server idx %d for id %u "
"timeout %u ret %d",
query_idx, server_idx, dns_id,
ctx->queries[query_idx].timeout, ret);
"ret %d", query_idx, server_idx, dns_id, ret);
return ret;
}
NET_DBG("[%u] submitting work to server idx %d for id %u "
"hash %u timeout %u",
query_idx, server_idx, dns_id,
ctx->queries[query_idx].query_hash,
ctx->queries[query_idx].timeout);
"hash %u", query_idx, server_idx, dns_id,
ctx->queries[query_idx].query_hash);
ret = net_context_sendto(net_ctx, dns_data->data, dns_data->len,
server, server_addr_len, NULL,
@ -888,6 +884,7 @@ int dns_resolve_name(struct dns_resolve_context *ctx,
void *user_data,
s32_t timeout)
{
k_timeout_t tout;
struct net_buf *dns_data = NULL;
struct net_buf *dns_qname = NULL;
struct sockaddr addr;
@ -900,9 +897,15 @@ int dns_resolve_name(struct dns_resolve_context *ctx,
return -EINVAL;
}
if (timeout == NET_WAIT_FOREVER) {
tout = K_FOREVER;
} else {
tout = K_MSEC(timeout);
}
/* Timeout cannot be 0 as we cannot resolve name that fast.
*/
if (timeout == K_NO_WAIT) {
if (K_TIMEOUT_EQ(tout, K_NO_WAIT)) {
return -EINVAL;
}
@ -963,7 +966,7 @@ try_resolve:
}
ctx->queries[i].cb = cb;
ctx->queries[i].timeout = timeout;
ctx->queries[i].timeout = tout;
ctx->queries[i].query = query;
ctx->queries[i].query_type = type;
ctx->queries[i].user_data = user_data;

View file

@ -71,7 +71,7 @@ static struct dns_resolve_context resv_ipv6_2;
#endif
/* this must be higher that the DNS_TIMEOUT */
#define WAIT_TIME ((DNS_TIMEOUT + 300) * 3)
#define WAIT_TIME K_MSEC((DNS_TIMEOUT + 300) * 3)
struct net_if_test {
u8_t idx;

View file

@ -68,7 +68,7 @@ static u16_t current_dns_id;
static struct dns_addrinfo addrinfo;
/* this must be higher that the DNS_TIMEOUT */
#define WAIT_TIME (DNS_TIMEOUT + 300)
#define WAIT_TIME K_MSEC(DNS_TIMEOUT + 300)
struct net_if_test {
u8_t idx;
@ -279,7 +279,7 @@ static void dns_query_invalid_timeout(void)
NULL,
dns_result_cb_dummy,
NULL,
K_NO_WAIT);
0);
zassert_equal(ret, -EINVAL, "Wrong return code for timeout");
}