1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_CLIENT_CHTTP2_CONNECTOR_H
#define GRPC_CORE_EXT_TRANSPORT_CHTTP2_CLIENT_CHTTP2_CONNECTOR_H
#include <grpc/support/port_platform.h>
#include "src/core/ext/filters/client_channel/connector.h"
#include "src/core/lib/channel/handshaker.h"
#include "src/core/lib/channel/handshaker_registry.h"
namespace grpc_core {
class Chttp2Connector : public SubchannelConnector {
public:
Chttp2Connector();
~Chttp2Connector() override;
void Connect(const Args& args, Result* result, grpc_closure* notify) override;
void Shutdown(grpc_error* error) override;
private:
static void Connected(void* arg, grpc_error* error);
void StartHandshakeLocked();
static void OnHandshakeDone(void* arg, grpc_error* error);
static void OnReceiveSettings(void* arg, grpc_error* error);
static void OnTimeout(void* arg, grpc_error* error);
// We cannot invoke notify_ until both OnTimeout() and OnReceiveSettings()
// have been called since that is an indicator to the upper layer that we are
// done with the connection attempt. So, the notification process is broken
// into two steps. 1) Either OnTimeout() or OnReceiveSettings() gets invoked
// first. Whichever gets invoked, calls MaybeNotify() to set the result and
// triggers the other callback to be invoked. 2) When the other callback is
// invoked, we call MaybeNotify() again to actually invoke the notify_
// callback. Note that this only happens if the handshake is done and the
// connector is waiting on the SETTINGS frame.
void MaybeNotify(grpc_error* error);
Mutex mu_;
Args args_;
Result* result_ = nullptr;
grpc_closure* notify_ = nullptr;
bool shutdown_ = false;
bool connecting_ = false;
// Holds the endpoint when first created before being handed off to
// the handshake manager, and then again after handshake is done.
grpc_endpoint* endpoint_ = nullptr;
grpc_closure connected_;
grpc_closure on_receive_settings_;
grpc_timer timer_;
grpc_closure on_timeout_;
absl::optional<grpc_error*> notify_error_;
RefCountedPtr<HandshakeManager> handshake_mgr_;
};
} // namespace grpc_core
#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_CLIENT_CHTTP2_CONNECTOR_H */
|