clean up os x + ios request code

fixes #129
This commit is contained in:
Konstantin Käfer
2014-04-14 11:47:57 -04:00
parent b4ad515792
commit 305e688a3a
12 changed files with 112 additions and 157 deletions

View File

@@ -48,28 +48,27 @@ void TileData::request() {
// Note: Somehow this feels slower than the change to request_http()
std::weak_ptr<TileData> weak_tile = shared_from_this();
platform::Request *request = platform::request_http(url, [=](platform::Response& res) {
req = platform::request_http(url, [weak_tile, url](platform::Response *res) {
std::shared_ptr<TileData> tile = weak_tile.lock();
if (!tile || tile->state == State::obsolete) {
// noop. Tile is obsolete and we're now just waiting for the refcount
// to drop to zero for destruction.
} else if (res.code == 200) {
} else if (res->code == 200) {
tile->state = State::loaded;
tile->data.swap(res.body);
tile->data.swap(res->body);
tile->parse();
} else {
fprintf(stderr, "tile loading failed (%s): %d\n", url.c_str(), res.code);
fprintf(stderr, "tile loading failed (%s): %d\n", url.c_str(), res->code);
}
}, []() {
platform::restart();
});
req = request;
}
void TileData::cancel() {
if (state != State::obsolete) {
state = State::obsolete;
platform::cancel_request_http(req);
platform::cancel_request_http(req.lock());
}
}