Skip to content

Commit

Permalink
[coro_http_client][improve]some improvment (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored Nov 1, 2023
1 parent 0e386d4 commit 38fcdb3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/ylt/coro_http/coro_http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ using req_content_type = cinatra::req_content_type;
using resp_data = cinatra::resp_data;
using http_method = cinatra::http_method;
using http_header = cinatra::http_header;
using uri_t = cinatra::uri_t;
template <typename String = std::string>
using req_context = cinatra::req_context<String>;
} // namespace coro_http
9 changes: 5 additions & 4 deletions include/ylt/thirdparty/cinatra/coro_http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ struct http_header;

struct resp_data {
std::error_code net_err;
int status;
int status = 0;
bool eof = false;
std::string_view resp_body;
std::span<http_header> resp_headers;
bool eof;
#ifdef BENCHMARK_TEST
uint64_t total;
uint64_t total = 0;
#endif
};

Expand All @@ -104,7 +104,7 @@ struct multipart_t {
size_t size = 0;
};

class coro_http_client {
class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
public:
struct config {
std::optional<std::chrono::steady_clock::duration> conn_timeout_duration;
Expand Down Expand Up @@ -1578,6 +1578,7 @@ class coro_http_client {
async_simple::coro::Lazy<void> async_read_ws() {
resp_data data{};

auto self = this->shared_from_this();
read_buf_.consume(read_buf_.size());
size_t header_size = 2;
std::shared_ptr sock = socket_;
Expand Down
4 changes: 2 additions & 2 deletions src/coro_io/tests/test_client_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ TEST_CASE("test client pools parallel r/w") {
CHECK(cli->get_host_name() == std::to_string(i));
}
auto rw = [&pool](int i) -> Lazy<void> {
ELOG_DEBUG << "start to insert {" << i << "} to hash table.";
// ELOG_DEBUG << "start to insert {" << i << "} to hash table.";
auto cli = pool[std::to_string(i)];
CHECK(cli->get_host_name() == std::to_string(i));
ELOG_DEBUG << "end to insert {" << i << "} to hash table.";
// ELOG_DEBUG << "end to insert {" << i << "} to hash table.";
co_return;
};

Expand Down

0 comments on commit 38fcdb3

Please sign in to comment.