summaryrefslogtreecommitdiff
path: root/src/storage
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-10-20 17:55:49 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-10-20 17:55:49 +0200
commit5a87fb337dc034c6d96ff74d20c5c257c0a65b77 (patch)
treeae6b75779c2dbd868058fb643413669050ce46f0 /src/storage
parent6bd63c565eee2a41fdd5ccbc248426bd469e1809 (diff)
downloadqtlocation-mapboxgl-5a87fb337dc034c6d96ff74d20c5c257c0a65b77.tar.gz
first attempt at using mason to install packages
[skip ci]
Diffstat (limited to 'src/storage')
-rw-r--r--src/storage/file_request_baton.cpp26
-rw-r--r--src/storage/http_request.cpp9
2 files changed, 31 insertions, 4 deletions
diff --git a/src/storage/file_request_baton.cpp b/src/storage/file_request_baton.cpp
index 127c78f3e5..d4c135fd71 100644
--- a/src/storage/file_request_baton.cpp
+++ b/src/storage/file_request_baton.cpp
@@ -29,7 +29,11 @@ void FileRequestBaton::notify_error(uv_fs_t *req) {
if (ptr->request && req->result < 0 && !ptr->canceled && req->result != UV_ECANCELED) {
ptr->request->response = std::unique_ptr<Response>(new Response);
ptr->request->response->code = req->result == UV_ENOENT ? 404 : 500;
+#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
+ ptr->request->response->message = uv_strerror(uv_last_error(req->loop));
+#else
ptr->request->response->message = uv_strerror(int(req->result));
+#endif
ptr->request->notify();
}
}
@@ -54,7 +58,8 @@ void FileRequestBaton::file_opened(uv_fs_t *req) {
uv_fs_close(req->loop, req, fd, file_closed);
} else {
ptr->fd = fd;
- uv_fs_fstat(req->loop, req, fd, file_stated);
+ const int r = uv_fs_fstat(req->loop, req, fd, file_stated);
+ assert(r == 0);
}
}
}
@@ -63,7 +68,7 @@ void FileRequestBaton::file_stated(uv_fs_t *req) {
FileRequestBaton *ptr = (FileRequestBaton *)req->data;
assert(ptr->thread_id == uv_thread_self());
- if (req->result < 0 || ptr->canceled || !ptr->request) {
+ if (req->result != 0 || ptr->canceled || !ptr->request) {
// Stating failed or was canceled. We already have an open file handle
// though, which we'll have to close.
notify_error(req);
@@ -71,13 +76,22 @@ void FileRequestBaton::file_stated(uv_fs_t *req) {
uv_fs_req_cleanup(req);
uv_fs_close(req->loop, req, ptr->fd, file_closed);
} else {
- if (static_cast<const uv_stat_t *>(req->ptr)->st_size > std::numeric_limits<int>::max()) {
+#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
+ const uv_statbuf_t *stat = static_cast<const uv_statbuf_t *>(req->ptr);
+#else
+ const uv_stat_t *stat = static_cast<const uv_stat_t *>(req->ptr);
+#endif
+ if (stat->st_size > std::numeric_limits<int>::max()) {
// File is too large for us to open this way because uv_buf's only support unsigned
// ints as maximum size.
if (ptr->request) {
ptr->request->response = std::unique_ptr<Response>(new Response);
ptr->request->response->code = UV_EFBIG;
+#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
+ ptr->request->response->message = uv_strerror(uv_err_t {UV_EFBIG, 0});
+#else
ptr->request->response->message = uv_strerror(UV_EFBIG);
+#endif
ptr->request->notify();
}
@@ -85,11 +99,15 @@ void FileRequestBaton::file_stated(uv_fs_t *req) {
uv_fs_close(req->loop, req, ptr->fd, file_closed);
} else {
const unsigned int size =
- (unsigned int)(static_cast<const uv_stat_t *>(req->ptr)->st_size);
+ (unsigned int)(stat->st_size);
ptr->body.resize(size);
ptr->buffer = uv_buf_init(const_cast<char *>(ptr->body.data()), size);
uv_fs_req_cleanup(req);
+#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
+ uv_fs_read(req->loop, req, ptr->fd, ptr->buffer.base, ptr->buffer.len, -1, file_read);
+#else
uv_fs_read(req->loop, req, ptr->fd, &ptr->buffer, 1, 0, file_read);
+#endif
}
}
}
diff --git a/src/storage/http_request.cpp b/src/storage/http_request.cpp
index 1b799d4895..ca1412fd9e 100644
--- a/src/storage/http_request.cpp
+++ b/src/storage/http_request.cpp
@@ -77,7 +77,11 @@ void HTTPRequest::startHTTPRequest(std::unique_ptr<Response> &&res) {
http_baton->response = std::move(res);
http_baton->async->data = new util::ptr<HTTPRequestBaton>(http_baton);
+#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
+ uv_async_init(loop, http_baton->async, [](uv_async_t *async, int) {
+#else
uv_async_init(loop, http_baton->async, [](uv_async_t *async) {
+#endif
util::ptr<HTTPRequestBaton> &http_baton = *(util::ptr<HTTPRequestBaton> *)async->data;
if (http_baton->request) {
@@ -193,7 +197,12 @@ void HTTPRequest::retryHTTPRequest(std::unique_ptr<Response> &&res, uint64_t tim
backoff_timer = new uv_timer_t();
uv_timer_init(loop, backoff_timer);
backoff_timer->data = new RetryBaton(this, std::move(res));
+
+#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
+ uv_timer_start(backoff_timer, [](uv_timer_t *timer, int) {
+#else
uv_timer_start(backoff_timer, [](uv_timer_t *timer) {
+#endif
std::unique_ptr<RetryBaton> pair { static_cast<RetryBaton *>(timer->data) };
pair->first->startHTTPRequest(std::move(pair->second));
pair->first->backoff_timer = nullptr;