Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subsys: net: lib: nrf_cloud: Reuse socket for A-GNSS #12575

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions subsys/net/lib/nrf_cloud/src/nrf_cloud_rest.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ static void sync_rest_client_data(struct nrf_cloud_rest_context *const rest_ctx,
rest_ctx->response_len = resp->response_len;
rest_ctx->total_response_len = resp->total_response_len;

rest_ctx->connect_socket = req->connect_socket;
if (resp->used_socket_is_alive) {
rest_ctx->connect_socket = resp->used_socket_id;
} else {
rest_ctx->connect_socket = -1;
}
}

static int do_rest_client_request(struct nrf_cloud_rest_context *const rest_ctx,
Expand Down Expand Up @@ -665,6 +669,12 @@ int nrf_cloud_rest_agps_data_get(struct nrf_cloud_rest_context *const rest_ctx,
memset(&resp, 0, sizeof(resp));
init_rest_client_request(rest_ctx, &req, HTTP_POST);

/* Usually more than one HTTP request is needed to fetch A-GNSS data, so the socket is
* always re-used. After all A-GNSS data has been downloaded, the socket is automatically
* closed, unless the caller has enabled rest_ctx->keep_alive.
*/
req.keep_alive = true;

#if defined(CONFIG_NRF_CLOUD_AGPS_FILTERED_RUNTIME)
filtered = request->filtered;
mask_angle = request->mask_angle;
Expand Down Expand Up @@ -967,14 +977,13 @@ int nrf_cloud_rest_disconnect(struct nrf_cloud_rest_context *const rest_ctx)
}

int err = close(rest_ctx->connect_socket);

if (err) {
LOG_ERR("Failed to close socket, error: %d", errno);
err = -EIO;
} else {
rest_ctx->connect_socket = -1;
}

rest_ctx->connect_socket = -1;

return err;
}

Expand Down
Loading