Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef REQUESTMONITOR_H | ||
#define REQUESTMONITOR_H | ||
|
||
#include <type_traits> | ||
#include <cassert> | ||
|
||
namespace http | ||
{ | ||
template<class R> | ||
class RequestMonitor | ||
{ | ||
R *request; | ||
|
||
protected: | ||
RequestMonitor() : | ||
request(nullptr) | ||
{ | ||
} | ||
|
||
virtual ~RequestMonitor() | ||
{ | ||
if (request) | ||
{ | ||
request->Cancel(); | ||
} | ||
} | ||
|
||
void RequestPoll() | ||
{ | ||
if (request && request->CheckDone()) | ||
{ | ||
OnResponse(request->Finish()); | ||
request = nullptr; | ||
} | ||
} | ||
|
||
template<class... Args> | ||
void RequestSetup(Args&&... args) | ||
{ | ||
assert(!request); | ||
request = new R(std::forward<Args>(args)...); | ||
} | ||
|
||
void RequestStart() | ||
{ | ||
assert(request); | ||
request->Start(); | ||
} | ||
|
||
virtual void OnResponse(typename std::result_of<decltype(&R::Finish)(R)>::type v) = 0; | ||
}; | ||
} | ||
|
||
#endif // REQUESTMONITOR_H | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters