summaryrefslogtreecommitdiff
path: root/include/mbgl
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl')
-rw-r--r--include/mbgl/storage/base_request.hpp10
-rw-r--r--include/mbgl/storage/file_request.hpp2
-rw-r--r--include/mbgl/storage/http_request.hpp4
-rw-r--r--include/mbgl/storage/http_request_baton.hpp64
-rw-r--r--include/mbgl/storage/response.hpp2
-rw-r--r--include/mbgl/util/uv.hpp6
6 files changed, 86 insertions, 2 deletions
diff --git a/include/mbgl/storage/base_request.hpp b/include/mbgl/storage/base_request.hpp
index 832ecbc23d..e9e6bfcb46 100644
--- a/include/mbgl/storage/base_request.hpp
+++ b/include/mbgl/storage/base_request.hpp
@@ -31,14 +31,22 @@ public:
Callback *add(Callback &&callback, const util::ptr<BaseRequest> &request);
void remove(Callback *callback);
+
+ // Must be called by subclasses when a valid Response object is available. It will notify
+ // all listeners.
void notify();
+ // This function is called when the request ought to be stopped. Any subclass must make sure this
+ // is also called in its destructor. Calling this function repeatedly must be safe.
+ // This function must call notify().
+ virtual void cancel() = 0;
+
public:
const unsigned long thread_id;
const std::string path;
std::unique_ptr<Response> response;
-private:
+protected:
// This object may hold a shared_ptr to itself. It does this to prevent destruction of this object
// while a request is in progress.
util::ptr<BaseRequest> self;
diff --git a/include/mbgl/storage/file_request.hpp b/include/mbgl/storage/file_request.hpp
index c99237ad4b..2f883728ff 100644
--- a/include/mbgl/storage/file_request.hpp
+++ b/include/mbgl/storage/file_request.hpp
@@ -14,6 +14,8 @@ public:
FileRequest(const std::string &path, uv_loop_t *loop);
~FileRequest();
+ void cancel();
+
private:
FileRequestBaton *ptr = nullptr;
diff --git a/include/mbgl/storage/http_request.hpp b/include/mbgl/storage/http_request.hpp
index ef3210d48d..61aed954f0 100644
--- a/include/mbgl/storage/http_request.hpp
+++ b/include/mbgl/storage/http_request.hpp
@@ -22,6 +22,8 @@ public:
HTTPRequest(ResourceType type, const std::string &path, uv_loop_t *loop, util::ptr<SQLiteStore> store);
~HTTPRequest();
+ void cancel();
+
private:
void loadedCacheEntry(std::unique_ptr<Response> &&response);
@@ -31,6 +33,8 @@ private:
HTTPRequestBaton *http_baton = nullptr;
util::ptr<SQLiteStore> store;
const ResourceType type;
+
+ friend struct HTTPRequestBaton;
};
}
diff --git a/include/mbgl/storage/http_request_baton.hpp b/include/mbgl/storage/http_request_baton.hpp
index 5f06a68cd1..47e75a203b 100644
--- a/include/mbgl/storage/http_request_baton.hpp
+++ b/include/mbgl/storage/http_request_baton.hpp
@@ -6,21 +6,83 @@
#include <string>
typedef struct uv_async_s uv_async_t;
+typedef struct uv_timer_s uv_timer_t;
namespace mbgl {
class HTTPRequest;
+enum class HTTPResponseType : int8_t {
+ // This error probably won't be resolved by retrying anytime soon. We are giving up.
+ PermanentError = -5,
+
+ // This error might be resolved by waiting some time (e.g. server issues).
+ // We are going to do an exponential back-off and will try again in a few seconds.
+ TemporaryError = -4,
+
+ // This error was caused by a temporary error and it is likely that it will be resolved
+ // immediately. We are going to try again right away. This is like the TemporaryError, except
+ // that we will not perform exponential back-off.
+ SingularError = -3,
+
+ // This error might be resolved once the network reachability status changes.
+ // We are going to watch the network status for changes and will retry as soon as the operating
+ // system notifies us of a network status change.
+ ConnectionError = -2,
+
+ // The request was canceled programatically.
+ Canceled = -1,
+
+ // The request is still in progress.
+ Unknown = 0,
+
+ // The request returned data successfully. We retrieved and decoded the data successfully.
+ Successful = 1,
+
+ // The request confirmed that the data wasn't changed. We already have the data.
+ NotModified = 2,
+};
+
struct HTTPRequestBaton {
+ HTTPRequestBaton();
+ ~HTTPRequestBaton();
+
+
+ const unsigned long thread_id;
HTTPRequest *request = nullptr;
std::string path;
uv_async_t *async = nullptr;
+ uv_timer_t *timer = nullptr;
std::unique_ptr<Response> response;
void *ptr = nullptr;
- bool not_modified = false;
+ HTTPResponseType type = HTTPResponseType::Unknown;
+ uint8_t attempts = 0;
+
+ // IMPLEMENT THESE 3 PLATFORM SPECIFIC FUNCTIONS:
+ // Begin the HTTP request. Platform-specific implementation.
void start();
+
+ // This will be called so that the baton can release resources. It is expected that the ptr is
+ // null after this call. Platform-specific implementation.
+ void cleanup();
+
+ // This will be called to cancel the HTTP request (if possible). Platform-specific implementation.
void cancel();
+
+
+
+ // Called when the request should be canceled. This will call cancel() in turn.
+ void stop();
+
+ // After calling reset(), it is safe to call start() again on this baton object.
+ void reset();
+
+ // Will call start() after the specified timeout.
+ void retry(uint64_t delay);
+
+ // Will be
+ static void notify(uv_async_t *async);
};
}
diff --git a/include/mbgl/storage/response.hpp b/include/mbgl/storage/response.hpp
index 4960173f9e..8125656d81 100644
--- a/include/mbgl/storage/response.hpp
+++ b/include/mbgl/storage/response.hpp
@@ -6,6 +6,8 @@
namespace mbgl {
+
+
class Response {
public:
long code = 0;
diff --git a/include/mbgl/util/uv.hpp b/include/mbgl/util/uv.hpp
index 80fff9c96f..3c533cfbf8 100644
--- a/include/mbgl/util/uv.hpp
+++ b/include/mbgl/util/uv.hpp
@@ -4,6 +4,7 @@
#include <string>
typedef struct uv_async_s uv_async_t;
+typedef struct uv_timer_s uv_timer_t;
typedef struct uv_handle_s uv_handle_t;
typedef struct uv_loop_s uv_loop_t;
@@ -11,6 +12,11 @@ namespace uv {
std::string cwd();
+struct deleter {
+ void operator()(uv_async_t *async);
+ void operator()(uv_timer_t *timer);
+};
+
class thread;
class rwlock;
class loop;