summaryrefslogtreecommitdiff
path: root/src/storage/file_request.cpp
blob: 9534c1a346b3d9fbd910d34af7b2ba4ba2d25ed2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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(uv_thread_self() == threadId);

    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(uv_thread_self() == threadId);
    cancel();
}

}