diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-03-01 13:05:13 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-03-01 13:05:13 +0100 |
commit | 6c58101b12ee8e599aff3541f10c1fbfe5a027fb (patch) | |
tree | 190fd66b912ab47956fd547237056a9ee1ecdbbe /macosx/main.mm | |
parent | 0782cfc5be92ebc79711f6f9756db303026030e3 (diff) | |
download | qtlocation-mapboxgl-6c58101b12ee8e599aff3541f10c1fbfe5a027fb.tar.gz |
multithreaded curl for linux
Diffstat (limited to 'macosx/main.mm')
-rw-r--r-- | macosx/main.mm | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/macosx/main.mm b/macosx/main.mm index 973db9a861..bed18013cb 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -240,7 +240,12 @@ void restart() { [[NSApplication sharedApplication] postEvent: [NSEvent eventWithCGEvent:event] atStart:NO]; } -Request request_http(std::string url, std::function<void(Response&)> background_function, std::function<void()> foreground_callback) +struct Request { + int16_t identifier; + std::string original_url; +}; + +Request *request_http(std::string url, std::function<void(Response&)> background_function, std::function<void()> foreground_callback) { NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@(url.c_str())] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { @@ -262,20 +267,20 @@ Request request_http(std::string url, std::function<void(Response&)> background_ [task resume]; - Request req; + Request *req = new Request(); - req.identifier = task.taskIdentifier; - req.original_url = url; + req->identifier = task.taskIdentifier; + req->original_url = url; return req; } -void cancel_request_http(Request request) +void cancel_request_http(Request *request) { [[NSURLSession sharedSession] getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) { for (NSURLSessionDownloadTask *task in downloadTasks) - if (task.taskIdentifier == request.identifier) + if (task.taskIdentifier == request->identifier) return [task cancel]; }]; } |