Commit 513ed819 authored by gejun's avatar gejun

Fix issues around WINDOW_UPDATE & rpc-timeout does not close the connection

parent 9cf3f779
...@@ -137,7 +137,7 @@ size_t H2Settings::ByteSize() const { ...@@ -137,7 +137,7 @@ size_t H2Settings::ByteSize() const {
return size; return size;
} }
void H2Settings::SerializeTo(void* out) const { size_t H2Settings::SerializeTo(void* out) const {
uint8_t* p = (uint8_t*)out; uint8_t* p = (uint8_t*)out;
if (header_table_size != DEFAULT_HEADER_TABLE_SIZE) { if (header_table_size != DEFAULT_HEADER_TABLE_SIZE) {
SaveUint16(p, HTTP2_SETTINGS_HEADER_TABLE_SIZE); SaveUint16(p, HTTP2_SETTINGS_HEADER_TABLE_SIZE);
...@@ -169,6 +169,7 @@ void H2Settings::SerializeTo(void* out) const { ...@@ -169,6 +169,7 @@ void H2Settings::SerializeTo(void* out) const {
SaveUint32(p + 2, max_header_list_size); SaveUint32(p + 2, max_header_list_size);
p += 6; p += 6;
} }
return static_cast<size_t>(p - (uint8_t*)out);
} }
void H2Settings::Print(std::ostream& os) const { void H2Settings::Print(std::ostream& os) const {
......
...@@ -90,10 +90,16 @@ struct H2Settings { ...@@ -90,10 +90,16 @@ struct H2Settings {
// Parse from n bytes from the iterator. // Parse from n bytes from the iterator.
// Returns true on success. // Returns true on success.
bool ParseFrom(butil::IOBufBytesIterator&, size_t n); bool ParseFrom(butil::IOBufBytesIterator&, size_t n);
// Bytes of serialized data. // Bytes of serialized data.
size_t ByteSize() const; size_t ByteSize() const;
// Maximum value that may be returned by ByteSize().
static const size_t MAX_BYTE_SIZE = 36;
// Serialize to `out' which is at least ByteSize() bytes long. // Serialize to `out' which is at least ByteSize() bytes long.
void SerializeTo(void* out) const; // Returns bytes written.
size_t SerializeTo(void* out) const;
void Print(std::ostream&) const; void Print(std::ostream&) const;
}; };
......
This diff is collapsed.
...@@ -24,7 +24,10 @@ ...@@ -24,7 +24,10 @@
#include "brpc/details/hpack.h" #include "brpc/details/hpack.h"
#include "brpc/stream_creator.h" #include "brpc/stream_creator.h"
#include "brpc/controller.h" #include "brpc/controller.h"
#ifndef NDEBUG
#include "bvar/bvar.h" #include "bvar/bvar.h"
#endif
namespace brpc { namespace brpc {
...@@ -159,8 +162,8 @@ public: ...@@ -159,8 +162,8 @@ public:
void Destroy(); void Destroy();
void Describe(butil::IOBuf*) const; void Describe(butil::IOBuf*) const;
// @SocketMessage // @SocketMessage
butil::Status AppendAndDestroySelf(butil::IOBuf* out, Socket*); butil::Status AppendAndDestroySelf(butil::IOBuf* out, Socket*) override;
size_t EstimatedByteSize(); size_t EstimatedByteSize() override;
private: private:
std::string& push(const std::string& name) std::string& push(const std::string& name)
...@@ -214,19 +217,28 @@ public: ...@@ -214,19 +217,28 @@ public:
size_t parsed_length() const { return this->_parsed_length; } size_t parsed_length() const { return this->_parsed_length; }
int stream_id() const { return header().h2_stream_id(); } int stream_id() const { return header().h2_stream_id(); }
#ifdef HAS_H2_STREAM_STATE int64_t ReleaseDeferredWindowUpdate() {
if (_deferred_window_update.load(butil::memory_order_relaxed) == 0) {
return 0;
}
return _deferred_window_update.exchange(0, butil::memory_order_relaxed);
}
bool ConsumeWindowSize(int64_t size);
#if defined(BRPC_H2_STREAM_STATE)
H2StreamState state() const { return _state; } H2StreamState state() const { return _state; }
void SetState(H2StreamState state); void SetState(H2StreamState state);
#endif #endif
friend class H2Context; friend class H2Context;
H2Context* _conn_ctx; H2Context* _conn_ctx;
#ifdef HAS_H2_STREAM_STATE #if defined(BRPC_H2_STREAM_STATE)
H2StreamState _state; H2StreamState _state;
#endif #endif
bool _stream_ended; bool _stream_ended;
butil::atomic<int64_t> _remote_window_size; butil::atomic<int64_t> _remote_window_left;
butil::atomic<int64_t> _local_window_size; butil::atomic<int64_t> _deferred_window_update;
uint64_t _correlation_id; uint64_t _correlation_id;
butil::IOBuf _remaining_header_fragment; butil::IOBuf _remaining_header_fragment;
}; };
...@@ -250,7 +262,6 @@ protected: ...@@ -250,7 +262,6 @@ protected:
}; };
} // namespace policy } // namespace policy
} // namespace brpc } // namespace brpc
#endif // BAIDU_RPC_POLICY_HTTP2_RPC_PROTOCOL_H #endif // BAIDU_RPC_POLICY_HTTP2_RPC_PROTOCOL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment