Skip to content

Commit 0470932

Browse files
leheckafacebook-github-bot
authored andcommitted
Reapplying only boiler plate code from D8955216
Summary: Original commit changeset: 8703161f6d79 The original diff D8955216 landed but caused memory regression and later was reverted in D9262496. In order to find the problematic piece of the original code, I am splitting it to the boiler plate code and the rest. This diff contains only the boiler plate code change. It is adding a parameter ProtocolVersion to the interface method ConnectionFactory::connect and all its implementations. No behavior is added or changed. Reviewed By: phoad Differential Revision: D9501071 fbshipit-source-id: 172d30fda0c08896d198c75d3f063dbe1e95f613
1 parent 5d77d4c commit 0470932

14 files changed

+40
-21
lines changed

rsocket/ConnectionFactory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <folly/Function.h>
1818
#include <folly/futures/Future.h>
1919
#include "rsocket/DuplexConnection.h"
20+
#include "rsocket/framing/ProtocolVersion.h"
2021

2122
namespace folly {
2223
class EventBase;
@@ -59,6 +60,7 @@ class ConnectionFactory {
5960
* Resource creation depends on the particular implementation.
6061
*/
6162
virtual folly::Future<ConnectedDuplexConnection> connect(
63+
ProtocolVersion,
6264
ResumeStatus resume) = 0;
6365
};
6466
} // namespace rsocket

rsocket/RSocket.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ folly::Future<std::unique_ptr<RSocketClient>> RSocket::createConnectedClient(
2828
folly::EventBase* stateMachineEvb) {
2929
CHECK(resumeManager)
3030
<< "provide ResumeManager::makeEmpty() instead of nullptr";
31-
31+
auto protocolVersion = setupParameters.protocolVersion;
3232
auto createRSC =
3333
[connectionFactory,
3434
setupParameters = std::move(setupParameters),
@@ -55,7 +55,7 @@ folly::Future<std::unique_ptr<RSocketClient>> RSocket::createConnectedClient(
5555
stateMachineEvb);
5656
};
5757

58-
return connectionFactory->connect(ResumeStatus::NEW_SESSION)
58+
return connectionFactory->connect(protocolVersion, ResumeStatus::NEW_SESSION)
5959
.then(
6060
[createRSC = std::move(createRSC)](
6161
ConnectionFactory::ConnectedDuplexConnection connection) mutable {

rsocket/RSocketClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ folly::Future<folly::Unit> RSocketClient::resume() {
7474
<< "The client was likely created without ConnectionFactory. Can't "
7575
<< "resume";
7676

77-
return connectionFactory_->connect(ResumeStatus::RESUMING)
77+
return connectionFactory_->connect(protocolVersion_, ResumeStatus::RESUMING)
7878
.then(
7979
[this](
8080
ConnectionFactory::ConnectedDuplexConnection connection) mutable {

rsocket/benchmarks/StreamThroughputMemory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class Factory : public ConnectionFactory {
137137
}
138138

139139
folly::Future<ConnectedDuplexConnection> connect(
140+
ProtocolVersion,
140141
ResumeStatus /* unused */) override {
141142
return folly::via(worker_.getEventBase(), [this] {
142143
return ConnectedDuplexConnection{std::move(connection_),

rsocket/framing/FrameHeader.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818

1919
#include "rsocket/framing/FrameFlags.h"
2020
#include "rsocket/framing/FrameType.h"
21+
#include "rsocket/internal/Common.h"
2122

2223
namespace rsocket {
2324

24-
/// A unique identifier of a stream.
25-
using StreamId = uint32_t;
26-
2725
/// Header that begins every RSocket frame.
2826
class FrameHeader {
2927
public:

rsocket/framing/FrameSerializer.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
#include "rsocket/framing/FrameSerializer.h"
16-
1716
#include "rsocket/framing/FrameSerializer_v1_0.h"
1817

1918
namespace rsocket {
@@ -50,4 +49,16 @@ folly::IOBufQueue FrameSerializer::createBufferQueue(size_t bufferSize) const {
5049
return queue;
5150
}
5251

52+
folly::Optional<StreamId> FrameSerializer::peekStreamId(
53+
const ProtocolVersion& protocolVersion,
54+
const folly::IOBuf& frame) {
55+
if (protocolVersion == FrameSerializerV1_0::Version) {
56+
return FrameSerializerV1_0().peekStreamId(frame);
57+
}
58+
59+
auto* msg = "unknown protocol version";
60+
DCHECK(false) << msg;
61+
return folly::none;
62+
}
63+
5364
} // namespace rsocket

rsocket/framing/FrameSerializer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class FrameSerializer {
3535
static std::unique_ptr<FrameSerializer> createAutodetectedSerializer(
3636
const folly::IOBuf& firstFrame);
3737

38+
static folly::Optional<StreamId> peekStreamId(
39+
const ProtocolVersion& protocolVersion,
40+
const folly::IOBuf& frame);
41+
3842
virtual FrameType peekFrameType(const folly::IOBuf& in) const = 0;
3943
virtual folly::Optional<StreamId> peekStreamId(
4044
const folly::IOBuf& in) const = 0;

rsocket/framing/FramedDuplexConnection.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "rsocket/framing/FramedDuplexConnection.h"
16-
1716
#include <folly/io/Cursor.h>
18-
19-
#include "rsocket/framing/FrameSerializer.h"
2017
#include "rsocket/framing/FrameSerializer_v1_0.h"
2118
#include "rsocket/framing/FramedReader.h"
2219

rsocket/internal/Common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ typedef Range<const char*> StringPiece;
3737

3838
namespace rsocket {
3939

40+
/// A unique identifier of a stream.
41+
using StreamId = uint32_t;
42+
4043
constexpr std::chrono::seconds kDefaultKeepaliveInterval{5};
4144

4245
constexpr int64_t kMaxRequestN = std::numeric_limits<int32_t>::max();

rsocket/test/RSocketClientServerTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ TEST(RSocketClientServer, ServerGetsGarbage) {
111111
auto factory =
112112
std::make_shared<TcpConnectionFactory>(*worker.getEventBase(), address);
113113

114-
auto result = factory->connect(ResumeStatus::NEW_SESSION).get();
114+
auto result =
115+
factory->connect(ProtocolVersion::Latest, ResumeStatus::NEW_SESSION)
116+
.get();
115117
auto connection = std::move(result.connection);
116118
auto evb = &result.eventBase;
117119

0 commit comments

Comments
 (0)