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
17 changes: 6 additions & 11 deletions source/common/http/codec_helper.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include <vector>

#include "envoy/http/codec.h"

#include "common/common/assert.h"

#include "absl/container/inlined_vector.h"

namespace Envoy {
namespace Http {

Expand Down Expand Up @@ -54,25 +54,20 @@ class StreamCallbackHelper {
bool local_end_stream_{};

protected:
StreamCallbackHelper() {
// Set space for 8 callbacks (64 bytes).
callbacks_.reserve(8);
}

void addCallbacks_(StreamCallbacks& callbacks) {
void addCallbacksHelper(StreamCallbacks& callbacks) {
ASSERT(!reset_callbacks_started_ && !local_end_stream_);
callbacks_.push_back(&callbacks);
for (uint32_t i = 0; i < high_watermark_callbacks_; ++i) {
callbacks.onAboveWriteBufferHighWatermark();
}
}

void removeCallbacks_(StreamCallbacks& callbacks) {
void removeCallbacksHelper(StreamCallbacks& callbacks) {
// For performance reasons we just clear the callback and do not resize the vector.
// Reset callbacks scale with the number of filters per request and do not get added and
// removed multiple times.
// The vector may not be safely resized without making sure the run.*Callbacks() helper
// functions above still handle removeCallbacks_() calls mid-loop.
// functions above still handle removeCallbacksHelper() calls mid-loop.
for (auto& callback : callbacks_) {
if (callback == &callbacks) {
callback = nullptr;
Expand All @@ -82,7 +77,7 @@ class StreamCallbackHelper {
}

private:
std::vector<StreamCallbacks*> callbacks_;
absl::InlinedVector<StreamCallbacks*, 8> callbacks_;
bool reset_callbacks_started_{};
uint32_t high_watermark_callbacks_{};
};
Expand Down
2 changes: 1 addition & 1 deletion source/common/http/conn_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ RequestDecoder& ConnectionManagerImpl::newStream(ResponseEncoder& response_encod
new_stream->response_encoder_->getStream().addCallbacks(*new_stream);
new_stream->buffer_limit_ = new_stream->response_encoder_->getStream().bufferLimit();
// If the network connection is backed up, the stream should be made aware of it on creation.
// Both HTTP/1.x and HTTP/2 codecs handle this in StreamCallbackHelper::addCallbacks_.
// Both HTTP/1.x and HTTP/2 codecs handle this in StreamCallbackHelper::addCallbacksHelper.
ASSERT(read_callbacks_->connection().aboveHighWatermark() == false ||
new_stream->high_watermark_count_ > 0);
new_stream->moveIntoList(std::move(new_stream), streams_);
Expand Down
4 changes: 2 additions & 2 deletions source/common/http/http1/codec_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class StreamEncoderImpl : public virtual StreamEncoder,
void disableChunkEncoding() override { disable_chunk_encoding_ = true; }

// Http::Stream
void addCallbacks(StreamCallbacks& callbacks) override { addCallbacks_(callbacks); }
void removeCallbacks(StreamCallbacks& callbacks) override { removeCallbacks_(callbacks); }
void addCallbacks(StreamCallbacks& callbacks) override { addCallbacksHelper(callbacks); }
void removeCallbacks(StreamCallbacks& callbacks) override { removeCallbacksHelper(callbacks); }
// After this is called, for the HTTP/1 codec, the connection should be closed, i.e. no further
// progress may be made with the codec.
void resetStream(StreamResetReason reason) override;
Expand Down
4 changes: 2 additions & 2 deletions source/common/http/http2/codec_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ class ConnectionImpl : public virtual Connection, protected Logger::Loggable<Log
Http1StreamEncoderOptionsOptRef http1StreamEncoderOptions() override { return absl::nullopt; }

// Http::Stream
void addCallbacks(StreamCallbacks& callbacks) override { addCallbacks_(callbacks); }
void removeCallbacks(StreamCallbacks& callbacks) override { removeCallbacks_(callbacks); }
void addCallbacks(StreamCallbacks& callbacks) override { addCallbacksHelper(callbacks); }
void removeCallbacks(StreamCallbacks& callbacks) override { removeCallbacksHelper(callbacks); }
void resetStream(StreamResetReason reason) override;
void readDisable(bool disable) override;
uint32_t bufferLimit() override { return pending_recv_data_.highWatermark(); }
Expand Down
6 changes: 4 additions & 2 deletions source/extensions/quic_listeners/quiche/envoy_quic_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ class EnvoyQuicStream : public virtual Http::StreamEncoder,

void addCallbacks(Http::StreamCallbacks& callbacks) override {
ASSERT(!local_end_stream_);
addCallbacks_(callbacks);
addCallbacksHelper(callbacks);
}
void removeCallbacks(Http::StreamCallbacks& callbacks) override {
removeCallbacksHelper(callbacks);
}
void removeCallbacks(Http::StreamCallbacks& callbacks) override { removeCallbacks_(callbacks); }
uint32_t bufferLimit() override { return send_buffer_simulation_.highWatermark(); }
const Network::Address::InstanceConstSharedPtr& connectionLocalAddress() override {
return connection()->localAddress();
Expand Down