|
18 | 18 | #include "src/RequestHandler.h" |
19 | 19 | #include "src/automata/ChannelRequester.h" |
20 | 20 | #include "src/automata/ChannelResponder.h" |
| 21 | +#include "src/automata/RequestResponseRequester.h" |
| 22 | +#include "src/automata/RequestResponseResponder.h" |
21 | 23 | #include "src/automata/StreamRequester.h" |
22 | 24 | #include "src/automata/StreamResponder.h" |
23 | 25 | #include "src/automata/SubscriptionRequester.h" |
@@ -166,6 +168,21 @@ void ReactiveSocket::requestFireAndForget(Payload request) { |
166 | 168 | connection_->outputFrameOrEnqueue(frame.serializeOut()); |
167 | 169 | } |
168 | 170 |
|
| 171 | +void ReactiveSocket::requestResponse( |
| 172 | + Payload payload, |
| 173 | + Subscriber<Payload>& responseSink) { |
| 174 | + // TODO(stupaq): handle any exceptions |
| 175 | + StreamId streamId = nextStreamId_; |
| 176 | + nextStreamId_ += 2; |
| 177 | + RequestResponseRequester::Parameters params = {connection_, streamId}; |
| 178 | + auto automaton = new RequestResponseRequester(params); |
| 179 | + connection_->addStream(streamId, *automaton); |
| 180 | + automaton->subscribe(responseSink); |
| 181 | + responseSink.onSubscribe(*automaton); |
| 182 | + automaton->onNext(std::move(payload)); |
| 183 | + automaton->start(); |
| 184 | +} |
| 185 | + |
169 | 186 | void ReactiveSocket::metadataPush(std::unique_ptr<folly::IOBuf> metadata) { |
170 | 187 | connection_->outputFrameOrEnqueue( |
171 | 188 | Frame_METADATA_PUSH(std::move(metadata)).serializeOut()); |
@@ -247,6 +264,19 @@ bool ReactiveSocket::createResponder( |
247 | 264 | automaton->start(); |
248 | 265 | break; |
249 | 266 | } |
| 267 | + case FrameType::REQUEST_RESPONSE: { |
| 268 | + Frame_REQUEST_RESPONSE frame; |
| 269 | + if (!frame.deserializeFrom(std::move(serializedFrame))) { |
| 270 | + return false; |
| 271 | + } |
| 272 | + SubscriptionResponder::Parameters params = {connection_, streamId}; |
| 273 | + auto automaton = new RequestResponseResponder(params); |
| 274 | + connection_->addStream(streamId, *automaton); |
| 275 | + handler_->handleRequestResponse(std::move(frame.payload_), *automaton); |
| 276 | + automaton->onNextFrame(std::move(frame)); |
| 277 | + automaton->start(); |
| 278 | + break; |
| 279 | + } |
250 | 280 | case FrameType::REQUEST_FNF: { |
251 | 281 | Frame_REQUEST_FNF frame; |
252 | 282 | if (!frame.deserializeFrom(std::move(serializedFrame))) { |
|
0 commit comments