net: context: Refactor because of timeout overhaul
The net_context API will change, the s32_t timeout parameter will be changed to k_timeout_t. All the Zephyr users of this API will be changed in subsequent commits. This is internal Zephyr API only, so the API is not deprecated etc. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
ab5aba4f8f
commit
e56fa75ade
5 changed files with 81 additions and 48 deletions
|
@ -866,7 +866,7 @@ int net_context_connect(struct net_context *context,
|
|||
const struct sockaddr *addr,
|
||||
socklen_t addrlen,
|
||||
net_context_connect_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
|
@ -896,7 +896,7 @@ int net_context_connect(struct net_context *context,
|
|||
*/
|
||||
int net_context_accept(struct net_context *context,
|
||||
net_tcp_accept_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
|
@ -922,7 +922,7 @@ int net_context_send(struct net_context *context,
|
|||
const void *buf,
|
||||
size_t len,
|
||||
net_context_send_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
|
@ -952,7 +952,7 @@ int net_context_sendto(struct net_context *context,
|
|||
const struct sockaddr *dst_addr,
|
||||
socklen_t addrlen,
|
||||
net_context_send_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
|
@ -977,7 +977,7 @@ int net_context_sendmsg(struct net_context *context,
|
|||
const struct msghdr *msghdr,
|
||||
int flags,
|
||||
net_context_send_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
|
@ -1018,7 +1018,7 @@ int net_context_sendmsg(struct net_context *context,
|
|||
*/
|
||||
int net_context_recv(struct net_context *context,
|
||||
net_context_recv_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
|
|
|
@ -219,15 +219,21 @@ static inline int net_offload_connect(struct net_if *iface,
|
|||
const struct sockaddr *addr,
|
||||
socklen_t addrlen,
|
||||
net_context_connect_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
NET_ASSERT(iface);
|
||||
NET_ASSERT(net_if_offload(iface));
|
||||
NET_ASSERT(net_if_offload(iface)->connect);
|
||||
|
||||
return net_if_offload(iface)->connect(context, addr, addrlen, cb,
|
||||
timeout, user_data);
|
||||
return net_if_offload(iface)->connect(
|
||||
context, addr, addrlen, cb,
|
||||
#ifdef CONFIG_LEGACY_TIMEOUT_API
|
||||
Z_TIMEOUT_MS(timeout),
|
||||
#else
|
||||
k_ticks_to_ms_floor64(timeout.ticks),
|
||||
#endif
|
||||
user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -260,14 +266,21 @@ static inline int net_offload_connect(struct net_if *iface,
|
|||
static inline int net_offload_accept(struct net_if *iface,
|
||||
struct net_context *context,
|
||||
net_tcp_accept_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
NET_ASSERT(iface);
|
||||
NET_ASSERT(net_if_offload(iface));
|
||||
NET_ASSERT(net_if_offload(iface)->accept);
|
||||
|
||||
return net_if_offload(iface)->accept(context, cb, timeout, user_data);
|
||||
return net_if_offload(iface)->accept(
|
||||
context, cb,
|
||||
#ifdef CONFIG_LEGACY_TIMEOUT_API
|
||||
Z_TIMEOUT_MS(timeout),
|
||||
#else
|
||||
k_ticks_to_ms_floor64(timeout.ticks),
|
||||
#endif
|
||||
user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -299,14 +312,21 @@ static inline int net_offload_accept(struct net_if *iface,
|
|||
static inline int net_offload_send(struct net_if *iface,
|
||||
struct net_pkt *pkt,
|
||||
net_context_send_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
NET_ASSERT(iface);
|
||||
NET_ASSERT(net_if_offload(iface));
|
||||
NET_ASSERT(net_if_offload(iface)->send);
|
||||
|
||||
return net_if_offload(iface)->send(pkt, cb, timeout, user_data);
|
||||
return net_if_offload(iface)->send(
|
||||
pkt, cb,
|
||||
#ifdef CONFIG_LEGACY_TIMEOUT_API
|
||||
Z_TIMEOUT_MS(timeout),
|
||||
#else
|
||||
k_ticks_to_ms_floor64(timeout.ticks),
|
||||
#endif
|
||||
user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -342,15 +362,21 @@ static inline int net_offload_sendto(struct net_if *iface,
|
|||
const struct sockaddr *dst_addr,
|
||||
socklen_t addrlen,
|
||||
net_context_send_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
NET_ASSERT(iface);
|
||||
NET_ASSERT(net_if_offload(iface));
|
||||
NET_ASSERT(net_if_offload(iface)->sendto);
|
||||
|
||||
return net_if_offload(iface)->sendto(pkt, dst_addr, addrlen, cb,
|
||||
timeout, user_data);
|
||||
return net_if_offload(iface)->sendto(
|
||||
pkt, dst_addr, addrlen, cb,
|
||||
#ifdef CONFIG_LEGACY_TIMEOUT_API
|
||||
Z_TIMEOUT_MS(timeout),
|
||||
#else
|
||||
k_ticks_to_ms_floor64(timeout.ticks),
|
||||
#endif
|
||||
user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -389,14 +415,21 @@ static inline int net_offload_sendto(struct net_if *iface,
|
|||
static inline int net_offload_recv(struct net_if *iface,
|
||||
struct net_context *context,
|
||||
net_context_recv_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
NET_ASSERT(iface);
|
||||
NET_ASSERT(net_if_offload(iface));
|
||||
NET_ASSERT(net_if_offload(iface)->recv);
|
||||
|
||||
return net_if_offload(iface)->recv(context, cb, timeout, user_data);
|
||||
return net_if_offload(iface)->recv(
|
||||
context, cb,
|
||||
#ifdef CONFIG_LEGACY_TIMEOUT_API
|
||||
Z_TIMEOUT_MS(timeout),
|
||||
#else
|
||||
k_ticks_to_ms_floor64(timeout.ticks),
|
||||
#endif
|
||||
user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -455,7 +488,7 @@ static inline int net_offload_connect(struct net_if *iface,
|
|||
const struct sockaddr *addr,
|
||||
socklen_t addrlen,
|
||||
net_context_connect_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
return 0;
|
||||
|
@ -464,7 +497,7 @@ static inline int net_offload_connect(struct net_if *iface,
|
|||
static inline int net_offload_accept(struct net_if *iface,
|
||||
struct net_context *context,
|
||||
net_tcp_accept_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
return 0;
|
||||
|
@ -473,7 +506,7 @@ static inline int net_offload_accept(struct net_if *iface,
|
|||
static inline int net_offload_send(struct net_if *iface,
|
||||
struct net_pkt *pkt,
|
||||
net_context_send_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
return 0;
|
||||
|
@ -484,7 +517,7 @@ static inline int net_offload_sendto(struct net_if *iface,
|
|||
const struct sockaddr *dst_addr,
|
||||
socklen_t addrlen,
|
||||
net_context_send_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
return 0;
|
||||
|
@ -493,7 +526,7 @@ static inline int net_offload_sendto(struct net_if *iface,
|
|||
static inline int net_offload_recv(struct net_if *iface,
|
||||
struct net_context *context,
|
||||
net_context_recv_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
return 0;
|
||||
|
|
|
@ -878,7 +878,7 @@ int net_context_connect(struct net_context *context,
|
|||
const struct sockaddr *addr,
|
||||
socklen_t addrlen,
|
||||
net_context_connect_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
struct sockaddr *laddr = NULL;
|
||||
|
@ -1053,7 +1053,7 @@ unlock:
|
|||
|
||||
int net_context_accept(struct net_context *context,
|
||||
net_tcp_accept_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
int ret = 0;
|
||||
|
@ -1285,7 +1285,7 @@ static void context_finalize_packet(struct net_context *context,
|
|||
}
|
||||
|
||||
static struct net_pkt *context_alloc_pkt(struct net_context *context,
|
||||
size_t len, s32_t timeout)
|
||||
size_t len, k_timeout_t timeout)
|
||||
{
|
||||
struct net_pkt *pkt;
|
||||
|
||||
|
@ -1344,7 +1344,7 @@ static int context_sendto(struct net_context *context,
|
|||
const struct sockaddr *dst_addr,
|
||||
socklen_t addrlen,
|
||||
net_context_send_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data,
|
||||
bool sendto)
|
||||
{
|
||||
|
@ -1630,7 +1630,7 @@ int net_context_send(struct net_context *context,
|
|||
const void *buf,
|
||||
size_t len,
|
||||
net_context_send_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
socklen_t addrlen;
|
||||
|
@ -1673,7 +1673,7 @@ int net_context_sendmsg(struct net_context *context,
|
|||
const struct msghdr *msghdr,
|
||||
int flags,
|
||||
net_context_send_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
int ret;
|
||||
|
@ -1694,7 +1694,7 @@ int net_context_sendto(struct net_context *context,
|
|||
const struct sockaddr *dst_addr,
|
||||
socklen_t addrlen,
|
||||
net_context_send_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
int ret;
|
||||
|
@ -1755,7 +1755,7 @@ unlock:
|
|||
#if defined(CONFIG_NET_UDP)
|
||||
static int recv_udp(struct net_context *context,
|
||||
net_context_recv_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
struct sockaddr local_addr = {
|
||||
|
@ -1854,7 +1854,7 @@ static enum net_verdict net_context_raw_packet_received(
|
|||
|
||||
static int recv_raw(struct net_context *context,
|
||||
net_context_recv_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
struct sockaddr *local_addr,
|
||||
void *user_data)
|
||||
{
|
||||
|
@ -1886,7 +1886,7 @@ static int recv_raw(struct net_context *context,
|
|||
|
||||
int net_context_recv(struct net_context *context,
|
||||
net_context_recv_cb_t cb,
|
||||
s32_t timeout,
|
||||
k_timeout_t timeout,
|
||||
void *user_data)
|
||||
{
|
||||
int ret;
|
||||
|
@ -1954,7 +1954,7 @@ int net_context_recv(struct net_context *context,
|
|||
}
|
||||
|
||||
#if defined(CONFIG_NET_CONTEXT_SYNC_RECV)
|
||||
if (timeout) {
|
||||
if (!K_TIMEOUT_EQ(timeout, K_NO_WAIT)) {
|
||||
int ret;
|
||||
|
||||
/* Make sure we have the lock, then the
|
||||
|
|
|
@ -740,8 +740,8 @@ static void rx_chksum_offload_disabled_test_v6(void)
|
|||
test_started = true;
|
||||
start_receiving = true;
|
||||
|
||||
ret = net_context_recv(udp_v6_ctx_1, recv_cb_offload_disabled, 0,
|
||||
NULL);
|
||||
ret = net_context_recv(udp_v6_ctx_1, recv_cb_offload_disabled,
|
||||
K_NO_WAIT, NULL);
|
||||
zassert_equal(ret, 0, "Recv UDP failed (%d)\n", ret);
|
||||
|
||||
start_receiving = false;
|
||||
|
@ -796,8 +796,8 @@ static void rx_chksum_offload_disabled_test_v4(void)
|
|||
test_started = true;
|
||||
start_receiving = true;
|
||||
|
||||
ret = net_context_recv(udp_v4_ctx_1, recv_cb_offload_disabled, 0,
|
||||
NULL);
|
||||
ret = net_context_recv(udp_v4_ctx_1, recv_cb_offload_disabled,
|
||||
K_NO_WAIT, NULL);
|
||||
zassert_equal(ret, 0, "Recv UDP failed (%d)\n", ret);
|
||||
|
||||
start_receiving = false;
|
||||
|
@ -852,8 +852,8 @@ static void rx_chksum_offload_enabled_test_v6(void)
|
|||
test_started = true;
|
||||
start_receiving = true;
|
||||
|
||||
ret = net_context_recv(udp_v6_ctx_2, recv_cb_offload_enabled, 0,
|
||||
NULL);
|
||||
ret = net_context_recv(udp_v6_ctx_2, recv_cb_offload_enabled,
|
||||
K_NO_WAIT, NULL);
|
||||
zassert_equal(ret, 0, "Recv UDP failed (%d)\n", ret);
|
||||
|
||||
ret = net_context_sendto(udp_v6_ctx_2, test_data, len,
|
||||
|
@ -906,8 +906,8 @@ static void rx_chksum_offload_enabled_test_v4(void)
|
|||
test_started = true;
|
||||
start_receiving = true;
|
||||
|
||||
ret = net_context_recv(udp_v4_ctx_2, recv_cb_offload_enabled, 0,
|
||||
NULL);
|
||||
ret = net_context_recv(udp_v4_ctx_2, recv_cb_offload_enabled,
|
||||
K_NO_WAIT, NULL);
|
||||
zassert_equal(ret, 0, "Recv UDP failed (%d)\n", ret);
|
||||
|
||||
ret = net_context_sendto(udp_v4_ctx_2, test_data, len,
|
||||
|
|
|
@ -65,7 +65,7 @@ static bool test_sending;
|
|||
|
||||
static struct k_sem wait_data;
|
||||
|
||||
#define WAIT_TIME 250
|
||||
#define WAIT_TIME K_MSEC(250)
|
||||
#define WAIT_TIME_LONG MSEC_PER_SEC
|
||||
#define SENDING 93244
|
||||
#define MY_PORT 1969
|
||||
|
@ -678,7 +678,7 @@ void timeout_thread(struct net_context *ctx, void *param2, void *param3)
|
|||
s32_t timeout = POINTER_TO_INT(param3);
|
||||
int ret;
|
||||
|
||||
ret = net_context_recv(ctx, recv_cb_timeout, timeout,
|
||||
ret = net_context_recv(ctx, recv_cb_timeout, K_MSEC(timeout),
|
||||
INT_TO_POINTER(family));
|
||||
if (ret != -ETIMEDOUT && expecting_cb_failure) {
|
||||
zassert_true(expecting_cb_failure,
|
||||
|
@ -781,10 +781,10 @@ static void net_ctx_recv_v6_timeout_forever(void)
|
|||
recv_cb_timeout_called = false;
|
||||
|
||||
/* Start a thread that will send data to receiver. */
|
||||
tid = start_timeout_v6_thread(K_FOREVER);
|
||||
tid = start_timeout_v6_thread(NET_WAIT_FOREVER);
|
||||
|
||||
/* Wait a bit so that we see if recv waited or not */
|
||||
k_sleep(K_MSEC(WAIT_TIME));
|
||||
k_sleep(WAIT_TIME);
|
||||
|
||||
net_ctx_send_v6();
|
||||
|
||||
|
@ -807,10 +807,10 @@ static void net_ctx_recv_v4_timeout_forever(void)
|
|||
recv_cb_timeout_called = false;
|
||||
|
||||
/* Start a thread that will send data to receiver. */
|
||||
tid = start_timeout_v4_thread(K_FOREVER);
|
||||
tid = start_timeout_v4_thread(NET_WAIT_FOREVER);
|
||||
|
||||
/* Wait a bit so that we see if recv waited or not */
|
||||
k_sleep(K_MSEC(WAIT_TIME));
|
||||
k_sleep(WAIT_TIME);
|
||||
|
||||
net_ctx_send_v4();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue