summaryrefslogtreecommitdiff
path: root/src/mbgl/storage/file_request.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/storage/file_request.cpp')
-rw-r--r--src/mbgl/storage/file_request.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/mbgl/storage/file_request.cpp b/src/mbgl/storage/file_request.cpp
new file mode 100644
index 0000000000..9f74c7b414
--- /dev/null
+++ b/src/mbgl/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 == std::this_thread::get_id());
+
+ 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 == std::this_thread::get_id());
+ cancel();
+}
+
+}