Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/anyhttp/h2/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class NGHttp2Stream : public std::enable_shared_from_this<NGHttp2Stream>
~NGHttp2Stream();

/// This function is called on receiving a data frame `nghttp2_on_data_chunk_recv_callback`.
void on_data(nghttp2_session* session, int32_t id_, const uint8_t* data, size_t len);
void on_data(const uint8_t* data, size_t len);

/// This function is called on receiving a header or data frame that has the EOF flag set.
void on_eof(nghttp2_session* session, int32_t id_);
Expand Down
18 changes: 13 additions & 5 deletions src/h2/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,23 @@ static int on_data_chunk_recv_callback(nghttp2_session* session, uint8_t flags,
auto handler = static_cast<NGHttp2Session*>(user_data);
auto stream = handler->find_stream(stream_id);

if (!stream)
//
// Connection-level credit is given back right away, with or without a stream: nobody else would,
// and the connection would run out of it. The stream-level window is only reopened once the
// reader has taken the data, which is what applies back pressure.
//
nghttp2_session_consume_connection(session, len);

if (stream)
{
logd("[{}.{}] on_data_chunk_recv_callback: DATA, len={}", handler->log_prefix(), stream_id,
len);
stream->on_data(data, len);
}
else
logw("[{}.{}] on_data_chunk_recv_callback: DATA, but no stream found (id={})",
handler->log_prefix(), stream_id, stream_id);
return 0;
}

logd("[{}.{}] on_data_chunk_recv_callback: DATA, len={}", handler->log_prefix(), stream_id, len);
stream->on_data(session, stream_id, data, len);
handler->start_write(); // might re-open windows

return 0;
Expand Down
5 changes: 1 addition & 4 deletions src/h2/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,16 +571,13 @@ void NGHttp2Stream::call_read_handler(asio::const_buffer view)
#endif
}

void NGHttp2Stream::on_data(nghttp2_session* session, int32_t id_, const uint8_t* data, size_t len)
void NGHttp2Stream::on_data(const uint8_t* data, size_t len)
{
assert(id == id_);
assert(!eof_received);
assert(len); // for EOF, on_eof() is called instead

mlogd("read callback: {} bytes...", len);

nghttp2_session_consume_connection(session, len);

//
// We try to invoke the read handler directly with the new buffer view. Only if there is no
// pending read handler that can be invoked immediately, the data will be copied into a buffer.
Expand Down
25 changes: 12 additions & 13 deletions src/h2v2/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,22 @@ static int on_recv_data(nghttp2_conn* conn, int64_t stream_id, const uint8_t* da
auto handler = static_cast<NGHttp2Session*>(user_data);
auto stream = static_cast<NGHttp2Stream*>(stream_user_data);

if (!stream)
{
logw("[{}] on_recv_data: DATA, but no stream found", handler->log_prefix(stream_id));
nghttp2_conn_extend_max_offset(conn, datalen);
return 0;
}

logd("[{}] on_recv_data: DATA, len={}", handler->log_prefix(stream_id), datalen);

//
// Connection-level credit is given back right away; the stream-level window is only reopened
// once the reader has taken the data, which is what applies back pressure. Version 1 split the
// same two steps between nghttp2_session_consume_connection() and consume_stream().
// Connection-level credit is given back right away, with or without a stream: nobody else would,
// and the connection would run out of it. The stream-level window is only reopened once the
// reader has taken the data, which is what applies back pressure. Version 1 split the same two
// steps between nghttp2_session_consume_connection() and consume_stream().
//
nghttp2_conn_extend_max_offset(conn, datalen);

stream->on_data(data, datalen);
if (stream)
{
logd("[{}] on_recv_data: DATA, len={}", handler->log_prefix(stream_id), datalen);
stream->on_data(data, datalen);
}
else
logw("[{}] on_recv_data: DATA, but no stream found", handler->log_prefix(stream_id));

handler->start_write(); // might re-open windows

return 0;
Expand Down