summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-04-30 12:02:41 -0400
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-04-30 12:02:41 -0400
commit95214472d433e3efa6d9045193271b38231387a2 (patch)
tree5532de9c0143a78dc9621fcf67cf2e0cd5405cdb /platform/darwin
parentbb88b9cd8e3109ed00af13d31fead29d40a4a9c2 (diff)
downloadqtlocation-mapboxgl-95214472d433e3efa6d9045193271b38231387a2.tar.gz
Use uv::async
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/http_request_nsurl.mm18
1 files changed, 4 insertions, 14 deletions
diff --git a/platform/darwin/http_request_nsurl.mm b/platform/darwin/http_request_nsurl.mm
index e3f0b5dad6..9572970f20 100644
--- a/platform/darwin/http_request_nsurl.mm
+++ b/platform/darwin/http_request_nsurl.mm
@@ -72,7 +72,7 @@ private:
std::unique_ptr<Response> response;
const std::shared_ptr<const Response> existingResponse;
ResponseStatus status = ResponseStatus::PermanentError;
- uv_async_t *async = nullptr;
+ uv::async async;
int attempts = 0;
uv_timer_t *timer = nullptr;
enum : bool { PreemptImmediately, ExponentialBackoff } strategy = PreemptImmediately;
@@ -134,27 +134,17 @@ HTTPRequest::HTTPRequest(HTTPNSURLContext* context_, const Resource& resource_,
: RequestBase(resource_, callback_),
context(context_),
existingResponse(existingResponse_),
- async(new uv_async_t) {
+ async(loop, [this] { handleResponse(); }) {
context->addRequest(this);
-
- async->data = this;
- uv_async_init(loop, async, [](uv_async_t *as, int) {
- auto impl = reinterpret_cast<HTTPRequest *>(as->data);
- impl->handleResponse();
- });
-
start();
}
HTTPRequest::~HTTPRequest() {
assert(!task);
- assert(async);
// Stop the backoff timer to avoid re-triggering this request.
cancelTimer();
- uv::close(async);
-
context->removeRequest(this);
}
@@ -364,7 +354,7 @@ void HTTPRequest::handleResult(NSData *data, NSURLResponse *res, NSError *error)
response->message = "response class is not NSHTTPURLResponse";
}
- uv_async_send(async);
+ async.send();
}
void HTTPRequest::retry(uint64_t timeout) {
@@ -373,7 +363,7 @@ void HTTPRequest::retry(uint64_t timeout) {
assert(!timer);
timer = new uv_timer_t;
timer->data = this;
- uv_timer_init(async->loop, timer);
+ uv_timer_init(async.get()->loop, timer);
uv_timer_start(timer, restart, timeout, 0);
}