forked from rsocket/rsocket-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRSocket.cpp
More file actions
122 lines (114 loc) · 4.48 KB
/
RSocket.cpp
File metadata and controls
122 lines (114 loc) · 4.48 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2004-present Facebook. All Rights Reserved.
#include "rsocket/RSocket.h"
namespace rsocket {
folly::Future<std::unique_ptr<RSocketClient>> RSocket::createConnectedClient(
std::shared_ptr<ConnectionFactory> connectionFactory,
SetupParameters setupParameters,
std::shared_ptr<RSocketResponder> responder,
std::chrono::milliseconds keepaliveInterval,
std::shared_ptr<RSocketStats> stats,
std::shared_ptr<RSocketConnectionEvents> connectionEvents,
std::shared_ptr<ResumeManager> resumeManager,
std::shared_ptr<ColdResumeHandler> coldResumeHandler,
folly::EventBase* stateMachineEvb) {
auto createRSC = [
connectionFactory,
setupParameters = std::move(setupParameters),
responder = std::move(responder),
keepaliveInterval,
stats = std::move(stats),
connectionEvents = std::move(connectionEvents),
resumeManager = std::move(resumeManager),
coldResumeHandler = std::move(coldResumeHandler),
stateMachineEvb
](ConnectionFactory::ConnectedDuplexConnection connection) mutable {
VLOG(3) << "createConnectedClient received DuplexConnection";
return RSocket::createClientFromConnection(
std::move(connection.connection),
connection.eventBase,
std::move(setupParameters),
std::move(connectionFactory),
std::move(responder),
keepaliveInterval,
std::move(stats),
std::move(connectionEvents),
std::move(resumeManager),
std::move(coldResumeHandler),
stateMachineEvb);
};
return connectionFactory->connect().then([createRSC = std::move(createRSC)](
ConnectionFactory::ConnectedDuplexConnection connection) mutable {
// fromConnection method must be called from the transport eventBase
// and since there is no guarantee that the Future returned from the
// connectionFactory::connect method is executed on the event base, we
// have to ensure it by using folly::via
auto* transportEvb = &connection.eventBase;
return via(transportEvb, [
connection = std::move(connection),
createRSC = std::move(createRSC)
]() mutable { return createRSC(std::move(connection)); });
});
}
folly::Future<std::unique_ptr<RSocketClient>> RSocket::createResumedClient(
std::shared_ptr<ConnectionFactory> connectionFactory,
ResumeIdentificationToken token,
std::shared_ptr<ResumeManager> resumeManager,
std::shared_ptr<ColdResumeHandler> coldResumeHandler,
std::shared_ptr<RSocketResponder> responder,
std::chrono::milliseconds keepaliveInterval,
std::shared_ptr<RSocketStats> stats,
std::shared_ptr<RSocketConnectionEvents> connectionEvents,
ProtocolVersion protocolVersion,
folly::EventBase* stateMachineEvb) {
auto* c = new RSocketClient(
std::move(connectionFactory),
std::move(protocolVersion),
std::move(token),
std::move(responder),
keepaliveInterval,
std::move(stats),
std::move(connectionEvents),
std::move(resumeManager),
std::move(coldResumeHandler),
stateMachineEvb);
return c->resume()
.then([client = std::unique_ptr<RSocketClient>(c)]() mutable {
return std::move(client);
});
}
std::unique_ptr<RSocketClient> RSocket::createClientFromConnection(
std::unique_ptr<DuplexConnection> connection,
folly::EventBase& transportEvb,
SetupParameters setupParameters,
std::shared_ptr<ConnectionFactory> connectionFactory,
std::shared_ptr<RSocketResponder> responder,
std::chrono::milliseconds keepaliveInterval,
std::shared_ptr<RSocketStats> stats,
std::shared_ptr<RSocketConnectionEvents> connectionEvents,
std::shared_ptr<ResumeManager> resumeManager,
std::shared_ptr<ColdResumeHandler> coldResumeHandler,
folly::EventBase* stateMachineEvb) {
auto c = std::unique_ptr<RSocketClient>(new RSocketClient(
std::move(connectionFactory),
setupParameters.protocolVersion,
setupParameters.token,
std::move(responder),
keepaliveInterval,
std::move(stats),
std::move(connectionEvents),
std::move(resumeManager),
std::move(coldResumeHandler),
stateMachineEvb));
c->fromConnection(
std::move(connection),
transportEvb,
std::move(setupParameters));
return c;
}
std::unique_ptr<RSocketServer> RSocket::createServer(
std::unique_ptr<ConnectionAcceptor> connectionAcceptor,
std::shared_ptr<RSocketStats> stats) {
return std::make_unique<RSocketServer>(
std::move(connectionAcceptor), std::move(stats));
}
} // namespace rsocket