summaryrefslogtreecommitdiff
path: root/common/foundation_request.mm
diff options
context:
space:
mode:
Diffstat (limited to 'common/foundation_request.mm')
-rw-r--r--common/foundation_request.mm20
1 files changed, 11 insertions, 9 deletions
diff --git a/common/foundation_request.mm b/common/foundation_request.mm
index 2bd651808a..c0b12cc734 100644
--- a/common/foundation_request.mm
+++ b/common/foundation_request.mm
@@ -41,8 +41,9 @@ class FoundationRequest : public llmr::platform::Request {
public:
FoundationRequest(const std::string &url,
std::function<void(llmr::platform::Response *)> background_function,
- std::function<void()> foreground_callback)
- : Request(url, background_function, foreground_callback) {
+ std::function<void()> foreground_callback,
+ uv_loop_t *loop)
+ : Request(url, background_function, foreground_callback, loop) {
#if TARGET_OS_IPHONE
active_tasks++;
dispatch_async(dispatch_get_main_queue(), ^(void) {
@@ -68,11 +69,12 @@ public:
std::shared_ptr<llmr::platform::Request>
llmr::platform::request_http(const std::string &url,
std::function<void(Response *)> background_function,
- std::function<void()> foreground_callback) {
+ std::function<void()> foreground_callback,
+ uv_loop_t *loop) {
uv_once(&request_initialize, request_initialize_cb);
std::shared_ptr<FoundationRequest> req =
- std::make_shared<FoundationRequest>(url, background_function, foreground_callback);
+ std::make_shared<FoundationRequest>(url, background_function, foreground_callback, loop);
// Note that we are creating a new shared_ptr pointer(!) to make sure there is at least one
// shared_ptr in existence while the NSURLSession is loading our data. We are making sure in the
@@ -91,13 +93,13 @@ llmr::platform::request_http(const std::string &url,
return;
}
- req->res = std::make_unique<Response>();
+ (*req_ptr)->res = std::make_unique<Response>();
if (!error && [response isKindOfClass:[NSHTTPURLResponse class]]) {
- req->res->code = [(NSHTTPURLResponse *)response statusCode];
- req->res->body = {(const char *)[data bytes], [data length]};
+ (*req_ptr)->res->code = [(NSHTTPURLResponse *)response statusCode];
+ (*req_ptr)->res->body = {(const char *)[data bytes], [data length]};
} else {
- req->res->error_message = [[error localizedDescription] UTF8String];
+ (*req_ptr)->res->error_message = [[error localizedDescription] UTF8String];
}
// We're currently in the request thread. We're going to schedule a uv_work request that
@@ -111,7 +113,7 @@ llmr::platform::request_http(const std::string &url,
// Executes the background_function in a libuv thread pool, and the after_work_cb back in
// the *main* event loop.
- uv_queue_work(uv_default_loop(), work, Request::work_callback,
+ uv_queue_work((*req_ptr)->loop, work, Request::work_callback,
Request::after_work_callback);
}];