diff options
Diffstat (limited to 'src/storage/file_request.cpp')
-rw-r--r-- | src/storage/file_request.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/storage/file_request.cpp b/src/storage/file_request.cpp new file mode 100644 index 0000000000..33398d5ef1 --- /dev/null +++ b/src/storage/file_request.cpp @@ -0,0 +1,37 @@ +#include <mbgl/storage/file_request.hpp> +#include <mbgl/storage/file_request_baton.hpp> +#include <mbgl/storage/response.hpp> + +#include <uv.h> + +#include <cassert> + +#include <unistd.h> + +namespace mbgl { + +FileRequest::FileRequest(const std::string &path_, uv_loop_t *loop) + : BaseRequest(path_), ptr(new FileRequestBaton(this, path, loop)) { +} + +void FileRequest::cancel() { + assert(thread_id == uv_thread_self()); + + if (ptr) { + ptr->cancel(); + + // When deleting a FileRequest object with a uv_fs_* call is in progress, we are making sure + // that the callback doesn't accidentally reference this object again. + ptr->request = nullptr; + ptr = nullptr; + } + + notify(); +} + +FileRequest::~FileRequest() { + assert(thread_id == uv_thread_self()); + cancel(); +} + +} |