net: Replace NET_WAIT_FOREVER by SYS_FOREVER_MS
As we now have SYS_FOREVER_MS, use that instead of network specific NET_WAIT_FOREVER. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
b78c9dca52
commit
65a1bebe85
12 changed files with 22 additions and 37 deletions
|
@ -28,12 +28,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
|
||||||
* Symbol to indicate that the caller wants the timeout to be waited forever.
|
|
||||||
* This can be used when a network API expects a millisecond timeout.
|
|
||||||
*/
|
|
||||||
#define NET_WAIT_FOREVER (-1)
|
|
||||||
|
|
||||||
/** Let the max timeout be 100 ms lower because of
|
/** Let the max timeout be 100 ms lower because of
|
||||||
* possible rounding in delayed work implementation.
|
* possible rounding in delayed work implementation.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -118,7 +118,7 @@ struct websocket_request {
|
||||||
* @param req Websocket request. User should allocate and fill the request
|
* @param req Websocket request. User should allocate and fill the request
|
||||||
* data.
|
* data.
|
||||||
* @param timeout Max timeout to wait for the connection. The timeout value is
|
* @param timeout Max timeout to wait for the connection. The timeout value is
|
||||||
* in milliseconds. Value NET_WAIT_FOREVER means to wait forever.
|
* in milliseconds. Value SYS_FOREVER_MS means to wait forever.
|
||||||
* @param user_data User specified data that is passed to the callback.
|
* @param user_data User specified data that is passed to the callback.
|
||||||
*
|
*
|
||||||
* @return Websocket id to be used when sending/receiving Websocket data.
|
* @return Websocket id to be used when sending/receiving Websocket data.
|
||||||
|
@ -143,7 +143,7 @@ int websocket_connect(int http_sock, struct websocket_request *req,
|
||||||
* is the only message, then opcode should have proper opcode (text or
|
* is the only message, then opcode should have proper opcode (text or
|
||||||
* binary) set.
|
* binary) set.
|
||||||
* @param timeout How long to try to send the message. The value is in
|
* @param timeout How long to try to send the message. The value is in
|
||||||
* milliseconds. Value NET_WAIT_FOREVER means to wait forever.
|
* milliseconds. Value SYS_FOREVER_MS means to wait forever.
|
||||||
*
|
*
|
||||||
* @return <0 if error, >=0 amount of bytes sent
|
* @return <0 if error, >=0 amount of bytes sent
|
||||||
*/
|
*/
|
||||||
|
@ -163,7 +163,7 @@ int websocket_send_msg(int ws_sock, const u8_t *payload, size_t payload_len,
|
||||||
* @param message_type Type of the message.
|
* @param message_type Type of the message.
|
||||||
* @param remaining How much there is data left in the message after this read.
|
* @param remaining How much there is data left in the message after this read.
|
||||||
* @param timeout How long to try to receive the message.
|
* @param timeout How long to try to receive the message.
|
||||||
* The value is in milliseconds. Value NET_WAIT_FOREVER means to wait
|
* The value is in milliseconds. Value SYS_FOREVER_MS means to wait
|
||||||
* forever.
|
* forever.
|
||||||
*
|
*
|
||||||
* @return <0 if error, >=0 amount of bytes received
|
* @return <0 if error, >=0 amount of bytes received
|
||||||
|
|
|
@ -309,7 +309,7 @@ static void poll_mqtt(void)
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
while (mqtt_connected) {
|
while (mqtt_connected) {
|
||||||
rc = wait(NET_WAIT_FOREVER);
|
rc = wait(SYS_FOREVER_MS);
|
||||||
if (rc > 0) {
|
if (rc > 0) {
|
||||||
mqtt_input(&client_ctx);
|
mqtt_input(&client_ctx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,7 +175,7 @@ static size_t how_much_to_send(size_t max_len)
|
||||||
static ssize_t sendall_with_ws_api(int sock, const void *buf, size_t len)
|
static ssize_t sendall_with_ws_api(int sock, const void *buf, size_t len)
|
||||||
{
|
{
|
||||||
return websocket_send_msg(sock, buf, len, WEBSOCKET_OPCODE_DATA_TEXT,
|
return websocket_send_msg(sock, buf, len, WEBSOCKET_OPCODE_DATA_TEXT,
|
||||||
true, true, NET_WAIT_FOREVER);
|
true, true, SYS_FOREVER_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t sendall_with_bsd_api(int sock, const void *buf, size_t len)
|
static ssize_t sendall_with_bsd_api(int sock, const void *buf, size_t len)
|
||||||
|
|
|
@ -897,11 +897,7 @@ int dns_resolve_name(struct dns_resolve_context *ctx,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeout == NET_WAIT_FOREVER) {
|
tout = SYS_TIMEOUT_MS(timeout);
|
||||||
tout = K_FOREVER;
|
|
||||||
} else {
|
|
||||||
tout = K_MSEC(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Timeout cannot be 0 as we cannot resolve name that fast.
|
/* Timeout cannot be 0 as we cannot resolve name that fast.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -491,12 +491,7 @@ int http_client_req(int sock, struct http_request *req,
|
||||||
req->internal.response.recv_buf_len = req->recv_buf_len;
|
req->internal.response.recv_buf_len = req->recv_buf_len;
|
||||||
req->internal.user_data = user_data;
|
req->internal.user_data = user_data;
|
||||||
req->internal.sock = sock;
|
req->internal.sock = sock;
|
||||||
|
req->internal.timeout = SYS_TIMEOUT_MS(timeout);
|
||||||
if (timeout == NET_WAIT_FOREVER) {
|
|
||||||
req->internal.timeout = K_FOREVER;
|
|
||||||
} else {
|
|
||||||
req->internal.timeout = K_MSEC(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
method = http_method_str(req->method);
|
method = http_method_str(req->method);
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ int mqtt_client_websocket_write(struct mqtt_client *client, const u8_t *data,
|
||||||
ret = websocket_send_msg(client->transport.websocket.sock,
|
ret = websocket_send_msg(client->transport.websocket.sock,
|
||||||
data + offset, datalen - offset,
|
data + offset, datalen - offset,
|
||||||
WEBSOCKET_OPCODE_DATA_BINARY,
|
WEBSOCKET_OPCODE_DATA_BINARY,
|
||||||
true, true, NET_WAIT_FOREVER);
|
true, true, SYS_FOREVER_MS);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ int mqtt_client_websocket_write_msg(struct mqtt_client *client,
|
||||||
ret = websocket_send_msg(client->transport.websocket.sock,
|
ret = websocket_send_msg(client->transport.websocket.sock,
|
||||||
message->msg_iov[i].iov_base,
|
message->msg_iov[i].iov_base,
|
||||||
message->msg_iov[i].iov_len, opcode,
|
message->msg_iov[i].iov_len, opcode,
|
||||||
true, final, NET_WAIT_FOREVER);
|
true, final, SYS_FOREVER_MS);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ int mqtt_client_websocket_write_msg(struct mqtt_client *client,
|
||||||
int mqtt_client_websocket_read(struct mqtt_client *client, u8_t *data,
|
int mqtt_client_websocket_read(struct mqtt_client *client, u8_t *data,
|
||||||
u32_t buflen, bool shall_block)
|
u32_t buflen, bool shall_block)
|
||||||
{
|
{
|
||||||
s32_t timeout = NET_WAIT_FOREVER;
|
s32_t timeout = SYS_FOREVER_MS;
|
||||||
u32_t message_type = 0U;
|
u32_t message_type = 0U;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ int sntp_simple(const char *server, u32_t timeout, struct sntp_time *time)
|
||||||
goto freeaddr;
|
goto freeaddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeout == NET_WAIT_FOREVER) {
|
if (timeout == SYS_FOREVER_MS) {
|
||||||
deadline = (u64_t)timeout;
|
deadline = (u64_t)timeout;
|
||||||
} else {
|
} else {
|
||||||
deadline = k_uptime_get() + (u64_t)timeout;
|
deadline = k_uptime_get() + (u64_t)timeout;
|
||||||
|
|
|
@ -1066,7 +1066,7 @@ int z_impl_zsock_poll(struct zsock_pollfd *fds, int nfds, int poll_timeout)
|
||||||
|
|
||||||
if (poll_timeout < 0) {
|
if (poll_timeout < 0) {
|
||||||
timeout = K_FOREVER;
|
timeout = K_FOREVER;
|
||||||
poll_timeout = NET_WAIT_FOREVER;
|
poll_timeout = SYS_FOREVER_MS;
|
||||||
} else {
|
} else {
|
||||||
timeout = K_MSEC(poll_timeout);
|
timeout = K_MSEC(poll_timeout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -476,7 +476,7 @@ static int websocket_prepare_and_send(struct websocket_context *ctx,
|
||||||
#else
|
#else
|
||||||
k_timeout_t tout = K_FOREVER;
|
k_timeout_t tout = K_FOREVER;
|
||||||
|
|
||||||
if (timeout != NET_WAIT_FOREVER) {
|
if (timeout != SYS_FOREVER_MS) {
|
||||||
tout = K_MSEC(timeout);
|
tout = K_MSEC(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -666,7 +666,7 @@ int websocket_recv_msg(int ws_sock, u8_t *buf, size_t buf_len,
|
||||||
int ret;
|
int ret;
|
||||||
k_timeout_t tout = K_FOREVER;
|
k_timeout_t tout = K_FOREVER;
|
||||||
|
|
||||||
if (timeout != NET_WAIT_FOREVER) {
|
if (timeout != SYS_FOREVER_MS) {
|
||||||
tout = K_MSEC(timeout);
|
tout = K_MSEC(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -913,13 +913,13 @@ static int websocket_recv(struct websocket_context *ctx, u8_t *buf,
|
||||||
|
|
||||||
static ssize_t websocket_read_vmeth(void *obj, void *buffer, size_t count)
|
static ssize_t websocket_read_vmeth(void *obj, void *buffer, size_t count)
|
||||||
{
|
{
|
||||||
return (ssize_t)websocket_recv(obj, buffer, count, NET_WAIT_FOREVER);
|
return (ssize_t)websocket_recv(obj, buffer, count, SYS_FOREVER_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t websocket_write_vmeth(void *obj, const void *buffer,
|
static ssize_t websocket_write_vmeth(void *obj, const void *buffer,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
return (ssize_t)websocket_send(obj, buffer, count, NET_WAIT_FOREVER);
|
return (ssize_t)websocket_send(obj, buffer, count, SYS_FOREVER_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t websocket_sendto_ctx(void *obj, const void *buf, size_t len,
|
static ssize_t websocket_sendto_ctx(void *obj, const void *buf, size_t len,
|
||||||
|
@ -928,7 +928,7 @@ static ssize_t websocket_sendto_ctx(void *obj, const void *buf, size_t len,
|
||||||
socklen_t addrlen)
|
socklen_t addrlen)
|
||||||
{
|
{
|
||||||
struct websocket_context *ctx = obj;
|
struct websocket_context *ctx = obj;
|
||||||
s32_t timeout = NET_WAIT_FOREVER;
|
s32_t timeout = SYS_FOREVER_MS;
|
||||||
|
|
||||||
if (flags & ZSOCK_MSG_DONTWAIT) {
|
if (flags & ZSOCK_MSG_DONTWAIT) {
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
|
@ -945,7 +945,7 @@ static ssize_t websocket_recvfrom_ctx(void *obj, void *buf, size_t max_len,
|
||||||
socklen_t *addrlen)
|
socklen_t *addrlen)
|
||||||
{
|
{
|
||||||
struct websocket_context *ctx = obj;
|
struct websocket_context *ctx = obj;
|
||||||
s32_t timeout = NET_WAIT_FOREVER;
|
s32_t timeout = SYS_FOREVER_MS;
|
||||||
|
|
||||||
if (flags & ZSOCK_MSG_DONTWAIT) {
|
if (flags & ZSOCK_MSG_DONTWAIT) {
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
|
|
|
@ -781,7 +781,7 @@ static void net_ctx_recv_v6_timeout_forever(void)
|
||||||
recv_cb_timeout_called = false;
|
recv_cb_timeout_called = false;
|
||||||
|
|
||||||
/* Start a thread that will send data to receiver. */
|
/* Start a thread that will send data to receiver. */
|
||||||
tid = start_timeout_v6_thread(NET_WAIT_FOREVER);
|
tid = start_timeout_v6_thread(SYS_FOREVER_MS);
|
||||||
|
|
||||||
/* Wait a bit so that we see if recv waited or not */
|
/* Wait a bit so that we see if recv waited or not */
|
||||||
k_sleep(WAIT_TIME);
|
k_sleep(WAIT_TIME);
|
||||||
|
@ -807,7 +807,7 @@ static void net_ctx_recv_v4_timeout_forever(void)
|
||||||
recv_cb_timeout_called = false;
|
recv_cb_timeout_called = false;
|
||||||
|
|
||||||
/* Start a thread that will send data to receiver. */
|
/* Start a thread that will send data to receiver. */
|
||||||
tid = start_timeout_v4_thread(NET_WAIT_FOREVER);
|
tid = start_timeout_v4_thread(SYS_FOREVER_MS);
|
||||||
|
|
||||||
/* Wait a bit so that we see if recv waited or not */
|
/* Wait a bit so that we see if recv waited or not */
|
||||||
k_sleep(WAIT_TIME);
|
k_sleep(WAIT_TIME);
|
||||||
|
|
|
@ -347,7 +347,7 @@ static void test_send_and_recv_lorem_ipsum(void)
|
||||||
ret = websocket_send_msg(POINTER_TO_INT(&ctx),
|
ret = websocket_send_msg(POINTER_TO_INT(&ctx),
|
||||||
lorem_ipsum, test_msg_len,
|
lorem_ipsum, test_msg_len,
|
||||||
WEBSOCKET_OPCODE_DATA_TEXT, true, true,
|
WEBSOCKET_OPCODE_DATA_TEXT, true, true,
|
||||||
NET_WAIT_FOREVER);
|
SYS_FOREVER_MS);
|
||||||
zassert_equal(ret, test_msg_len,
|
zassert_equal(ret, test_msg_len,
|
||||||
"Should have sent %zd bytes but sent %d instead",
|
"Should have sent %zd bytes but sent %d instead",
|
||||||
test_msg_len, ret);
|
test_msg_len, ret);
|
||||||
|
@ -367,7 +367,7 @@ static void test_recv_two_large_split_msg(void)
|
||||||
|
|
||||||
ret = websocket_send_msg(POINTER_TO_INT(&ctx), lorem_ipsum,
|
ret = websocket_send_msg(POINTER_TO_INT(&ctx), lorem_ipsum,
|
||||||
test_msg_len, WEBSOCKET_OPCODE_DATA_TEXT,
|
test_msg_len, WEBSOCKET_OPCODE_DATA_TEXT,
|
||||||
false, true, NET_WAIT_FOREVER);
|
false, true, SYS_FOREVER_MS);
|
||||||
zassert_equal(ret, test_msg_len,
|
zassert_equal(ret, test_msg_len,
|
||||||
"1st should have sent %zd bytes but sent %d instead",
|
"1st should have sent %zd bytes but sent %d instead",
|
||||||
test_msg_len, ret);
|
test_msg_len, ret);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue