Skip to content

Commit fe71e9b

Browse files
authored
Delete FrameBufferAllocator (rsocket#712)
This was planned on being passed into FrameSerializer so we could have the serializer allocate frames with extra headroom for the frame length if needed. This shouldn't be hidden by an external allocator however. If we're adding frame lengths, then the frame serializer should know about it and it should be the one serializing and deserializing them.
1 parent 23b154b commit fe71e9b

File tree

7 files changed

+8
-35
lines changed

7 files changed

+8
-35
lines changed

rsocket/framing/Frame.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@ const uint32_t Frame_LEASE::kMaxNumRequests;
1616
const uint32_t Frame_SETUP::kMaxKeepaliveTime;
1717
const uint32_t Frame_SETUP::kMaxLifetime;
1818

19-
std::unique_ptr<folly::IOBuf> FrameBufferAllocator::allocate(size_t size) {
20-
// Purposely leak the allocator, since it's hard to deterministically
21-
// guarantee that threads will stop using it before it would get statically
22-
// destructed.
23-
static auto* singleton = new FrameBufferAllocator;
24-
return singleton->allocateBuffer(size);
25-
}
26-
27-
std::unique_ptr<folly::IOBuf> FrameBufferAllocator::allocateBuffer(
28-
size_t size) {
29-
return folly::IOBuf::createCombined(size);
30-
}
31-
3219
std::ostream&
3320
writeFlags(std::ostream& os, FrameFlags frameFlags, FrameType frameType) {
3421
constexpr const char* kEmpty = "0x00";

rsocket/framing/Frame.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,6 @@ class FrameHeader {
5151

5252
std::ostream& operator<<(std::ostream&, const FrameHeader&);
5353

54-
class FrameBufferAllocator {
55-
public:
56-
static std::unique_ptr<folly::IOBuf> allocate(size_t size);
57-
58-
virtual ~FrameBufferAllocator() = default;
59-
60-
private:
61-
virtual std::unique_ptr<folly::IOBuf> allocateBuffer(size_t size);
62-
};
63-
64-
/// @{
6554
/// Frames do not form hierarchy, as we never perform type erasure on a frame.
6655
/// We use inheritance only to save code duplication.
6756
///

rsocket/framing/FrameSerializer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,4 @@ std::unique_ptr<FrameSerializer> FrameSerializer::createAutodetectedSerializer(
7272
std::ostream& operator<<(std::ostream& os, const ProtocolVersion& version) {
7373
return os << version.major << "." << version.minor;
7474
}
75-
76-
} // reactivesocket
75+
}

rsocket/framing/FrameSerializer.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#pragma once
44

55
#include <folly/Optional.h>
6-
#include <iosfwd>
6+
77
#include <memory>
8-
#include <string>
8+
99
#include "rsocket/framing/Frame.h"
1010

1111
namespace rsocket {
@@ -86,5 +86,4 @@ class FrameSerializer {
8686
Frame_RESUME_OK&,
8787
std::unique_ptr<folly::IOBuf>) = 0;
8888
};
89-
90-
} // reactivesocket
89+
}

rsocket/framing/FrameSerializer_v0.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ constexpr inline bool operator!(FrameFlags_V0 a) {
5959
} // namespace
6060

6161
static folly::IOBufQueue createBufferQueue(size_t bufferSize) {
62-
auto buf = rsocket::FrameBufferAllocator::allocate(bufferSize);
62+
auto buf = folly::IOBuf::createCombined(bufferSize);
6363
folly::IOBufQueue queue(folly::IOBufQueue::cacheChainLength());
6464
queue.append(std::move(buf));
6565
return queue;

rsocket/framing/FrameSerializer_v1_0.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ProtocolVersion FrameSerializerV1_0::protocolVersion() {
2020
}
2121

2222
static folly::IOBufQueue createBufferQueue(size_t bufferSize) {
23-
auto buf = rsocket::FrameBufferAllocator::allocate(bufferSize);
23+
auto buf = folly::IOBuf::createCombined(bufferSize);
2424
folly::IOBufQueue queue(folly::IOBufQueue::cacheChainLength());
2525
queue.append(std::move(buf));
2626
return queue;
@@ -678,5 +678,4 @@ ProtocolVersion FrameSerializerV1_0::detectProtocolVersion(
678678
}
679679
return ProtocolVersion::Unknown;
680680
}
681-
682-
} // reactivesocket
681+
}

rsocket/framing/FrameSerializer_v1_0.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ class FrameSerializerV1_0 : public FrameSerializer {
6363
folly::io::Cursor& cur,
6464
FrameFlags flags);
6565
};
66-
} // reactivesocket
66+
}

0 commit comments

Comments
 (0)