/proc/self/cwd/source/extensions/filters/network/thrift_proxy/conn_state.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include "envoy/tcp/conn_pool.h" |
4 | | |
5 | | namespace Envoy { |
6 | | namespace Extensions { |
7 | | namespace NetworkFilters { |
8 | | namespace ThriftProxy { |
9 | | |
10 | | /** |
11 | | * ThriftConnectionState tracks thrift-related connection state for pooled connections. |
12 | | */ |
13 | | class ThriftConnectionState : public Tcp::ConnectionPool::ConnectionState { |
14 | | public: |
15 | 0 | ThriftConnectionState(int32_t initial_sequence_id = 0) : next_sequence_id_(initial_sequence_id) {} |
16 | | |
17 | | /** |
18 | | * @return int32_t the next Thrift sequence id to use for this connection. |
19 | | */ |
20 | 0 | int32_t nextSequenceId() { |
21 | 0 | if (next_sequence_id_ == std::numeric_limits<int32_t>::max()) { |
22 | 0 | next_sequence_id_ = 0; |
23 | 0 | return std::numeric_limits<int32_t>::max(); |
24 | 0 | } |
25 | | |
26 | 0 | return next_sequence_id_++; |
27 | 0 | } |
28 | | |
29 | | /** |
30 | | * @return true if this upgrade has been attempted on this connection. |
31 | | */ |
32 | 0 | bool upgradeAttempted() const { return upgrade_attempted_; } |
33 | | /** |
34 | | * @return true if this connection has been upgraded |
35 | | */ |
36 | 0 | bool isUpgraded() const { return upgraded_; } |
37 | | |
38 | | /** |
39 | | * Marks the connection as successfully upgraded. |
40 | | */ |
41 | 0 | void markUpgraded() { |
42 | 0 | upgrade_attempted_ = true; |
43 | 0 | upgraded_ = true; |
44 | 0 | } |
45 | | |
46 | | /** |
47 | | * Marks the connection as not upgraded. |
48 | | */ |
49 | 0 | void markUpgradeFailed() { |
50 | 0 | upgrade_attempted_ = true; |
51 | 0 | upgraded_ = false; |
52 | 0 | } |
53 | | |
54 | | private: |
55 | | int32_t next_sequence_id_; |
56 | | bool upgrade_attempted_{false}; |
57 | | bool upgraded_{false}; |
58 | | }; |
59 | | |
60 | | } // namespace ThriftProxy |
61 | | } // namespace NetworkFilters |
62 | | } // namespace Extensions |
63 | | } // namespace Envoy |