From 5a87fb337dc034c6d96ff74d20c5c257c0a65b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Mon, 20 Oct 2014 17:55:49 +0200 Subject: first attempt at using mason to install packages [skip ci] --- src/storage/file_request_baton.cpp | 26 ++++++++++++++++++++++---- src/storage/http_request.cpp | 9 +++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) (limited to 'src/storage') 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(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(req->ptr)->st_size > std::numeric_limits::max()) { +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 + const uv_statbuf_t *stat = static_cast(req->ptr); +#else + const uv_stat_t *stat = static_cast(req->ptr); +#endif + if (stat->st_size > std::numeric_limits::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(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(req->ptr)->st_size); + (unsigned int)(stat->st_size); ptr->body.resize(size); ptr->buffer = uv_buf_init(const_cast(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 &&res) { http_baton->response = std::move(res); http_baton->async->data = new util::ptr(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 &http_baton = *(util::ptr *)async->data; if (http_baton->request) { @@ -193,7 +197,12 @@ void HTTPRequest::retryHTTPRequest(std::unique_ptr &&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 pair { static_cast(timer->data) }; pair->first->startHTTPRequest(std::move(pair->second)); pair->first->backoff_timer = nullptr; -- cgit v1.2.1