net: http: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API. Clarify the documentation of the timeout parameter that it is in milliseconds. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
8a9153678a
commit
1b04d44247
3 changed files with 15 additions and 6 deletions
|
@ -174,7 +174,7 @@ struct http_client_internal_data {
|
|||
int sock;
|
||||
|
||||
/** Request timeout */
|
||||
s32_t timeout;
|
||||
k_timeout_t timeout;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -271,6 +271,7 @@ struct http_request {
|
|||
* @param req HTTP request information
|
||||
* @param timeout Max timeout to wait for the data. The timeout value cannot be
|
||||
* 0 as there would be no time to receive the data.
|
||||
* The timeout value is in milliseconds.
|
||||
* @param user_data User specified data that is passed to the callback.
|
||||
*
|
||||
* @return <0 if error, >=0 amount of data sent to the server
|
||||
|
|
|
@ -152,7 +152,7 @@ void main(void)
|
|||
struct sockaddr_in6 addr6;
|
||||
struct sockaddr_in addr4;
|
||||
int sock4 = -1, sock6 = -1;
|
||||
s32_t timeout = K_SECONDS(3);
|
||||
s32_t timeout = 3 * MSEC_PER_SEC;
|
||||
int ret;
|
||||
int port = HTTP_PORT;
|
||||
|
||||
|
|
|
@ -490,9 +490,14 @@ int http_client_req(int sock, struct http_request *req,
|
|||
req->internal.response.recv_buf = req->recv_buf;
|
||||
req->internal.response.recv_buf_len = req->recv_buf_len;
|
||||
req->internal.user_data = user_data;
|
||||
req->internal.timeout = timeout;
|
||||
req->internal.sock = sock;
|
||||
|
||||
if (timeout == NET_WAIT_FOREVER) {
|
||||
req->internal.timeout = K_FOREVER;
|
||||
} else {
|
||||
req->internal.timeout = K_MSEC(timeout);
|
||||
}
|
||||
|
||||
method = http_method_str(req->method);
|
||||
|
||||
ret = http_send_data(sock, send_buf, send_buf_max_len, &send_buf_pos,
|
||||
|
@ -635,9 +640,11 @@ int http_client_req(int sock, struct http_request *req,
|
|||
http_client_init_parser(&req->internal.parser,
|
||||
&req->internal.parser_settings);
|
||||
|
||||
if (timeout != K_FOREVER && timeout != K_NO_WAIT) {
|
||||
if (!K_TIMEOUT_EQ(req->internal.timeout, K_FOREVER) &&
|
||||
!K_TIMEOUT_EQ(req->internal.timeout, K_NO_WAIT)) {
|
||||
k_delayed_work_init(&req->internal.work, http_timeout);
|
||||
(void)k_delayed_work_submit(&req->internal.work, timeout);
|
||||
(void)k_delayed_work_submit(&req->internal.work,
|
||||
req->internal.timeout);
|
||||
}
|
||||
|
||||
/* Request is sent, now wait data to be received */
|
||||
|
@ -648,7 +655,8 @@ int http_client_req(int sock, struct http_request *req,
|
|||
NET_DBG("Received %d bytes", total_recv);
|
||||
}
|
||||
|
||||
if (timeout != K_FOREVER && timeout != K_NO_WAIT) {
|
||||
if (!K_TIMEOUT_EQ(req->internal.timeout, K_FOREVER) &&
|
||||
!K_TIMEOUT_EQ(req->internal.timeout, K_NO_WAIT)) {
|
||||
(void)k_delayed_work_cancel(&req->internal.work);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue