Fix async client issues.

This commit is contained in:
Adam Gu
2018-06-14 17:21:24 +08:00
parent 781121aea3
commit 44271eb2cc
17 changed files with 339 additions and 238 deletions
+9 -4
View File
@@ -3,7 +3,7 @@
#include "boost/asio/io_context.hpp"
#include "webcc/logger.h"
#include "webcc/http_async_client.h"
#include "webcc/async_http_client.h"
// In order to test this client, create a file index.html whose content is
// simply "Hello, World!", then start a HTTP server with Python 3:
@@ -19,15 +19,20 @@ void Test(boost::asio::io_context& ioc) {
request->Build();
webcc::HttpAsyncClientPtr client(new webcc::HttpAsyncClient(ioc));
webcc::HttpAsyncClientPtr client(new webcc::AsyncHttpClient(ioc));
// Response handler.
auto handler = [](std::shared_ptr<webcc::HttpResponse> response,
webcc::Error error) {
webcc::Error error,
bool timed_out) {
if (error == webcc::kNoError) {
std::cout << response->content() << std::endl;
} else {
std::cout << webcc::DescribeError(error) << std::endl;
std::cout << webcc::DescribeError(error);
if (timed_out) {
std::cout << " (timed out)";
}
std::cout << std::endl;
}
};
+5 -4
View File
@@ -3,7 +3,7 @@
#include "json/json.h"
#include "webcc/logger.h"
#include "webcc/rest_async_client.h"
#include "webcc/async_rest_client.h"
// -----------------------------------------------------------------------------
@@ -44,7 +44,7 @@ class BookListClient {
}
private:
webcc::RestAsyncClient rest_client_;
webcc::AsyncRestClient rest_client_;
};
// -----------------------------------------------------------------------------
@@ -84,7 +84,7 @@ public:
}
private:
webcc::RestAsyncClient rest_client_;
webcc::AsyncRestClient rest_client_;
};
// -----------------------------------------------------------------------------
@@ -113,7 +113,8 @@ int main(int argc, char* argv[]) {
// Response handler.
auto handler = [](std::shared_ptr<webcc::HttpResponse> response,
webcc::Error error) {
webcc::Error error,
bool timed_out) {
if (error == webcc::kNoError) {
std::cout << response->content() << std::endl;
} else {
+2 -2
View File
@@ -34,8 +34,8 @@ protected:
void PrintError() {
std::cout << webcc::DescribeError(rest_client_.error());
if (rest_client_.timeout_occurred()) {
std::cout << " (timeout)";
if (rest_client_.timed_out()) {
std::cout << " (timed out)";
}
std::cout << std::endl;
}