wire_reader_impl.h
Go to the documentation of this file.
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GRPC_CORE_EXT_TRANSPORT_BINDER_WIRE_FORMAT_WIRE_READER_IMPL_H
16 #define GRPC_CORE_EXT_TRANSPORT_BINDER_WIRE_FORMAT_WIRE_READER_IMPL_H
17 
19 
20 #include <memory>
21 #include <utility>
22 
23 #include "absl/container/flat_hash_map.h"
24 #include "absl/synchronization/notification.h"
25 
27 
32 
33 namespace grpc_binder {
34 
35 class WireReaderImpl : public WireReader {
36  public:
38  std::shared_ptr<TransportStreamReceiver> transport_stream_receiver,
39  bool is_client,
40  std::shared_ptr<grpc::experimental::binder::SecurityPolicy>
41  security_policy,
42  std::function<void()> on_destruct_callback = nullptr);
43  ~WireReaderImpl() override;
44 
45  void Orphan() override { Unref(); }
46 
71  std::shared_ptr<WireWriter> SetupTransport(
72  std::unique_ptr<Binder> binder) override;
73 
75  ReadableParcel* parcel, int uid);
76 
84  void SendSetupTransport(Binder* binder);
85 
93  // TODO(waynetu): In the testing environment, we still use this method (on
94  // another WireReader instance) for server-side transport setup, and thus it
95  // is marked as public. Try moving this method back to private, and hopefully
96  // we can also avoid moving |other_end_binder_| out in the implementation.
97  std::unique_ptr<Binder> RecvSetupTransport();
98 
99  private:
101  ReadableParcel* parcel);
103  ReadableParcel* parcel,
104  int* cancellation_flags)
106 
107  std::shared_ptr<TransportStreamReceiver> transport_stream_receiver_;
110  bool connected_ ABSL_GUARDED_BY(mu_) = false;
111  bool recvd_setup_transport_ ABSL_GUARDED_BY(mu_) = false;
112  // NOTE: other_end_binder_ will be moved out when RecvSetupTransport() is
113  // called. Be cautious not to access it afterward.
114  std::unique_ptr<Binder> other_end_binder_;
119  std::unique_ptr<TransactionReceiver> tx_receiver_;
121  std::shared_ptr<grpc::experimental::binder::SecurityPolicy> security_policy_;
122  // When WireReaderImpl gets destructed, call on_destruct_callback_. This is
123  // mostly for decrementing the reference count of its transport.
125 
126  // ACK every 16k bytes.
127  static constexpr int64_t kFlowControlAckBytes = 16 * 1024;
128  int64_t num_incoming_bytes_ ABSL_GUARDED_BY(mu_) = 0;
129  int64_t num_acknowledged_bytes_ ABSL_GUARDED_BY(mu_) = 0;
130 
131  // Used to send ACK.
132  std::shared_ptr<WireWriter> wire_writer_;
133 };
134 
135 } // namespace grpc_binder
136 
137 #endif // GRPC_CORE_EXT_TRANSPORT_BINDER_WIRE_FORMAT_WIRE_READER_IMPL_H
grpc_binder::WireReaderImpl::ABSL_GUARDED_BY
bool connected_ ABSL_GUARDED_BY(mu_)
grpc_binder::WireReaderImpl::is_client_
bool is_client_
Definition: wire_reader_impl.h:120
grpc_binder::WireReaderImpl::ProcessStreamingTransaction
absl::Status ProcessStreamingTransaction(transaction_code_t code, ReadableParcel *parcel)
Definition: wire_reader_impl.cc:254
binder.h
grpc_core::InternallyRefCounted< WireReader >::Unref
void Unref()
Definition: orphanable.h:100
grpc_binder
Definition: connection_id_generator.cc:45
grpc_binder::WireReaderImpl::other_end_binder_
std::unique_ptr< Binder > other_end_binder_
Definition: wire_reader_impl.h:114
transaction_code_t
uint32_t transaction_code_t
Definition: binder_constants.h:24
absl::Notification
Definition: abseil-cpp/absl/synchronization/notification.h:66
wire_reader.h
grpc_binder::WireReaderImpl::security_policy_
std::shared_ptr< grpc::experimental::binder::SecurityPolicy > security_policy_
Definition: wire_reader_impl.h:121
binder_security_policy.h
grpc_binder::WireReaderImpl::transport_stream_receiver_
std::shared_ptr< TransportStreamReceiver > transport_stream_receiver_
Definition: wire_reader_impl.h:107
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
grpc_binder::WireReaderImpl::connection_noti_
absl::Notification connection_noti_
Definition: wire_reader_impl.h:108
grpc_binder::WireReader
Definition: wire_reader.h:29
grpc_binder::WireReaderImpl::on_destruct_callback_
std::function< void()> on_destruct_callback_
Definition: wire_reader_impl.h:124
ABSL_EXCLUSIVE_LOCKS_REQUIRED
#define ABSL_EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: abseil-cpp/absl/base/thread_annotations.h:145
grpc_binder::WireReaderImpl::tx_receiver_
std::unique_ptr< TransactionReceiver > tx_receiver_
Definition: wire_reader_impl.h:119
grpc_binder::WireReaderImpl
Definition: wire_reader_impl.h:35
grpc_binder::WireReaderImpl::wire_writer_
std::shared_ptr< WireWriter > wire_writer_
Definition: wire_reader_impl.h:132
grpc_binder::WireReaderImpl::ProcessStreamingTransactionImpl
absl::Status ProcessStreamingTransactionImpl(transaction_code_t code, ReadableParcel *parcel, int *cancellation_flags) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_)
Definition: wire_reader_impl.cc:315
grpc_binder::WireReaderImpl::~WireReaderImpl
~WireReaderImpl() override
Definition: wire_reader_impl.cc:87
grpc_binder::WireReaderImpl::RecvSetupTransport
std::unique_ptr< Binder > RecvSetupTransport()
Definition: wire_reader_impl.cc:144
grpc_binder::WireReaderImpl::mu_
grpc_core::Mutex mu_
Definition: wire_reader_impl.h:109
grpc_core::Mutex
Definition: src/core/lib/gprpp/sync.h:61
grpc_binder::WireReaderImpl::ProcessTransaction
absl::Status ProcessTransaction(transaction_code_t code, ReadableParcel *parcel, int uid)
Definition: wire_reader_impl.cc:153
absl::Status
Definition: third_party/abseil-cpp/absl/status/status.h:424
absl::flat_hash_map
Definition: abseil-cpp/absl/container/flat_hash_map.h:113
wire_writer.h
grpc_binder::WireReaderImpl::kFlowControlAckBytes
static constexpr int64_t kFlowControlAckBytes
Definition: wire_reader_impl.h:127
transport_stream_receiver.h
connected_
grpc_closure connected_
Definition: tcp_connect_handshaker.cc:87
grpc_binder::WireReaderImpl::SetupTransport
std::shared_ptr< WireWriter > SetupTransport(std::unique_ptr< Binder > binder) override
Definition: wire_reader_impl.cc:93
code
Definition: bloaty/third_party/zlib/contrib/infback9/inftree9.h:24
grpc_binder::ReadableParcel
Definition: binder.h:66
grpc_binder::Binder
Definition: binder.h:87
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
grpc_binder::WireReaderImpl::Orphan
void Orphan() override
Definition: wire_reader_impl.h:45
grpc_binder::WireReaderImpl::SendSetupTransport
void SendSetupTransport(Binder *binder)
Definition: wire_reader_impl.cc:117
grpc_binder::WireReaderImpl::WireReaderImpl
WireReaderImpl(std::shared_ptr< TransportStreamReceiver > transport_stream_receiver, bool is_client, std::shared_ptr< grpc::experimental::binder::SecurityPolicy > security_policy, std::function< void()> on_destruct_callback=nullptr)
Definition: wire_reader_impl.cc:75
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:52