diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-08-16 09:08:52 -0700 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-08-16 09:08:52 -0700 |
| commit | 4f0fcc582eed69e4a45a94c4ef5a4d0e2e31a216 (patch) | |
| tree | df37c60c4afb113f3a4fa6efad1a6cb919543e10 /node/HttpClient.hpp | |
| parent | aa59cfd5458241cecb96409b90ca38058b65b651 (diff) | |
| download | infinitytier-4f0fcc582eed69e4a45a94c4ef5a4d0e2e31a216.tar.gz infinitytier-4f0fcc582eed69e4a45a94c4ef5a4d0e2e31a216.zip | |
Refactor HttpClient a bit.
Diffstat (limited to 'node/HttpClient.hpp')
| -rw-r--r-- | node/HttpClient.hpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/node/HttpClient.hpp b/node/HttpClient.hpp index 59c1bcac..f65b88e8 100644 --- a/node/HttpClient.hpp +++ b/node/HttpClient.hpp @@ -30,11 +30,15 @@ #include <string> #include <map> +#include <set> #include "Constants.hpp" +#include "Mutex.hpp" namespace ZeroTier { +class HttpClient_Private_Request; + /** * HTTP client that does queries in the background * @@ -55,8 +59,12 @@ namespace ZeroTier { class HttpClient { public: + friend class HttpClient_Private_Request; typedef void * Request; + HttpClient(); + ~HttpClient(); + /** * Empty map for convenience use */ @@ -65,24 +73,37 @@ public: /** * Request a URL using the GET method */ - static inline Request GET( + inline Request GET( const std::string &url, const std::map<std::string,std::string> &headers, unsigned int timeout, - void (*handler)(void *,int,const std::string &,bool,const std::string &), + void (*handler)(void *,int,const std::string &,const std::string &), void *arg) { return _do("GET",url,headers,timeout,handler,arg); } + /** + * Cancel a request + * + * If the request is not active, this does nothing. This may take some time + * depending on HTTP implementation. It may also not kill instantly, but + * it will prevent the handler function from ever being called and cause the + * request to die silently when complete. + */ + void cancel(Request req); + private: - static Request _do( + Request _do( const char *method, const std::string &url, const std::map<std::string,std::string> &headers, unsigned int timeout, - void (*handler)(void *,int,const std::string &,bool,const std::string &), + void (*handler)(void *,int,const std::string &,const std::string &), void *arg); + + std::set<Request> _requests; + Mutex _requests_m; }; } // namespace ZeroTier |
