Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kelbon committed Jan 26, 2025
1 parent a71aecc commit dd9cca1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/tgbm/net/http2/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct waiter_of_connection : bi::list_base_hook<link_option> {

bool await_ready() noexcept;
std::coroutine_handle<> await_suspend(std::coroutine_handle<>) noexcept;
[[nodiscard]] http2_connection_ptr await_resume() const;
[[nodiscard]] http2_connection_ptr await_resume();
};

struct connection_lock_t {
Expand Down
13 changes: 9 additions & 4 deletions src/net/http2/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ struct request_node {
dd::task<int>::handle_type task; // setted by 'await_suspend' (requester)
};
http2_connection_ptr connection = nullptr;
// received resonse (filled by 'reader' in connection)
// received resonse (filled by 'reader' in connection)
on_header_fn_ptr on_header;
on_data_part_fn_ptr on_data_part;
int status = reqerr_e::unknown_err;
Expand Down Expand Up @@ -519,6 +519,7 @@ struct http2_connection {
void return_node(request_node* ptr) noexcept {
assert(ptr);
forget(*ptr);
ptr->connection = nullptr;
if (free_nodes.size() >= std::min<size_t>(1024, server_settings.max_concurrent_streams)) {
delete ptr;
return;
Expand Down Expand Up @@ -557,8 +558,12 @@ void intrusive_ptr_add_ref(request_node* p) {

void intrusive_ptr_release(request_node* p) noexcept {
--p->refcount;
if (p->refcount == 0)
p->connection->return_node(p);
if (p->refcount == 0) {
if (p->connection)
p->connection->return_node(p);
else
delete p;
}
}

// any finish request with cancelled
Expand Down Expand Up @@ -1348,7 +1353,7 @@ std::coroutine_handle<> noexport::waiter_of_connection::await_suspend(std::corou
return client->start_connecting().handle;
}

[[nodiscard]] http2_connection_ptr noexport::waiter_of_connection::await_resume() const {
[[nodiscard]] http2_connection_ptr noexport::waiter_of_connection::await_resume() {
if (!result || result->is_dropped() || client->stop_requested)
return nullptr;
return std::move(result);
Expand Down
17 changes: 17 additions & 0 deletions test/test_http2_frames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ struct test_factory {
}
void stop() {
stop_requested = true;
while (!queue.empty()) {
auto x = queue.front();
x.ec = boost::asio::error::operation_aborted;
queue.pop_front();
x.handle.resume();
}
}
bool run_one(tgbm::duration_t timeout) {
stop_requested = false;
Expand Down Expand Up @@ -129,6 +135,14 @@ void test_connection::start_read(std::coroutine_handle<> callback, std::span<tgb
}

void test_connection::shutdown() noexcept {
if (reader) {
*reader_ec = boost::asio::error::operation_aborted;
std::coroutine_handle r = reader;
reader = nullptr;
reader_ec = nullptr;
reader_buf = {};
r.resume();
}
while (!factory.queue.empty()) {
auto [c, t, ec] = factory.queue.front();
if (c == this) {
Expand Down Expand Up @@ -199,12 +213,15 @@ dd::generator<dd::nothing_t> connection_validator(test_connection& con) {
co_yield dd::elements_of(wait_header_and_data(input, hdr, data));
REQUIRE(hdr.type == tgbm::http2::frame_e::DATA);
bytes.clear();
// TODO check this test fully
tgbm::http2::frame_header h;
h.type = tgbm::http2::frame_e::HEADERS;
h.stream_id = hdr.stream_id;
h.flags = tgbm::http2::flags::END_HEADERS | tgbm::http2::flags::END_STREAM;
h.length = 0;
h.send_to(std::back_inserter(bytes));
con.push_answer_bytes(bytes);

fmt::println("received {}, {}", hdr.stream_id, (int)hdr.type);
}

Expand Down

0 comments on commit dd9cca1

Please sign in to comment.